Skip to content

Commit 5432b75

Browse files
Add support for multiple NSGs in machine spec (#356)
1 parent fe5d306 commit 5432b75

10 files changed

+140
-7
lines changed

api/v1beta1/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ type NetworkDetails struct {
4444
SubnetName string `json:"subnetName,omitempty"`
4545

4646
// NSGId defines the ID of the NSG to use. This parameter takes priority over NsgNames.
47+
// Deprecated, please use NetworkDetails.NSGIds
4748
NSGId *string `json:"nsgId,omitempty"`
4849

50+
// NSGIds defines the list of NSG IDs to use. This parameter takes priority over NsgNames.
51+
NSGIds []string `json:"nsgIds,omitempty"`
52+
4953
// SkipSourceDestCheck defines whether the source/destination check is disabled on the VNIC.
5054
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`
5155

api/v1beta1/zz_generated.conversion.go

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

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ type NetworkDetails struct {
4848
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`
4949

5050
// NSGId defines the ID of the NSG to use. This parameter takes priority over NsgNames.
51+
// Deprecated, please use NetworkDetails.NSGIds
5152
NSGId *string `json:"nsgId,omitempty"`
5253

54+
// NSGIds defines the list of NSG IDs to use. This parameter takes priority over NsgNames.
55+
NSGIds []string `json:"nsgIds,omitempty"`
56+
5357
// NsgNames defines a list of the nsg names of the network security groups (NSGs) to add the VNIC to.
5458
NsgNames []string `json:"nsgNames,omitempty"`
5559

api/v1beta2/zz_generated.deepcopy.go

Lines changed: 5 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,
188188
}
189189

190190
var nsgIds []string
191+
machineNsgIds := m.OCIMachine.Spec.NetworkDetails.NSGIds
191192
nsgId := m.OCIMachine.Spec.NetworkDetails.NSGId
192-
if nsgId != nil {
193+
if machineNsgIds != nil && len(machineNsgIds) > 0 {
194+
nsgIds = machineNsgIds
195+
} else if nsgId != nil {
193196
nsgIds = []string{*nsgId}
194197
} else {
195198
if m.IsControlPlane() {

cloud/scope/machine_test.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,76 @@ func TestInstanceReconciliation(t *testing.T) {
455455
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
456456
},
457457
},
458+
{
459+
name: "check all params together, with subnet id set, nsg id list",
460+
errorExpected: false,
461+
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
462+
setupAllParams(ms)
463+
ms.OCIMachine.Spec.CapacityReservationId = common.String("cap-id")
464+
ms.OCIMachine.Spec.DedicatedVmHostId = common.String("dedicated-host-id")
465+
ms.OCIMachine.Spec.NetworkDetails.HostnameLabel = common.String("hostname-label")
466+
ms.OCIMachine.Spec.NetworkDetails.SubnetId = common.String("subnet-machine-id")
467+
ms.OCIMachine.Spec.NetworkDetails.NSGIds = []string{"nsg-machine-id-1", "nsg-machine-id-2"}
468+
// above array should take precedence
469+
ms.OCIMachine.Spec.NetworkDetails.NSGId = common.String("nsg-machine-id")
470+
ms.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck = common.Bool(true)
471+
ms.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord = common.Bool(true)
472+
ms.OCIMachine.Spec.NetworkDetails.DisplayName = common.String("display-name")
473+
ms.OCIMachine.Spec.InstanceSourceViaImageDetails = &infrastructurev1beta2.InstanceSourceViaImageConfig{
474+
KmsKeyId: common.String("kms-key-id"),
475+
BootVolumeVpusPerGB: common.Int64(32),
476+
}
477+
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
478+
DisplayName: common.String("name"),
479+
CompartmentId: common.String("test"),
480+
})).Return(core.ListInstancesResponse{}, nil)
481+
482+
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String("name"),
483+
CapacityReservationId: common.String("cap-id"),
484+
DedicatedVmHostId: common.String("dedicated-host-id"),
485+
SourceDetails: core.InstanceSourceViaImageDetails{
486+
ImageId: common.String("image"),
487+
BootVolumeSizeInGBs: common.Int64(120),
488+
KmsKeyId: common.String("kms-key-id"),
489+
BootVolumeVpusPerGB: common.Int64(32),
490+
},
491+
CreateVnicDetails: &core.CreateVnicDetails{
492+
SubnetId: common.String("subnet-machine-id"),
493+
AssignPublicIp: common.Bool(false),
494+
DefinedTags: map[string]map[string]interface{}{},
495+
FreeformTags: map[string]string{
496+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
497+
ociutil.ClusterResourceIdentifier: "resource_uid",
498+
},
499+
NsgIds: []string{"nsg-machine-id-1", "nsg-machine-id-2"},
500+
HostnameLabel: common.String("hostname-label"),
501+
SkipSourceDestCheck: common.Bool(true),
502+
AssignPrivateDnsRecord: common.Bool(true),
503+
DisplayName: common.String("display-name"),
504+
},
505+
Metadata: map[string]string{
506+
"user_data": base64.StdEncoding.EncodeToString([]byte("test")),
507+
},
508+
Shape: common.String("shape"),
509+
ShapeConfig: &core.LaunchInstanceShapeConfigDetails{
510+
Ocpus: common.Float32(2),
511+
MemoryInGBs: common.Float32(100),
512+
BaselineOcpuUtilization: core.LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8,
513+
},
514+
AvailabilityDomain: common.String("ad2"),
515+
CompartmentId: common.String("test"),
516+
IsPvEncryptionInTransitEnabled: common.Bool(true),
517+
DefinedTags: map[string]map[string]interface{}{},
518+
FreeformTags: map[string]string{
519+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
520+
ociutil.ClusterResourceIdentifier: "resource_uid",
521+
},
522+
}
523+
computeClient.EXPECT().LaunchInstance(gomock.Any(), gomock.Eq(core.LaunchInstanceRequest{
524+
LaunchInstanceDetails: launchDetails,
525+
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
526+
},
527+
},
458528
{
459529
name: "shape config is empty",
460530
errorExpected: false,

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,15 @@ spec:
204204
type: string
205205
nsgId:
206206
description: NSGId defines the ID of the NSG to use. This
207-
parameter takes priority over NsgNames.
207+
parameter takes priority over NsgNames. Deprecated, please
208+
use NetworkDetails.NSGIds
208209
type: string
210+
nsgIds:
211+
description: NSGIds defines the list of NSG IDs to use. This
212+
parameter takes priority over NsgNames.
213+
items:
214+
type: string
215+
type: array
209216
nsgNames:
210217
description: NsgNames defines a list of the nsg names of the
211218
network security groups (NSGs) to add the VNIC to.
@@ -925,8 +932,15 @@ spec:
925932
type: string
926933
nsgId:
927934
description: NSGId defines the ID of the NSG to use. This
928-
parameter takes priority over NsgNames.
935+
parameter takes priority over NsgNames. Deprecated, please
936+
use NetworkDetails.NSGIds
929937
type: string
938+
nsgIds:
939+
description: NSGIds defines the list of NSG IDs to use. This
940+
parameter takes priority over NsgNames.
941+
items:
942+
type: string
943+
type: array
930944
nsgNames:
931945
description: NsgNames defines a list of the nsg names of the
932946
network security groups (NSGs) to add the VNIC to.

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,14 @@ spec:
277277
type: string
278278
nsgId:
279279
description: NSGId defines the ID of the NSG to use. This parameter
280-
takes priority over NsgNames.
280+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
281281
type: string
282+
nsgIds:
283+
description: NSGIds defines the list of NSG IDs to use. This parameter
284+
takes priority over NsgNames.
285+
items:
286+
type: string
287+
type: array
282288
nsgNames:
283289
description: NsgNames defines a list of the nsg names of the network
284290
security groups (NSGs) to add the VNIC to.
@@ -1045,8 +1051,14 @@ spec:
10451051
type: string
10461052
nsgId:
10471053
description: NSGId defines the ID of the NSG to use. This parameter
1048-
takes priority over NsgNames.
1054+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
10491055
type: string
1056+
nsgIds:
1057+
description: NSGIds defines the list of NSG IDs to use. This parameter
1058+
takes priority over NsgNames.
1059+
items:
1060+
type: string
1061+
type: array
10501062
nsgNames:
10511063
description: NsgNames defines a list of the nsg names of the network
10521064
security groups (NSGs) to add the VNIC to.

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,15 @@ spec:
303303
type: string
304304
nsgId:
305305
description: NSGId defines the ID of the NSG to use. This
306-
parameter takes priority over NsgNames.
306+
parameter takes priority over NsgNames. Deprecated,
307+
please use NetworkDetails.NSGIds
307308
type: string
309+
nsgIds:
310+
description: NSGIds defines the list of NSG IDs to use.
311+
This parameter takes priority over NsgNames.
312+
items:
313+
type: string
314+
type: array
308315
nsgNames:
309316
description: NsgNames defines a list of the nsg names
310317
of the network security groups (NSGs) to add the VNIC
@@ -1051,8 +1058,15 @@ spec:
10511058
type: string
10521059
nsgId:
10531060
description: NSGId defines the ID of the NSG to use. This
1054-
parameter takes priority over NsgNames.
1061+
parameter takes priority over NsgNames. Deprecated,
1062+
please use NetworkDetails.NSGIds
10551063
type: string
1064+
nsgIds:
1065+
description: NSGIds defines the list of NSG IDs to use.
1066+
This parameter takes priority over NsgNames.
1067+
items:
1068+
type: string
1069+
type: array
10561070
nsgNames:
10571071
description: NsgNames defines a list of the nsg names
10581072
of the network security groups (NSGs) to add the VNIC

0 commit comments

Comments
 (0)