Skip to content

Commit 9f74b45

Browse files
Add Subnet Id and NSG ID to machine spec (#291)
* Add Subnet Id and NSG ID to machine spec
1 parent cc93896 commit 9f74b45

12 files changed

+143
-38
lines changed

api/v1beta1/conversion.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package v1beta1
1818

1919
import (
20-
"errors"
2120
"github.com/oracle/cluster-api-provider-oci/api/v1beta2"
2221
"k8s.io/apimachinery/pkg/conversion"
2322
)
@@ -115,12 +114,6 @@ func Convert_v1beta1_OCIMachineSpec_To_v1beta2_OCIMachineSpec(in *OCIMachineSpec
115114
if err != nil {
116115
return err
117116
}
118-
if in.NetworkDetails.SubnetId != nil {
119-
return errors.New("deprecated field NetworkDetails.SubnetId is present in OCIMachineSpec")
120-
}
121-
if in.NetworkDetails.NSGId != nil {
122-
return errors.New("deprecated field NetworkDetails.NSGId is present in OCIMachineSpec")
123-
}
124117
if in.NSGName != "" && len(in.NetworkDetails.NsgNames) == 0 {
125118
out.NetworkDetails.NsgNames = []string{in.NSGName}
126119
}

api/v1beta1/conversion_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ func fuzzFuncs(_ runtimeserializer.CodecFactory) []interface{} {
4040
func OCIMachineFuzzer(obj *OCIMachine, c fuzz.Continue) {
4141
c.FuzzNoCustom(obj)
4242
// nil fields which have been removed so that tests dont fail
43-
obj.Spec.NetworkDetails.NSGId = nil
44-
obj.Spec.NetworkDetails.SubnetId = nil
4543
obj.Spec.NSGName = ""
4644
}
4745

@@ -92,8 +90,6 @@ func OCIClusterTemplateFuzzer(obj *OCIClusterTemplate, c fuzz.Continue) {
9290
func OCIMachineTemplateFuzzer(obj *OCIMachineTemplate, c fuzz.Continue) {
9391
c.FuzzNoCustom(obj)
9492
// nil fields which ave been removed so that tests dont fail
95-
obj.Spec.Template.Spec.NetworkDetails.NSGId = nil
96-
obj.Spec.Template.Spec.NetworkDetails.SubnetId = nil
9793
obj.Spec.Template.Spec.NSGName = ""
9894
}
9995

api/v1beta1/types.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ var OCIManagedClusterSubnetRoles = []Role{PodRole, ControlPlaneEndpointRole, Wor
3434

3535
// NetworkDetails defines the configuration options for the network
3636
type NetworkDetails struct {
37-
// SubnetId defines the ID of the subnet to use.
38-
// Deprecated, use SubnetName parameter
37+
// SubnetId defines the ID of the subnet to use. This parameter takes priority over SubnetName.
3938
SubnetId *string `json:"subnetId,omitempty"`
4039

4140
// AssignPublicIp defines whether the instance should have a public IP address
@@ -44,7 +43,7 @@ type NetworkDetails struct {
4443
// SubnetName defines the subnet name to use for the VNIC
4544
SubnetName string `json:"subnetName,omitempty"`
4645

47-
// Deprecated, use NsgNames parameter to define the NSGs
46+
// NSGId defines the ID of the NSG to use. This parameter takes priority over NsgNames.
4847
NSGId *string `json:"nsgId,omitempty"`
4948

5049
// SkipSourceDestCheck defines whether the source/destination check is disabled on the VNIC.

api/v1beta1/zz_generated.conversion.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ var OCIManagedClusterSubnetRoles = []Role{PodRole, ControlPlaneEndpointRole, Wor
3434

3535
// NetworkDetails defines the configuration options for the network
3636
type NetworkDetails struct {
37+
// SubnetId defines the ID of the subnet to use. This parameter takes priority over SubnetName.
38+
SubnetId *string `json:"subnetId,omitempty"`
39+
3740
// AssignPublicIp defines whether the instance should have a public IP address
3841
AssignPublicIp bool `json:"assignPublicIp,omitempty"`
3942

@@ -43,6 +46,9 @@ type NetworkDetails struct {
4346
// SkipSourceDestCheck defines whether the source/destination check is disabled on the VNIC.
4447
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`
4548

49+
// NSGId defines the ID of the NSG to use. This parameter takes priority over NsgNames.
50+
NSGId *string `json:"nsgId,omitempty"`
51+
4652
// NsgNames defines a list of the nsg names of the network security groups (NSGs) to add the VNIC to.
4753
NsgNames []string `json:"nsgNames,omitempty"`
4854

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cloud/scope/machine.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,25 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,
178178
sourceDetails.BootVolumeVpusPerGB = m.OCIMachine.Spec.InstanceSourceViaImageDetails.BootVolumeVpusPerGB
179179
}
180180

181-
var subnetId *string
182-
if m.IsControlPlane() {
183-
subnetId = m.getGetControlPlaneMachineSubnet()
184-
} else {
185-
subnetId = m.getWorkerMachineSubnet()
181+
subnetId := m.OCIMachine.Spec.NetworkDetails.SubnetId
182+
if subnetId == nil {
183+
if m.IsControlPlane() {
184+
subnetId = m.getGetControlPlaneMachineSubnet()
185+
} else {
186+
subnetId = m.getWorkerMachineSubnet()
187+
}
186188
}
187189

188190
var nsgIds []string
189-
if m.IsControlPlane() {
190-
nsgIds = m.getGetControlPlaneMachineNSGs()
191+
nsgId := m.OCIMachine.Spec.NetworkDetails.NSGId
192+
if nsgId != nil {
193+
nsgIds = []string{*nsgId}
191194
} else {
192-
nsgIds = m.getWorkerMachineNSGs()
195+
if m.IsControlPlane() {
196+
nsgIds = m.getGetControlPlaneMachineNSGs()
197+
} else {
198+
nsgIds = m.getWorkerMachineNSGs()
199+
}
193200
}
194201

195202
failureDomain := m.Machine.Spec.FailureDomain

cloud/scope/machine_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,74 @@ func TestInstanceReconciliation(t *testing.T) {
381381
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
382382
},
383383
},
384+
{
385+
name: "check all params together, with subnet id set",
386+
errorExpected: false,
387+
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
388+
setupAllParams(ms)
389+
ms.OCIMachine.Spec.CapacityReservationId = common.String("cap-id")
390+
ms.OCIMachine.Spec.DedicatedVmHostId = common.String("dedicated-host-id")
391+
ms.OCIMachine.Spec.NetworkDetails.HostnameLabel = common.String("hostname-label")
392+
ms.OCIMachine.Spec.NetworkDetails.SubnetId = common.String("subnet-machine-id")
393+
ms.OCIMachine.Spec.NetworkDetails.NSGId = common.String("nsg-machine-id")
394+
ms.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck = common.Bool(true)
395+
ms.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord = common.Bool(true)
396+
ms.OCIMachine.Spec.NetworkDetails.DisplayName = common.String("display-name")
397+
ms.OCIMachine.Spec.InstanceSourceViaImageDetails = &infrastructurev1beta2.InstanceSourceViaImageConfig{
398+
KmsKeyId: common.String("kms-key-id"),
399+
BootVolumeVpusPerGB: common.Int64(32),
400+
}
401+
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
402+
DisplayName: common.String("name"),
403+
CompartmentId: common.String("test"),
404+
})).Return(core.ListInstancesResponse{}, nil)
405+
406+
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String("name"),
407+
CapacityReservationId: common.String("cap-id"),
408+
DedicatedVmHostId: common.String("dedicated-host-id"),
409+
SourceDetails: core.InstanceSourceViaImageDetails{
410+
ImageId: common.String("image"),
411+
BootVolumeSizeInGBs: common.Int64(120),
412+
KmsKeyId: common.String("kms-key-id"),
413+
BootVolumeVpusPerGB: common.Int64(32),
414+
},
415+
CreateVnicDetails: &core.CreateVnicDetails{
416+
SubnetId: common.String("subnet-machine-id"),
417+
AssignPublicIp: common.Bool(false),
418+
DefinedTags: map[string]map[string]interface{}{},
419+
FreeformTags: map[string]string{
420+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
421+
ociutil.ClusterResourceIdentifier: "resource_uid",
422+
},
423+
NsgIds: []string{"nsg-machine-id"},
424+
HostnameLabel: common.String("hostname-label"),
425+
SkipSourceDestCheck: common.Bool(true),
426+
AssignPrivateDnsRecord: common.Bool(true),
427+
DisplayName: common.String("display-name"),
428+
},
429+
Metadata: map[string]string{
430+
"user_data": base64.StdEncoding.EncodeToString([]byte("test")),
431+
},
432+
Shape: common.String("shape"),
433+
ShapeConfig: &core.LaunchInstanceShapeConfigDetails{
434+
Ocpus: common.Float32(2),
435+
MemoryInGBs: common.Float32(100),
436+
BaselineOcpuUtilization: core.LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8,
437+
},
438+
AvailabilityDomain: common.String("ad2"),
439+
CompartmentId: common.String("test"),
440+
IsPvEncryptionInTransitEnabled: common.Bool(true),
441+
DefinedTags: map[string]map[string]interface{}{},
442+
FreeformTags: map[string]string{
443+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
444+
ociutil.ClusterResourceIdentifier: "resource_uid",
445+
},
446+
}
447+
computeClient.EXPECT().LaunchInstance(gomock.Any(), gomock.Eq(core.LaunchInstanceRequest{
448+
LaunchInstanceDetails: launchDetails,
449+
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
450+
},
451+
},
384452
{
385453
name: "shape config is empty",
386454
errorExpected: false,

config/crd/bases/infrastructure.cluster.x-k8s.io_ocimachinepools.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ spec:
204204
primary private IP. Used for DNS.
205205
type: string
206206
nsgId:
207-
description: "Deprecated, use \tNsgNames parameter to define
208-
the NSGs"
207+
description: NSGId defines the ID of the NSG to use. This
208+
parameter takes priority over NsgNames.
209209
type: string
210210
nsgNames:
211211
description: NsgNames defines a list of the nsg names of the
@@ -219,7 +219,7 @@ spec:
219219
type: boolean
220220
subnetId:
221221
description: SubnetId defines the ID of the subnet to use.
222-
Deprecated, use SubnetName parameter
222+
This parameter takes priority over SubnetName.
223223
type: string
224224
subnetName:
225225
description: SubnetName defines the subnet name to use for
@@ -920,6 +920,10 @@ spec:
920920
description: HostnameLabel defines the hostname for the VNIC's
921921
primary private IP. Used for DNS.
922922
type: string
923+
nsgId:
924+
description: NSGId defines the ID of the NSG to use. This
925+
parameter takes priority over NsgNames.
926+
type: string
923927
nsgNames:
924928
description: NsgNames defines a list of the nsg names of the
925929
network security groups (NSGs) to add the VNIC to.
@@ -930,6 +934,10 @@ spec:
930934
description: SkipSourceDestCheck defines whether the source/destination
931935
check is disabled on the VNIC.
932936
type: boolean
937+
subnetId:
938+
description: SubnetId defines the ID of the subnet to use.
939+
This parameter takes priority over SubnetName.
940+
type: string
933941
subnetName:
934942
description: SubnetName defines the subnet name to use for
935943
the VNIC

config/crd/bases/infrastructure.cluster.x-k8s.io_ocimachines.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ spec:
270270
primary private IP. Used for DNS.
271271
type: string
272272
nsgId:
273-
description: "Deprecated, use \tNsgNames parameter to define the
274-
NSGs"
273+
description: NSGId defines the ID of the NSG to use. This parameter
274+
takes priority over NsgNames.
275275
type: string
276276
nsgNames:
277277
description: NsgNames defines a list of the nsg names of the network
@@ -284,8 +284,8 @@ spec:
284284
check is disabled on the VNIC.
285285
type: boolean
286286
subnetId:
287-
description: SubnetId defines the ID of the subnet to use. Deprecated,
288-
use SubnetName parameter
287+
description: SubnetId defines the ID of the subnet to use. This
288+
parameter takes priority over SubnetName.
289289
type: string
290290
subnetName:
291291
description: SubnetName defines the subnet name to use for the
@@ -1030,6 +1030,10 @@ spec:
10301030
description: HostnameLabel defines the hostname for the VNIC's
10311031
primary private IP. Used for DNS.
10321032
type: string
1033+
nsgId:
1034+
description: NSGId defines the ID of the NSG to use. This parameter
1035+
takes priority over NsgNames.
1036+
type: string
10331037
nsgNames:
10341038
description: NsgNames defines a list of the nsg names of the network
10351039
security groups (NSGs) to add the VNIC to.
@@ -1040,6 +1044,10 @@ spec:
10401044
description: SkipSourceDestCheck defines whether the source/destination
10411045
check is disabled on the VNIC.
10421046
type: boolean
1047+
subnetId:
1048+
description: SubnetId defines the ID of the subnet to use. This
1049+
parameter takes priority over SubnetName.
1050+
type: string
10431051
subnetName:
10441052
description: SubnetName defines the subnet name to use for the
10451053
VNIC

config/crd/bases/infrastructure.cluster.x-k8s.io_ocimachinetemplates.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ spec:
295295
VNIC's primary private IP. Used for DNS.
296296
type: string
297297
nsgId:
298-
description: "Deprecated, use \tNsgNames parameter to
299-
define the NSGs"
298+
description: NSGId defines the ID of the NSG to use. This
299+
parameter takes priority over NsgNames.
300300
type: string
301301
nsgNames:
302302
description: NsgNames defines a list of the nsg names
@@ -311,7 +311,7 @@ spec:
311311
type: boolean
312312
subnetId:
313313
description: SubnetId defines the ID of the subnet to
314-
use. Deprecated, use SubnetName parameter
314+
use. This parameter takes priority over SubnetName.
315315
type: string
316316
subnetName:
317317
description: SubnetName defines the subnet name to use
@@ -1034,6 +1034,10 @@ spec:
10341034
description: HostnameLabel defines the hostname for the
10351035
VNIC's primary private IP. Used for DNS.
10361036
type: string
1037+
nsgId:
1038+
description: NSGId defines the ID of the NSG to use. This
1039+
parameter takes priority over NsgNames.
1040+
type: string
10371041
nsgNames:
10381042
description: NsgNames defines a list of the nsg names
10391043
of the network security groups (NSGs) to add the VNIC
@@ -1045,6 +1049,10 @@ spec:
10451049
description: SkipSourceDestCheck defines whether the source/destination
10461050
check is disabled on the VNIC.
10471051
type: boolean
1052+
subnetId:
1053+
description: SubnetId defines the ID of the subnet to
1054+
use. This parameter takes priority over SubnetName.
1055+
type: string
10481056
subnetName:
10491057
description: SubnetName defines the subnet name to use
10501058
for the VNIC

exp/api/v1beta1/zz_generated.conversion.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)