Skip to content

Commit 0f8f8f1

Browse files
Add support for multiple NSGs in machine spec (#356)
1 parent dd7f330 commit 0f8f8f1

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
@@ -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.
@@ -926,8 +933,15 @@ spec:
926933
type: string
927934
nsgId:
928935
description: NSGId defines the ID of the NSG to use. This
929-
parameter takes priority over NsgNames.
936+
parameter takes priority over NsgNames. Deprecated, please
937+
use NetworkDetails.NSGIds
930938
type: string
939+
nsgIds:
940+
description: NSGIds defines the list of NSG IDs to use. This
941+
parameter takes priority over NsgNames.
942+
items:
943+
type: string
944+
type: array
931945
nsgNames:
932946
description: NsgNames defines a list of the nsg names of the
933947
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
@@ -278,8 +278,14 @@ spec:
278278
type: string
279279
nsgId:
280280
description: NSGId defines the ID of the NSG to use. This parameter
281-
takes priority over NsgNames.
281+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
282282
type: string
283+
nsgIds:
284+
description: NSGIds defines the list of NSG IDs to use. This parameter
285+
takes priority over NsgNames.
286+
items:
287+
type: string
288+
type: array
283289
nsgNames:
284290
description: NsgNames defines a list of the nsg names of the network
285291
security groups (NSGs) to add the VNIC to.
@@ -1046,8 +1052,14 @@ spec:
10461052
type: string
10471053
nsgId:
10481054
description: NSGId defines the ID of the NSG to use. This parameter
1049-
takes priority over NsgNames.
1055+
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
10501056
type: string
1057+
nsgIds:
1058+
description: NSGIds defines the list of NSG IDs to use. This parameter
1059+
takes priority over NsgNames.
1060+
items:
1061+
type: string
1062+
type: array
10511063
nsgNames:
10521064
description: NsgNames defines a list of the nsg names of the network
10531065
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
@@ -304,8 +304,15 @@ spec:
304304
type: string
305305
nsgId:
306306
description: NSGId defines the ID of the NSG to use. This
307-
parameter takes priority over NsgNames.
307+
parameter takes priority over NsgNames. Deprecated,
308+
please use NetworkDetails.NSGIds
308309
type: string
310+
nsgIds:
311+
description: NSGIds defines the list of NSG IDs to use.
312+
This parameter takes priority over NsgNames.
313+
items:
314+
type: string
315+
type: array
309316
nsgNames:
310317
description: NsgNames defines a list of the nsg names
311318
of the network security groups (NSGs) to add the VNIC
@@ -1052,8 +1059,15 @@ spec:
10521059
type: string
10531060
nsgId:
10541061
description: NSGId defines the ID of the NSG to use. This
1055-
parameter takes priority over NsgNames.
1062+
parameter takes priority over NsgNames. Deprecated,
1063+
please use NetworkDetails.NSGIds
10561064
type: string
1065+
nsgIds:
1066+
description: NSGIds defines the list of NSG IDs to use.
1067+
This parameter takes priority over NsgNames.
1068+
items:
1069+
type: string
1070+
type: array
10571071
nsgNames:
10581072
description: NsgNames defines a list of the nsg names
10591073
of the network security groups (NSGs) to add the VNIC

0 commit comments

Comments
 (0)