Skip to content

Commit 3c31d78

Browse files
Merge pull request #293 from oracle/mp/torontoSupport
Remove check for number of subnets
2 parents d5dc7a0 + 06a723b commit 3c31d78

File tree

3 files changed

+102
-23
lines changed

3 files changed

+102
-23
lines changed

pkg/cloudprovider/providers/oci/load_balancer.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,12 @@ func (cp *CloudProvider) EnsureLoadBalancer(ctx context.Context, clusterName str
323323
secretBackendSetString := service.Annotations[ServiceAnnotationLoadBalancerTLSBackendSetSecret]
324324
sslConfig = NewSSLConfig(secretListenerString, secretBackendSetString, ports, cp)
325325
}
326-
subnets := []string{cp.config.LoadBalancer.Subnet1, cp.config.LoadBalancer.Subnet2}
326+
var subnets []string
327+
if cp.config.LoadBalancer.Subnet2 != "" {
328+
subnets = []string{cp.config.LoadBalancer.Subnet1, cp.config.LoadBalancer.Subnet2}
329+
} else {
330+
subnets = []string{cp.config.LoadBalancer.Subnet1}
331+
}
327332
spec, err := NewLBSpec(service, nodes, subnets, sslConfig, cp.securityListManagerFactory)
328333
if err != nil {
329334
logger.With(zap.Error(err)).Error("Failed to derive LBSpec")

pkg/cloudprovider/providers/oci/load_balancer_spec.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,11 @@ type LBSpec struct {
9595

9696
// NewLBSpec creates a LB Spec from a Kubernetes service and a slice of nodes.
9797
func NewLBSpec(svc *v1.Service, nodes []*v1.Node, defaultSubnets []string, sslConfig *SSLConfig, secListFactory securityListManagerFactory) (*LBSpec, error) {
98-
if len(defaultSubnets) != 2 {
99-
return nil, errors.New("default subnets incorrectly configured")
100-
}
98+
// Disable check for whether there are two subnets, rely on OCI to decide whether the number of subnets is correct
99+
// This allows LoadBalancers to be created in single AD regions
100+
// if len(defaultSubnets) != 2 {
101+
// return nil, errors.New("default subnets incorrectly configured")
102+
// }
101103

102104
if err := validateService(svc); err != nil {
103105
return nil, errors.Wrap(err, "invalid service")
@@ -134,11 +136,14 @@ func NewLBSpec(svc *v1.Service, nodes []*v1.Node, defaultSubnets []string, sslCo
134136
return nil, errors.Errorf("a configuration for subnet1 must be specified for an internal load balancer")
135137
}
136138
subnets = subnets[:1]
137-
} else {
138-
if subnets[0] == "" || subnets[1] == "" {
139-
return nil, errors.Errorf("a configuration for both subnets must be specified")
140-
}
141139
}
140+
// Disable check for whether there are two subnets, rely on OCI to decide whether the number of subnets is correct
141+
// This allows LoadBalancers to be created in single AD regions
142+
// else {
143+
// if subnets[0] == "" || subnets[1] == "" {
144+
// return nil, errors.Errorf("a configuration for both subnets must be specified")
145+
// }
146+
// }
142147

143148
listeners, err := getListeners(svc, sslConfig)
144149
if err != nil {

pkg/cloudprovider/providers/oci/load_balancer_spec_test.go

Lines changed: 84 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,90 @@ func TestNewLBSpecSuccess(t *testing.T) {
503503
}
504504
}
505505

506+
func TestNewLBSpecSingleAD(t *testing.T) {
507+
testCases := map[string]struct {
508+
defaultSubnetOne string
509+
defaultSubnetTwo string
510+
nodes []*v1.Node
511+
service *v1.Service
512+
expected *LBSpec
513+
}{
514+
"single subnet for single AD": {
515+
defaultSubnetOne: "one",
516+
service: &v1.Service{
517+
ObjectMeta: metav1.ObjectMeta{
518+
Namespace: "kube-system",
519+
Name: "testservice",
520+
UID: "test-uid",
521+
Annotations: map[string]string{
522+
ServiceAnnotationLoadBalancerBEProtocol: "",
523+
ServiceAnnotationLoadBalancerSubnet1: "annotation-one",
524+
},
525+
},
526+
Spec: v1.ServiceSpec{
527+
SessionAffinity: v1.ServiceAffinityNone,
528+
Ports: []v1.ServicePort{
529+
v1.ServicePort{
530+
Protocol: v1.ProtocolTCP,
531+
Port: int32(80),
532+
},
533+
},
534+
},
535+
},
536+
expected: &LBSpec{
537+
Name: "test-uid",
538+
Shape: "100Mbps",
539+
Internal: false,
540+
Subnets: []string{"annotation-one"},
541+
Listeners: map[string]loadbalancer.ListenerDetails{
542+
"TCP-80": loadbalancer.ListenerDetails{
543+
DefaultBackendSetName: common.String("TCP-80"),
544+
Port: common.Int(80),
545+
Protocol: common.String("TCP"),
546+
},
547+
},
548+
BackendSets: map[string]loadbalancer.BackendSetDetails{
549+
"TCP-80": loadbalancer.BackendSetDetails{
550+
Backends: []loadbalancer.BackendDetails{},
551+
HealthChecker: &loadbalancer.HealthCheckerDetails{
552+
Protocol: common.String("HTTP"),
553+
Port: common.Int(10256),
554+
UrlPath: common.String("/healthz"),
555+
},
556+
Policy: common.String("ROUND_ROBIN"),
557+
},
558+
},
559+
SourceCIDRs: []string{"0.0.0.0/0"},
560+
Ports: map[string]portSpec{
561+
"TCP-80": portSpec{
562+
ListenerPort: 80,
563+
HealthCheckerPort: 10256,
564+
},
565+
},
566+
securityListManager: newSecurityListManagerNOOP(),
567+
},
568+
},
569+
}
570+
for name, tc := range testCases {
571+
t.Run(name, func(t *testing.T) {
572+
// we expect the service to be unchanged
573+
tc.expected.service = tc.service
574+
subnets := []string{tc.defaultSubnetOne}
575+
slManagerFactory := func(mode string) securityListManager {
576+
return newSecurityListManagerNOOP()
577+
}
578+
result, err := NewLBSpec(tc.service, tc.nodes, subnets, nil, slManagerFactory)
579+
if err != nil {
580+
t.Error(err)
581+
}
582+
583+
if !reflect.DeepEqual(result, tc.expected) {
584+
t.Errorf("Expected load balancer spec\n%+v\nbut got\n%+v", tc.expected, result)
585+
}
586+
})
587+
}
588+
}
589+
506590
func TestNewLBSpecFailure(t *testing.T) {
507591
testCases := map[string]struct {
508592
defaultSubnetOne string
@@ -566,21 +650,6 @@ func TestNewLBSpecFailure(t *testing.T) {
566650
},
567651
expectedErrMsg: "error parsing service annotation: service.beta.kubernetes.io/oci-load-balancer-connection-idle-timeout=whoops",
568652
},
569-
"missing subnet defaults and annotations": {
570-
service: &v1.Service{
571-
ObjectMeta: metav1.ObjectMeta{
572-
Namespace: "kube-system",
573-
Name: "testservice",
574-
UID: "test-uid",
575-
Annotations: map[string]string{},
576-
},
577-
Spec: v1.ServiceSpec{
578-
SessionAffinity: v1.ServiceAffinityNone,
579-
Ports: []v1.ServicePort{},
580-
},
581-
},
582-
expectedErrMsg: "a configuration for both subnets must be specified",
583-
},
584653
"internal lb missing subnet1": {
585654
defaultSubnetTwo: "two",
586655
service: &v1.Service{

0 commit comments

Comments
 (0)