Skip to content
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
6 changes: 6 additions & 0 deletions api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,12 @@ type NLBSpec struct {
// BackendSetDetails specifies the configuration of a network load balancer backend set.
// +optional
BackendSetDetails BackendSetDetails `json:"backendSetDetails,omitempty"`

// A list of a reserved Ip OCID
// Min Items: 0
// Max Items: 1
// +optional
ReservedIpIds []string `json:"reservedIpIds,omitempty"`
}

// BackendSetDetails specifies the configuration of a network load balancer backend set.
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.

6 changes: 6 additions & 0 deletions api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ type NLBSpec struct {
// BackendSetDetails specifies the configuration of a network load balancer backend set.
// +optional
BackendSetDetails BackendSetDetails `json:"backendSetDetails,omitempty"`

// A list of a reserved Ip OCID
// Min Items: 0
// Max Items: 1
// +optional
ReservedIpIds []string `json:"reservedIpIds,omitempty"`
}

// BackendSetDetails specifies the configuration of a network load balancer backend set.
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.

7 changes: 7 additions & 0 deletions cloud/scope/network_load_balancer_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func (s *ClusterScope) CreateNLB(ctx context.Context, lb infrastructurev1beta2.L
}
}
}
var reservedIps []networkloadbalancer.ReservedIp
if len(lb.NLBSpec.ReservedIpIds) > 0 {
// since max is one we only take the first ip id supplied
reservedIps = append(reservedIps, networkloadbalancer.ReservedIp{Id: common.String(lb.NLBSpec.ReservedIpIds[0])})
}

