Skip to content

Commit ef5b1a3

Browse files
authored
feat #388: Add support for paravirtualized launch volume attachment (#395)
* updated tilt-helper 1.updated tilt image golang version to 1.21.8 2.added bash to kustomize-sub.sh call Signed-off-by: Mayank Kakani <[email protected]> * Update types.go Added LaunchParavirtualizedVolumeAttachment types to v1 * Update types.go added LaunchParavirtualizedVolumeAttachment type * Update machine.go Added support for getParavirtualizedVolumeAttachment * Update infrastructure.cluster.x-k8s.io_ocimachines.yaml added launchParavirtualizedVolumeAttachment defination * Update infrastructure.cluster.x-k8s.io_ocimachinetemplates.yaml added launchParavirtualizedVolumeAttachment definations * Update go.mod Updated OCI go sdk version to v65.81.1 to support paravirtualized volume * Update go.sum Updated OCI SDK version * Update machine_test.go added test for paravirtualized volumes * Update machine.go updated message "Unknown attachment type not supported" * Update machine_test.go updated name - "check all params together, with paravirtualized volume support" * Fixed unittests Fixed paravirtualized volume support unit test case --------- Signed-off-by: Mayank Kakani <[email protected]>
1 parent 14936bf commit ef5b1a3

9 files changed

+448
-7
lines changed

Tiltfile

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ if "default_registry" in settings:
4141

