Skip to content

Commit b4f68de

Browse files
Add support for multiple NSGs in machine spec (#356)
1 parent 2177212 commit b4f68de

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
@@ -47,8 +47,12 @@ type NetworkDetails struct {
4747
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`
4848

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

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

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
@@ -453,6 +453,76 @@ func TestInstanceReconciliation(t *testing.T) {
453453
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
454454
},
455455
},
456+
{
457+
name: "check all params together, with subnet id set, nsg id list",
458+
errorExpected: false,
459+
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
460+
setupAllParams(ms)
461+
ms.OCIMachine.Spec.CapacityReservationId = common.String("cap-id")
462+
ms.OCIMachine.Spec.DedicatedVmHostId = common.String("dedicated-host-id")
463+
ms.OCIMachine.Spec.NetworkDetails.HostnameLabel = common.String("hostname-label")
464+
ms.OCIMachine.Spec.NetworkDetails.SubnetId = common.String("subnet-machine-id")
465+
ms.OCIMachine.Spec.NetworkDetails.NSGIds = []string{"nsg-machine-id-1", "nsg-machine-id-2"}
466+
// above array should take precedence
467+
ms.OCIMachine.Spec.NetworkDetails.NSGId = common.String("nsg-machine-id")
468+
ms.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck = common.Bool(true)
469+
ms.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord = common.Bool(true)
470+
ms.OCIMachine.Spec.NetworkDetails.DisplayName = common.String("display-name")
471+
ms.OCIMachine.Spec.InstanceSourceViaImageDetails = &infrastructurev1beta2.InstanceSourceViaImageConfig{
472+
KmsKeyId: common.String("kms-key-id"),
473+
BootVolumeVpusPerGB: common.Int64(32),
474+
}
475+
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
476+
DisplayName: common.String("name"),
477+
CompartmentId: common.String("test"),
478+
})).Return(core.ListInstancesResponse{}, nil)
479+
480+
launchDetails := core.LaunchInstanceDetails{DisplayName: common.String("name"),
481+
CapacityReservationId: common.String("cap-id"),
482+
DedicatedVmHostId: common.String("dedicated-host-id"),
483+
SourceDetails: core.InstanceSourceViaImageDetails{
484+
ImageId: common.String("image"),
485+
BootVolumeSizeInGBs: common.Int64(120),
486+
KmsKeyId: common.String("kms-key-id"),
487+
BootVolumeVpusPerGB: common.Int64(32),
488+
},
489+
CreateVnicDetails: &core.CreateVnicDetails{
490+
SubnetId: common.String("subnet-machine-id"),
491+
AssignPublicIp: common.Bool(false),
492+
DefinedTags: map[string]map[string]interface{}{},
493+
FreeformTags: map[string]string{
494+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
495+
ociutil.ClusterResourceIdentifier: "resource_uid",
496+
},
497+
NsgIds: []string{"nsg-machine-id-1", "nsg-machine-id-2"},
498+
HostnameLabel: common.String("hostname-label"),
499+
SkipSourceDestCheck: common.Bool(true),
500+
AssignPrivateDnsRecord: common.Bool(true),
501+
DisplayName: common.String("display-name"),
502+
},
503+
Metadata: map[string]string{
504+
"user_data": base64.StdEncoding.EncodeToString([]byte("test")),
505+
},
506+
Shape: common.String("shape"),
507+
ShapeConfig: &core.LaunchInstanceShapeConfigDetails{
508+
Ocpus: common.Float32(2),
509+
MemoryInGBs: common.Float32(100),
510+
BaselineOcpuUtilization: core.LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8,
511+
},
512+
AvailabilityDomain: common.String("ad2"),
513+
CompartmentId: common.String("test"),
514+
IsPvEncryptionInTransitEnabled: common.Bool(true),
515+
DefinedTags: map[string]map[string]interface{}{},
516+
FreeformTags: map[string]string{
517+
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
518+
ociutil.ClusterResourceIdentifier: "resource_uid",
519+
},
520+
}
521+
computeClient.EXPECT().LaunchInstance(gomock.Any(), gomock.Eq(core.LaunchInstanceRequest{
522+
LaunchInstanceDetails: launchDetails,
523+
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
524+
},
525+
},
456526
{
457527
name: "shape config is empty",
458528
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
@@ -205,8 +205,15 @@ spec:
205205
type: string
206206
nsgId:
207207
description: NSGId defines the ID of the NSG to use. This
208-
parameter takes priority over NsgNames.
208+
parameter takes priority over NsgNames. Deprecated, please
209+
use NetworkDetails.NSGIds
209210
type: string
211+
nsgIds:
212+
description: NSGIds defines the list of NSG IDs to use. This
213+
parameter takes priority over NsgNames.
214+
items:
215+
type: string
216+
type: array
210217
nsgNames:
211218
description: NsgNames defines a list of the nsg names of the
212219
network security groups (NSGs) to add the VNIC to.
@@ -922,8 +929,15 @@ spec:
922929
type: string
923930
nsgId:
924931
description: NSGId defines the ID of the NSG to use. This
925-
parameter takes priority over NsgNames.
932+
parameter takes priority over NsgNames. Deprecated, please
933+
use NetworkDetails.NSGIds
926934
type: string
935+
nsgIds:
936+
description: NSGIds defines the list of NSG IDs to use. This
937+
parameter takes priority over NsgNames.
938+
items:
939+
type: string
940+
type: array
927941
nsgNames:
928942
description: NsgNames defines a list of the nsg names of the
929943
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
@@ -271,8 +271,14 @@ spec:
271271
type: string
272272
nsgId:
273273
description: NSGId defines the ID of the NSG to use. This parameter
274-
takes priority over NsgNames.
274+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
275275
type: string
276+
nsgIds:
277+
description: NSGIds defines the list of NSG IDs to use. This parameter
278+
takes priority over NsgNames.
279+
items:
280+
type: string
281+
type: array
276282
nsgNames:
277283
description: NsgNames defines a list of the nsg names of the network
278284
security groups (NSGs) to add the VNIC to.
@@ -1032,8 +1038,14 @@ spec:
10321038
type: string
10331039
nsgId:
10341040
description: NSGId defines the ID of the NSG to use. This parameter
1035-
takes priority over NsgNames.
1041+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
10361042
type: string
1043+
nsgIds:
1044+
description: NSGIds defines the list of NSG IDs to use. This parameter
1045+
takes priority over NsgNames.
1046+
items:
1047+
type: string
1048+
type: array
10371049
nsgNames:
10381050
description: NsgNames defines a list of the nsg names of the network
10391051
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
@@ -296,8 +296,15 @@ spec:
296296
type: string
297297
nsgId:
298298
description: NSGId defines the ID of the NSG to use. This
299-
parameter takes priority over NsgNames.
299+
parameter takes priority over NsgNames. Deprecated,
300+
please use NetworkDetails.NSGIds
300301
type: string
302+
nsgIds:
303+
description: NSGIds defines the list of NSG IDs to use.
304+
This parameter takes priority over NsgNames.
305+
items:
306+
type: string
307+
type: array
301308
nsgNames:
302309
description: NsgNames defines a list of the nsg names
303310
of the network security groups (NSGs) to add the VNIC
@@ -1036,8 +1043,15 @@ spec:
10361043
type: string
10371044
nsgId:
10381045
description: NSGId defines the ID of the NSG to use. This
1039-
parameter takes priority over NsgNames.
1046+
parameter takes priority over NsgNames. Deprecated,
1047+
please use NetworkDetails.NSGIds
10401048
type: string
1049+
nsgIds:
1050+
description: NSGIds defines the list of NSG IDs to use.
1051+
This parameter takes priority over NsgNames.
1052+
items:
1053+
type: string
1054+
type: array
10411055
nsgNames:
10421056
description: NsgNames defines a list of the nsg names
10431057
of the network security groups (NSGs) to add the VNIC

0 commit comments

Comments
 (0)