Skip to content

Commit f3c63b1

Browse files
authored
Merge pull request kubernetes#92839 from kishorj/nlb_external
AWS cloudprovider allow external management of LB types nlb-ip and external
2 parents a4103df + 2dc4e6e commit f3c63b1

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

staging/src/k8s.io/legacy-cloud-providers/aws/aws.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,6 +3668,9 @@ func buildListener(port v1.ServicePort, annotations map[string]string, sslPorts
36683668
// EnsureLoadBalancer implements LoadBalancer.EnsureLoadBalancer
36693669
func (c *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, apiService *v1.Service, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
36703670
annotations := apiService.Annotations
3671+
if isLBExternal(annotations) {
3672+
return nil, cloudprovider.ImplementedElsewhere
3673+
}
36713674
klog.V(2).Infof("EnsureLoadBalancer(%v, %v, %v, %v, %v, %v, %v)",
36723675
clusterName, apiService.Namespace, apiService.Name, c.region, apiService.Spec.LoadBalancerIP, apiService.Spec.Ports, annotations)
36733676

@@ -3679,7 +3682,6 @@ func (c *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, apiS
36793682
if len(apiService.Spec.Ports) == 0 {
36803683
return nil, fmt.Errorf("requested load balancer with no ports")
36813684
}
3682-
36833685
// Figure out what mappings we want on the load balancer
36843686
listeners := []*elb.Listener{}
36853687
v2Mappings := []nlbPortMapping{}
@@ -4065,6 +4067,9 @@ func (c *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, apiS
40654067

40664068
// GetLoadBalancer is an implementation of LoadBalancer.GetLoadBalancer
40674069
func (c *Cloud) GetLoadBalancer(ctx context.Context, clusterName string, service *v1.Service) (*v1.LoadBalancerStatus, bool, error) {
4070+
if isLBExternal(service.Annotations) {
4071+
return nil, false, nil
4072+
}
40684073
loadBalancerName := c.GetLoadBalancerName(ctx, clusterName, service)
40694074

40704075
if isNLB(service.Annotations) {
@@ -4325,6 +4330,9 @@ func (c *Cloud) updateInstanceSecurityGroupsForLoadBalancer(lb *elb.LoadBalancer
43254330

43264331
// EnsureLoadBalancerDeleted implements LoadBalancer.EnsureLoadBalancerDeleted.
43274332
func (c *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName string, service *v1.Service) error {
4333+
if isLBExternal(service.Annotations) {
4334+
return nil
4335+
}
43284336
loadBalancerName := c.GetLoadBalancerName(ctx, clusterName, service)
43294337

43304338
if isNLB(service.Annotations) {
@@ -4509,11 +4517,13 @@ func (c *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName strin
45094517

45104518
// UpdateLoadBalancer implements LoadBalancer.UpdateLoadBalancer
45114519
func (c *Cloud) UpdateLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) error {
4520+
if isLBExternal(service.Annotations) {
4521+
return cloudprovider.ImplementedElsewhere
4522+
}
45124523
instances, err := c.findInstancesForELB(nodes, service.Annotations)
45134524
if err != nil {
45144525
return err
45154526
}
4516-
45174527
loadBalancerName := c.GetLoadBalancerName(ctx, clusterName, service)
45184528
if isNLB(service.Annotations) {
45194529
lb, err := c.describeLoadBalancerv2(loadBalancerName)

staging/src/k8s.io/legacy-cloud-providers/aws/aws_loadbalancer.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ func isNLB(annotations map[string]string) bool {
6969
return false
7070
}
7171

72+
func isLBExternal(annotations map[string]string) bool {
73+
if val := annotations[ServiceAnnotationLoadBalancerType]; val == "nlb-ip" || val == "external" {
74+
return true
75+
}
76+
return false
77+
}
78+
7279
type nlbPortMapping struct {
7380
FrontendPort int64
7481
FrontendProtocol string

staging/src/k8s.io/legacy-cloud-providers/aws/aws_loadbalancer_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,43 @@ func TestIsNLB(t *testing.T) {
168168
}
169169
}
170170

171+
func TestIsLBExternal(t *testing.T) {
172+
tests := []struct {
173+
name string
174+
annotations map[string]string
175+
want bool
176+
}{
177+
{
178+
name: "No annotation",
179+
annotations: map[string]string{},
180+
want: false,
181+
},
182+
{
183+
name: "Type NLB",
184+
annotations: map[string]string{"service.beta.kubernetes.io/aws-load-balancer-type": "nlb"},
185+
want: false,
186+
},
187+
{
188+
name: "Type NLB-IP",
189+
annotations: map[string]string{"service.beta.kubernetes.io/aws-load-balancer-type": "nlb-ip"},
190+
want: true,
191+
},
192+
{
193+
name: "Type External",
194+
annotations: map[string]string{"service.beta.kubernetes.io/aws-load-balancer-type": "external"},
195+
want: true,
196+
},
197+
}
198+
for _, test := range tests {
199+
t.Logf("Running test case %s", test.name)
200+
got := isLBExternal(test.annotations)
201+
202+
if got != test.want {
203+
t.Errorf("Incorrect value for isLBExternal() case %s. Got %t, expected %t.", test.name, got, test.want)
204+
}
205+
}
206+
}
207+
171208
func TestSyncElbListeners(t *testing.T) {
172209
tests := []struct {
173210
name string

0 commit comments

Comments
 (0)