4242
tilt_helper_dockerfile_header = """
4343
# Tilt image
44-
FROM golang:1.19 as tilt-helper
44+
FROM golang:1.21.8 as tilt-helper
4545
# Support live reloading with Tilt
4646
RUN go install github.com/go-delve/delve/cmd/dlv@latest
4747
RUN wget --output-document /restart.sh --quiet https://raw.githubusercontent.com/tilt-dev/rerun-process-wrapper/master/restart.sh && \
@@ -196,7 +196,7 @@ def base64_decode(to_decode):
196196
return str(decode_blob)
197197

198198
def kustomizesub(folder):
199-
yaml = local('hack/kustomize-sub.sh {}'.format(folder), quiet=True)
199+
yaml = local('bash hack/kustomize-sub.sh {}'.format(folder), quiet=True)
200200
return yaml
201201

202202
##############################
@@ -216,4 +216,4 @@ deploy_capi()
216216

217217
capoci()
218218

219-
waitforsystem()
219+
waitforsystem()

api/v1beta1/types.go

+31
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,7 @@ type VolumeType string
10981098

10991099
const (
11001100
IscsiType VolumeType = "iscsi"
1101+
ParavirtualizedType VolumeType = "paravirtualized"
11011102
)
11021103

11031104
// EncryptionInTransitTypeEnum Enum with underlying type: string
@@ -1115,6 +1116,7 @@ type LaunchVolumeAttachment struct {
11151116

11161117
// The details of iscsi volume attachment.
11171118
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
1119+
ParavirtualizedAttachment LaunchParavirtualizedVolumeAttachment `json:"launchParavirtualizedVolumeAttachment,omitempty"`
11181120
}
11191121

11201122
// LaunchIscsiVolumeAttachment specifies the iscsi volume attachments to create as part of the launch instance operation.
@@ -1152,6 +1154,35 @@ type LaunchIscsiVolumeAttachment struct {
11521154
EncryptionInTransitType EncryptionInTransitTypeEnum `json:"encryptionInTransitType,omitempty"`
11531155
}
11541156

1157+
// LaunchParavirtualizedVolumeAttachment specifies the paravirtualized volume attachments to create as part of the launch instance operation.
1158+
type LaunchParavirtualizedVolumeAttachment struct {
1159+
// The device name. To retrieve a list of devices for a given instance, see ListInstanceDevices.
1160+
Device *string `json:"device,omitempty"`
1161+
1162+
// A user-friendly name. Does not have to be unique, and it's changeable.
1163+
// Avoid entering confidential information.
1164+
DisplayName *string `json:"displayName,omitempty"`
1165+
1166+
// Whether the attachment was created in read-only mode.
1167+
IsReadOnly *bool `json:"isReadOnly,omitempty"`
1168+
1169+
// Whether the attachment should be created in shareable mode. If an attachment
1170+
// is created in shareable mode, then other instances can attach the same volume, provided
1171+
// that they also create their attachments in shareable mode. Only certain volume types can
1172+
// be attached in shareable mode. Defaults to false if not specified.
1173+
IsShareable *bool `json:"isShareable,omitempty"`
1174+
1175+
// The OCID of the volume. If CreateVolumeDetails is specified, this field must be omitted from the request.
1176+
VolumeId *string `json:"volumeId,omitempty"`
1177+
1178+
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
1179+
LaunchCreateVolumeFromAttributes LaunchCreateVolumeFromAttributes `json:"launchCreateVolumeFromAttributes,omitempty"`
1180+
1181+
// Refer the top-level definition of isPvEncryptionInTransitEnabled.
1182+
// The default value is False.
1183+
IsPvEncryptionInTransitEnabled *bool `json:"isPvEncryptionInTransitEnabled,omitempty"`
1184+
}
1185+
11551186
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
11561187
type LaunchCreateVolumeFromAttributes struct {
11571188

api/v1beta2/types.go

+32
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ type VolumeType string
11681168

11691169
const (
11701170
IscsiType VolumeType = "iscsi"
1171+
ParavirtualizedType VolumeType = "paravirtualized"
11711172
)
11721173

11731174
// EncryptionInTransitTypeEnum Enum with underlying type: string
@@ -1186,6 +1187,7 @@ type LaunchVolumeAttachment struct {
11861187

11871188
// The details of iscsi volume attachment.
11881189
IscsiAttachment LaunchIscsiVolumeAttachment `json:"launchIscsiVolumeAttachment,omitempty"`
1190+
ParavirtualizedAttachment LaunchParavirtualizedVolumeAttachment `json:"launchParavirtualizedVolumeAttachment,omitempty"`
11891191
}
11901192

11911193
// LaunchIscsiVolumeAttachment specifies the iscsi volume attachments to create as part of the launch instance operation.
@@ -1223,6 +1225,36 @@ type LaunchIscsiVolumeAttachment struct {
12231225
EncryptionInTransitType EncryptionInTransitTypeEnum `json:"encryptionInTransitType,omitempty"`
12241226
}
12251227

1228+
// LaunchParavirtualizedVolumeAttachment specifies the paravirtualized volume attachments to create as part of the launch instance operation.
1229+
type LaunchParavirtualizedVolumeAttachment struct {
1230+
// The device name. To retrieve a list of devices for a given instance, see ListInstanceDevices.
1231+
Device *string `json:"device,omitempty"`
1232+
1233+
// A user-friendly name. Does not have to be unique, and it's changeable.
1234+
// Avoid entering confidential information.
1235+
DisplayName *string `json:"displayName,omitempty"`
1236+
1237+
// Whether the attachment was created in read-only mode.
1238+
IsReadOnly *bool `json:"isReadOnly,omitempty"`
1239+
1240+
// Whether the attachment should be created in shareable mode. If an attachment
1241+
// is created in shareable mode, then other instances can attach the same volume, provided
1242+
// that they also create their attachments in shareable mode. Only certain volume types can
1243+
// be attached in shareable mode. Defaults to false if not specified.
1244+
IsShareable *bool `json:"isShareable,omitempty"`
1245+
1246+
// The OCID of the volume. If CreateVolumeDetails is specified, this field must be omitted from the request.
1247+
VolumeId *string `json:"volumeId,omitempty"`
1248+
1249+
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
1250+
LaunchCreateVolumeFromAttributes LaunchCreateVolumeFromAttributes `json:"launchCreateVolumeFromAttributes,omitempty"`
1251+
1252+
// Refer the top-level definition of encryptionInTransitType.
1253+
// The default value is False.
1254+
IsPvEncryptionInTransitEnabled *bool `json:"isPvEncryptionInTransitEnabled,omitempty"`
1255+
}
1256+
1257+
12261258
// LaunchCreateVolumeFromAttributes The details of the volume to create for CreateVolume operation.
12271259
type LaunchCreateVolumeFromAttributes struct {
12281260

cloud/scope/machine.go

+17
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,10 @@ func (m *MachineScope) getLaunchVolumeAttachments() []core.LaunchAttachVolumeDet
997997
for _, attachment := range volumeAttachmentsInSpec {
998998
if attachment.Type == infrastructurev1beta2.IscsiType {
999999
volumes = append(volumes, getIscsiVolumeAttachment(attachment.IscsiAttachment))
1000+
} else if attachment.Type == infrastructurev1beta2.ParavirtualizedType {
1001+
volumes = append(volumes, getParavirtualizedVolumeAttachment(attachment.ParavirtualizedAttachment))
1002+
} else {
1003+
m.Logger.Info("Unknown attachment type not supported")
10001004
}
10011005
}
10021006
return volumes
@@ -1017,6 +1021,19 @@ func getIscsiVolumeAttachment(attachment infrastructurev1beta2.LaunchIscsiVolume
10171021
return volumeDetails
10181022
}
10191023

1024+
func getParavirtualizedVolumeAttachment(attachment infrastructurev1beta2.LaunchParavirtualizedVolumeAttachment) core.LaunchAttachVolumeDetails {
1025+
volumeDetails := core.LaunchAttachParavirtualizedVolumeDetails{
1026+
Device: attachment.Device,
1027+
DisplayName: attachment.DisplayName,
1028+
IsShareable: attachment.IsShareable,
1029+
IsReadOnly: attachment.IsReadOnly,
1030+
VolumeId: attachment.VolumeId,
1031+
IsPvEncryptionInTransitEnabled: attachment.IsPvEncryptionInTransitEnabled,
1032+
LaunchCreateVolumeDetails: getLaunchCreateVolumeDetails(attachment.LaunchCreateVolumeFromAttributes),
1033+
}
1034+
return volumeDetails
1035+
}
1036+
10201037
func getLaunchCreateVolumeDetails(attributes infrastructurev1beta2.LaunchCreateVolumeFromAttributes) core.LaunchCreateVolumeFromAttributes {
10211038
return core.LaunchCreateVolumeFromAttributes{
10221039
SizeInGBs: attributes.SizeInGBs,

cloud/scope/machine_test.go

+97
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,103 @@ func TestInstanceReconciliation(t *testing.T) {
551551
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
552552
},
553553
},
554+
{
555+
name: "check all params together, with paravirtualized volume support",
556+
errorExpected: false,
557+
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
558+
setupAllParams(ms)
559+
ms.OCIMachine.Spec.CapacityReservationId = common.String("cap-id")
560+
ms.OCIMachine.Spec.DedicatedVmHostId = common.String("dedicated-host-id")
561+
ms.OCIMachine.Spec.NetworkDetails.HostnameLabel = common.String("hostname-label")
562+
ms.OCIMachine.Spec.NetworkDetails.SubnetId = common.String("subnet-machine-id")
563+
ms.OCIMachine.Spec.NetworkDetails.NSGIds = []string{"nsg-machine-id-1", "nsg-machine-id-2"}
564+
// above array should take precedence
565+
ms.OCIMachine.Spec.NetworkDetails.NSGId = common.String("nsg-machine-id")
566+
ms.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck = common.Bool(true)
567+
ms.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord = common.Bool(true)
568+
ms.OCIMachine.Spec.NetworkDetails.DisplayName = common.String("display-name")
569+
ms.OCIMachine.Spec.LaunchVolumeAttachment = []infrastructurev1beta2.LaunchVolumeAttachment{
570+
{
571+
Type: infrastructurev1beta2.ParavirtualizedType,
572+
ParavirtualizedAttachment: infrastructurev1beta2.LaunchParavirtualizedVolumeAttachment{
573+
Device: common.String("/dev/oci"),
574+
IsShareable: common.Bool(true),
575+
IsPvEncryptionInTransitEnabled: common.Bool(false),
576+
LaunchCreateVolumeFromAttributes: infrastructurev1beta2.LaunchCreateVolumeFromAttributes{
577+
DisplayName: common.String("test-volume"),
578+
SizeInGBs: common.Int64(75),
579+
VpusPerGB: common.Int64(20),
580+
},
581+
},
582+
},
583+
}
584+
ms.OCIMachine.Spec.InstanceSourceViaImageDetails = &infrastructurev1beta2.InstanceSourceViaImageConfig{
585+
KmsKeyId: common.String("kms-key-id"),
586+
BootVolumeVpusPerGB: common.Int64(32),
587+
}
588+
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
589+
DisplayName: common.String("name"),
590+
CompartmentId: common.String("test"),
591+
})).Return(core.ListInstancesResponse{}, nil)
592+
593+
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String("name"),
594+
CapacityReservationId: common.String("cap-id"),
595+
DedicatedVmHostId: common.String("dedicated-host-id"),
596+
SourceDetails: core.InstanceSourceViaImageDetails{
597+
ImageId: common.String("image"),
598+
BootVolumeSizeInGBs: common.Int64(120),
599+
KmsKeyId: common.String("kms-key-id"),
600+
BootVolumeVpusPerGB: common.Int64(32),
601+
},
602+
CreateVnicDetails: &core.CreateVnicDetails{
603+
SubnetId: common.String("subnet-machine-id"),
604+
AssignPublicIp: common.Bool(false),
605+
DefinedTags: map[string]map[string]interface{}{},
606+
FreeformTags: map[string]string{
607+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
608+
ociutil.ClusterResourceIdentifier: "resource_uid",
609+
},
610+
NsgIds: []string{"nsg-machine-id-1", "nsg-machine-id-2"},
611+
HostnameLabel: common.String("hostname-label"),
612+
SkipSourceDestCheck: common.Bool(true),
613+
AssignPrivateDnsRecord: common.Bool(true),
614+
DisplayName: common.String("display-name"),
615+
},
616+
LaunchVolumeAttachments: []core.LaunchAttachVolumeDetails{
617+
core.LaunchAttachParavirtualizedVolumeDetails{
618+
Device: common.String("/dev/oci"),
619+
IsShareable: common.Bool(true),
620+
IsPvEncryptionInTransitEnabled: common.Bool(false),
621+
LaunchCreateVolumeDetails: core.LaunchCreateVolumeFromAttributes{
622+
DisplayName: common.String("test-volume"),
623+
SizeInGBs: common.Int64(75),
624+
VpusPerGB: common.Int64(20),
625+
},
626+
},
627+
},
628+
Metadata: map[string]string{
629+
"user_data": base64.StdEncoding.EncodeToString([]byte("test")),
630+
},
631+
Shape: common.String("shape"),
632+
ShapeConfig: &core.LaunchInstanceShapeConfigDetails{
633+
Ocpus: common.Float32(2),
634+
MemoryInGBs: common.Float32(100),
635+
BaselineOcpuUtilization: core.LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8,
636+
},
637+
AvailabilityDomain: common.String("ad2"),
638+
CompartmentId: common.String("test"),
639+
IsPvEncryptionInTransitEnabled: common.Bool(true),
640+
DefinedTags: map[string]map[string]interface{}{},
641+
FreeformTags: map[string]string{
642+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
643+
ociutil.ClusterResourceIdentifier: "resource_uid",
644+
},
645+
}
646+
computeClient.EXPECT().LaunchInstance(gomock.Any(), gomock.Eq(core.LaunchInstanceRequest{
647+
LaunchInstanceDetails: launchDetails,
648+
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
649+
},
650+
},
554651
{
555652
name: "shape config is empty",
556653
errorExpected: false,

0 commit comments

Comments
 (0)