Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple NSGs in machine spec #356

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -48,8 +48,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 @@ -455,6 +455,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 @@ -204,8 +204,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 @@ -925,8 +932,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 @@ -277,8 +277,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 @@ -1045,8 +1051,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 @@ -303,8 +303,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 @@ -1051,8 +1058,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