Skip to content

Commit

Permalink
Add support for multiple NSGs in machine spec (oracle#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamradhakrishnan committed Mar 22, 2024
1 parent 2177212 commit b4f68de
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 7 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ type NetworkDetails struct {
SubnetName string `json:"subnetName,omitempty"`

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

// NSGIds defines the list of NSG IDs to use. This parameter takes priority over NsgNames.
NSGIds []string `json:"nsgIds,omitempty"`

// SkipSourceDestCheck defines whether the source/destination check is disabled on the VNIC.
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ type NetworkDetails struct {
SkipSourceDestCheck *bool `json:"skipSourceDestCheck,omitempty"`

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

// NSGIds defines the list of NSG IDs to use. This parameter takes priority over NsgNames.
NSGIds []string `json:"nsgIds,omitempty"`

// NsgNames defines a list of the nsg names of the network security groups (NSGs) to add the VNIC to.
NsgNames []string `json:"nsgNames,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions api/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cloud/scope/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ func (m *MachineScope) GetOrCreateMachine(ctx context.Context) (*core.Instance,
}

var nsgIds []string
machineNsgIds := m.OCIMachine.Spec.NetworkDetails.NSGIds
nsgId := m.OCIMachine.Spec.NetworkDetails.NSGId
if nsgId != nil {
if machineNsgIds != nil && len(machineNsgIds) > 0 {
nsgIds = machineNsgIds
} else if nsgId != nil {
nsgIds = []string{*nsgId}
} else {
if m.IsControlPlane() {
Expand Down
70 changes: 70 additions & 0 deletions cloud/scope/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,76 @@ func TestInstanceReconciliation(t *testing.T) {
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
},
},
{
name: "check all params together, with subnet id set, nsg id list",
errorExpected: false,
testSpecificSetup: func(machineScope *MachineScope, computeClient *mock_compute.MockComputeClient) {
setupAllParams(ms)
ms.OCIMachine.Spec.CapacityReservationId = common.String("cap-id")
ms.OCIMachine.Spec.DedicatedVmHostId = common.String("dedicated-host-id")
ms.OCIMachine.Spec.NetworkDetails.HostnameLabel = common.String("hostname-label")
ms.OCIMachine.Spec.NetworkDetails.SubnetId = common.String("subnet-machine-id")
ms.OCIMachine.Spec.NetworkDetails.NSGIds = []string{"nsg-machine-id-1", "nsg-machine-id-2"}
// above array should take precedence
ms.OCIMachine.Spec.NetworkDetails.NSGId = common.String("nsg-machine-id")
ms.OCIMachine.Spec.NetworkDetails.SkipSourceDestCheck = common.Bool(true)
ms.OCIMachine.Spec.NetworkDetails.AssignPrivateDnsRecord = common.Bool(true)
ms.OCIMachine.Spec.NetworkDetails.DisplayName = common.String("display-name")
ms.OCIMachine.Spec.InstanceSourceViaImageDetails = &infrastructurev1beta2.InstanceSourceViaImageConfig{
KmsKeyId: common.String("kms-key-id"),
BootVolumeVpusPerGB: common.Int64(32),
}
computeClient.EXPECT().ListInstances(gomock.Any(), gomock.Eq(core.ListInstancesRequest{
DisplayName: common.String("name"),
CompartmentId: common.String("test"),
})).Return(core.ListInstancesResponse{}, nil)

launchDetails := core.LaunchInstanceDetails{DisplayName: common.String("name"),
CapacityReservationId: common.String("cap-id"),
DedicatedVmHostId: common.String("dedicated-host-id"),
SourceDetails: core.InstanceSourceViaImageDetails{
ImageId: common.String("image"),
BootVolumeSizeInGBs: common.Int64(120),
KmsKeyId: common.String("kms-key-id"),
BootVolumeVpusPerGB: common.Int64(32),
},
CreateVnicDetails: &core.CreateVnicDetails{
SubnetId: common.String("subnet-machine-id"),
AssignPublicIp: common.Bool(false),
DefinedTags: map[string]map[string]interface{}{},
FreeformTags: map[string]string{
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
ociutil.ClusterResourceIdentifier: "resource_uid",
},
NsgIds: []string{"nsg-machine-id-1", "nsg-machine-id-2"},
HostnameLabel: common.String("hostname-label"),
SkipSourceDestCheck: common.Bool(true),
AssignPrivateDnsRecord: common.Bool(true),
DisplayName: common.String("display-name"),
},
Metadata: map[string]string{
"user_data": base64.StdEncoding.EncodeToString([]byte("test")),
},
Shape: common.String("shape"),
ShapeConfig: &core.LaunchInstanceShapeConfigDetails{
Ocpus: common.Float32(2),
MemoryInGBs: common.Float32(100),
BaselineOcpuUtilization: core.LaunchInstanceShapeConfigDetailsBaselineOcpuUtilization8,
},
AvailabilityDomain: common.String("ad2"),
CompartmentId: common.String("test"),
IsPvEncryptionInTransitEnabled: common.Bool(true),
DefinedTags: map[string]map[string]interface{}{},
FreeformTags: map[string]string{
ociutil.CreatedBy: ociutil.OCIClusterAPIProvider,
ociutil.ClusterResourceIdentifier: "resource_uid",
},
}
computeClient.EXPECT().LaunchInstance(gomock.Any(), gomock.Eq(core.LaunchInstanceRequest{
LaunchInstanceDetails: launchDetails,
OpcRetryToken: ociutil.GetOPCRetryToken("machineuid")})).Return(core.LaunchInstanceResponse{}, nil)
},
},
{
name: "shape config is empty",
errorExpected: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,15 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This
parameter takes priority over NsgNames.
parameter takes priority over NsgNames. Deprecated, please
use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use. This
parameter takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names of the
network security groups (NSGs) to add the VNIC to.
Expand Down Expand Up @@ -922,8 +929,15 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This
parameter takes priority over NsgNames.
parameter takes priority over NsgNames. Deprecated, please
use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use. This
parameter takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names of the
network security groups (NSGs) to add the VNIC to.
Expand Down
16 changes: 14 additions & 2 deletions config/crd/bases/infrastructure.cluster.x-k8s.io_ocimachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,14 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This parameter
takes priority over NsgNames.
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use. This parameter
takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names of the network
security groups (NSGs) to add the VNIC to.
Expand Down Expand Up @@ -1032,8 +1038,14 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This parameter
takes priority over NsgNames.
takes priority over NsgNames. Deprecated, please use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use. This parameter
takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names of the network
security groups (NSGs) to add the VNIC to.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,15 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This
parameter takes priority over NsgNames.
parameter takes priority over NsgNames. Deprecated,
please use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use.
This parameter takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names
of the network security groups (NSGs) to add the VNIC
Expand Down Expand Up @@ -1036,8 +1043,15 @@ spec:
type: string
nsgId:
description: NSGId defines the ID of the NSG to use. This
parameter takes priority over NsgNames.
parameter takes priority over NsgNames. Deprecated,
please use NetworkDetails.NSGIds
type: string
nsgIds:
description: NSGIds defines the list of NSG IDs to use.
This parameter takes priority over NsgNames.
items:
type: string
type: array
nsgNames:
description: NsgNames defines a list of the nsg names
of the network security groups (NSGs) to add the VNIC
Expand Down

0 comments on commit b4f68de

Please sign in to comment.