if len(controlPlaneEndpointSubnets) < 1 {
return nil, nil, errors.New("control plane endpoint subnet not provided")
}
Expand All @@ -199,6 +205,7 @@ func (s *ClusterScope) CreateNLB(ctx context.Context, lb infrastructurev1beta2.L
BackendSets: backendSetDetails,
FreeformTags: s.GetFreeFormTags(),
DefinedTags: s.GetDefinedTags(),
ReservedIps: reservedIps,
}
nsgs := make([]string, 0)
for _, nsg := range ptr.ToNSGSlice(s.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup.List) {
Expand Down
112 changes: 112 additions & 0 deletions cloud/scope/network_load_balancer_reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,118 @@ func TestNLBReconciliation(t *testing.T) {
}, nil)
},
},
{
name: "create network load balancer, reserved ip",
errorExpected: false,
testSpecificSetup: func(clusterScope *ClusterScope, nlbClient *mock_nlb.MockNetworkLoadBalancerClient) {
clusterScope.OCIClusterAccessor.GetNetworkSpec().Vcn.Subnets = []*infrastructurev1beta2.Subnet{
{
Role: infrastructurev1beta2.ControlPlaneEndpointRole,
ID: common.String("s1"),
},
}
clusterScope.OCIClusterAccessor.GetNetworkSpec().Vcn.NetworkSecurityGroup = infrastructurev1beta2.NetworkSecurityGroup{
List: []*infrastructurev1beta2.NSG{
{
Role: infrastructurev1beta2.ControlPlaneEndpointRole,
ID: common.String("nsg1"),
},
{
Role: infrastructurev1beta2.ControlPlaneEndpointRole,
ID: common.String("nsg2"),
},
},
}
clusterScope.OCIClusterAccessor.GetNetworkSpec().APIServerLB = infrastructurev1beta2.LoadBalancer{
NLBSpec: infrastructurev1beta2.NLBSpec{
ReservedIpIds: []string{"ocid1.publicip.oc1.iad.testocid"},
BackendSetDetails: infrastructurev1beta2.BackendSetDetails{
IsInstantFailoverEnabled: common.Bool(true),
IsFailOpen: common.Bool(false),
IsPreserveSource: common.Bool(false),
HealthChecker: infrastructurev1beta2.HealthChecker{
UrlPath: common.String("readyz"),
},
},
},
}
definedTags, definedTagsInterface := getDefinedTags()
ociClusterAccessor.OCICluster.Spec.DefinedTags = definedTags
nlbClient.EXPECT().ListNetworkLoadBalancers(gomock.Any(), gomock.Eq(networkloadbalancer.ListNetworkLoadBalancersRequest{
CompartmentId: common.String("compartment-id"),
DisplayName: common.String(fmt.Sprintf("%s-%s", "cluster", "apiserver")),
})).
Return(networkloadbalancer.ListNetworkLoadBalancersResponse{}, nil)
nlbClient.EXPECT().CreateNetworkLoadBalancer(gomock.Any(), gomock.Eq(networkloadbalancer.CreateNetworkLoadBalancerRequest{
CreateNetworkLoadBalancerDetails: networkloadbalancer.CreateNetworkLoadBalancerDetails{
CompartmentId: common.String("compartment-id"),
DisplayName: common.String(fmt.Sprintf("%s-%s", "cluster", "apiserver")),
SubnetId: common.String("s1"),
IsPrivate: common.Bool(false),
NetworkSecurityGroupIds: []string{"nsg1", "nsg2"},
Listeners: map[string]networkloadbalancer.ListenerDetails{
APIServerLBListener: {
Protocol: networkloadbalancer.ListenerProtocolsTcp,
Port: common.Int(6443),
DefaultBackendSetName: common.String(APIServerLBBackendSetName),
Name: common.String(APIServerLBListener),
},
},
ReservedIps: []networkloadbalancer.ReservedIp{networkloadbalancer.ReservedIp{Id: common.String("ocid1.publicip.oc1.iad.testocid")}},
BackendSets: map[string]networkloadbalancer.BackendSetDetails{
APIServerLBBackendSetName: networkloadbalancer.BackendSetDetails{
Policy: LoadBalancerPolicy,
IsInstantFailoverEnabled: common.Bool(true),
IsFailOpen: common.Bool(false),
IsPreserveSource: common.Bool(false),
HealthChecker: &networkloadbalancer.HealthChecker{
Port: common.Int(6443),
Protocol: networkloadbalancer.HealthCheckProtocolsHttps,
UrlPath: common.String("readyz"),
ReturnCode: common.Int(200),
},
Backends: []networkloadbalancer.Backend{},
},
},
FreeformTags: tags,
DefinedTags: definedTagsInterface,
},
OpcRetryToken: ociutil.GetOPCRetryToken("%s-%s", "create-nlb", string("resource_uid")),
})).
Return(networkloadbalancer.CreateNetworkLoadBalancerResponse{
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{
Id: common.String("nlb-id"),
},
OpcWorkRequestId: common.String("opc-wr-id"),
}, nil)
nlbClient.EXPECT().GetWorkRequest(gomock.Any(), gomock.Eq(networkloadbalancer.GetWorkRequestRequest{
WorkRequestId: common.String("opc-wr-id"),
})).Return(networkloadbalancer.GetWorkRequestResponse{
WorkRequest: networkloadbalancer.WorkRequest{
Status: networkloadbalancer.OperationStatusSucceeded,
},
}, nil)

nlbClient.EXPECT().GetNetworkLoadBalancer(gomock.Any(), gomock.Eq(networkloadbalancer.GetNetworkLoadBalancerRequest{
NetworkLoadBalancerId: common.String("nlb-id"),
})).
Return(networkloadbalancer.GetNetworkLoadBalancerResponse{
NetworkLoadBalancer: networkloadbalancer.NetworkLoadBalancer{
Id: common.String("nlb-id"),
FreeformTags: tags,
DefinedTags: make(map[string]map[string]interface{}),
IsPrivate: common.Bool(false),
DisplayName: common.String(fmt.Sprintf("%s-%s", "cluster", "apiserver")),
IpAddresses: []networkloadbalancer.IpAddress{
{
IpAddress: common.String("2.2.2.2"),
IsPublic: common.Bool(true),
},
},
},
}, nil)
},
},
{
name: "create network load balancer request fails",
errorExpected: true,
Expand Down
Loading