Skip to content

Commit 8d02ff5

Browse files
committed
fixup! controller support for mixed protocol LB services
1 parent 72ed8d1 commit 8d02ff5

File tree

2 files changed

+46
-44
lines changed

2 files changed

+46
-44
lines changed

providers/gce/gce_loadbalancer.go

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -145,28 +145,28 @@ func (g *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, svc
145145
return nil, err
146146
}
147147

148-
// Services with multiples protocols are not supported by this controller, warn the users and sets
149-
// the corresponding Service Status Condition.
148+
// Services with multiples protocols are not supported by this controller (without AlphaFeatureMultiProtocolLB),
149+
// warn the users and set the corresponding Service Status Condition.
150150
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1435-mixed-protocol-lb
151-
if !g.AlphaFeatureGate.Enabled(AlphaFeatureMultiProtocolLB) {
152-
if err := checkMixedProtocol(svc.Spec.Ports); err != nil {
153-
if hasLoadBalancerPortsError(svc) {
154-
return nil, err
155-
}
156-
klog.Warningf("Ignoring service %s/%s using different ports protocols", svc.Namespace, svc.Name)
157-
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancers with multiple protocols are not supported.")
158-
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
159-
metav1apply.Condition().
160-
WithType(v1.LoadBalancerPortsError).
161-
WithStatus(metav1.ConditionTrue).
162-
WithReason(v1.LoadBalancerPortsErrorReason).
163-
WithMessage("LoadBalancer with multiple protocols are not supported"))
164-
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
165-
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
166-
return nil, errApply
167-
}
151+
if g.AlphaFeatureGate.Enabled(AlphaFeatureMultiProtocolLB) {
152+
klog.Infof("AlphaFeatureMultiProtocolLB feature gate is enabled")
153+
} else if err := checkMixedProtocol(svc.Spec.Ports); err != nil {
154+
if hasLoadBalancerPortsError(svc) {
168155
return nil, err
169156
}
157+
klog.Warningf("Ignoring service %s/%s using different ports protocols", svc.Namespace, svc.Name)
158+
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancers with multiple protocols are not supported.")
159+
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
160+
metav1apply.Condition().
161+
WithType(v1.LoadBalancerPortsError).
162+
WithStatus(metav1.ConditionTrue).
163+
WithReason(v1.LoadBalancerPortsErrorReason).
164+
WithMessage("LoadBalancer with multiple protocols are not supported"))
165+
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
166+
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
167+
return nil, errApply
168+
}
169+
return nil, err
170170
}
171171

172172
klog.V(4).Infof("EnsureLoadBalancer(%v, %v, %v, %v, %v): ensure %v loadbalancer", clusterName, svc.Namespace, svc.Name, loadBalancerName, g.region, desiredScheme)
@@ -230,24 +230,24 @@ func (g *Cloud) UpdateLoadBalancer(ctx context.Context, clusterName string, svc
230230
return err
231231
}
232232

233-
// Services with multiples protocols are not supported by this controller, warn the users and sets
233+
// Services with multiples protocols are not supported by this controller (without AlphaFeatureMultiProtocolLB), warn the users and sets
234234
// the corresponding Service Status Condition, but keep processing the Update to not break upgrades.
235235
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1435-mixed-protocol-lb
236-
if !g.AlphaFeatureGate.Enabled(AlphaFeatureMultiProtocolLB) {
237-
if err := checkMixedProtocol(svc.Spec.Ports); err != nil && !hasLoadBalancerPortsError(svc) {
238-
klog.Warningf("Ignoring update for service %s/%s using different ports protocols", svc.Namespace, svc.Name)
239-
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancer with multiple protocols are not supported.")
240-
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
241-
metav1apply.Condition().
242-
WithType(v1.LoadBalancerPortsError).
243-
WithStatus(metav1.ConditionTrue).
244-
WithReason(v1.LoadBalancerPortsErrorReason).
245-
WithMessage("LoadBalancer with multiple protocols are not supported"))
246-
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
247-
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
248-
// the error is retried by the controller loop
249-
return errApply
250-
}
236+
if g.AlphaFeatureGate.Enabled(AlphaFeatureMultiProtocolLB) {
237+
klog.Infof("AlphaFeatureMultiProtocolLB feature gate is enabled")
238+
} else if err := checkMixedProtocol(svc.Spec.Ports); err != nil && !hasLoadBalancerPortsError(svc) {
239+
klog.Warningf("Ignoring update for service %s/%s using different ports protocols", svc.Namespace, svc.Name)
240+
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancer with multiple protocols are not supported.")
241+
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
242+
metav1apply.Condition().
243+
WithType(v1.LoadBalancerPortsError).
244+
WithStatus(metav1.ConditionTrue).
245+
WithReason(v1.LoadBalancerPortsErrorReason).
246+
WithMessage("LoadBalancer with multiple protocols are not supported"))
247+
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
248+
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
249+
// the error is retried by the controller loop
250+
return errApply
251251
}
252252
}
253253

providers/gce/gce_loadbalancer_external.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ const (
5252
// IP address, a firewall rule, a target pool, and a forwarding rule. This
5353
// function has to manage all of them.
5454
//
55-
// Due to an interesting series of design decisions, this handles both creating
56-
// new load balancers and updating existing load balancers, recognizing when
57-
// each is needed.
55+
// This function handles both creating new load balancers and updating existing load balancers,
56+
// recognizing when each is needed.
57+
// This approach is resilient, for example if we are interrupted part-way during creation.
5858
func (g *Cloud) ensureExternalLoadBalancer(clusterName string, clusterID string, apiService *v1.Service, existingFwdRule *compute.ForwardingRule, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) {
5959
// Process services with LoadBalancerClass "networking.gke.io/l4-regional-external-legacy" used for this controller.
6060
// LoadBalancerClass can't be updated so we know this controller should process the NetLB.
@@ -456,7 +456,6 @@ func (g *Cloud) ensureIPAddress(loadBalancerName, lbRefStr, requestedIP, fwdRule
456456
return ipAddressToUse, isSafeToReleaseIP, nil
457457
}
458458

459-
460459
// updateExternalLoadBalancer is the external implementation of LoadBalancer.UpdateLoadBalancer.
461460
func (g *Cloud) updateExternalLoadBalancer(clusterName string, service *v1.Service, nodes []*v1.Node) error {
462461
// Process services with LoadBalancerClass "networking.gke.io/l4-regional-external-legacy" used for this controller.
@@ -534,8 +533,13 @@ func (g *Cloud) ensureExternalLoadBalancerDeleted(clusterName, clusterID string,
534533
},
535534
func() error {
536535
klog.Infof("ensureExternalLoadBalancerDeleted(%s): Deleting forwarding rules.", lbRefStr)
537-
// The forwarding rule must be deleted before either the target pool can,
538-
// unfortunately, so we have to do these two serially.
536+
// The forwarding rule must be deleted before the target pool can be deleted,
537+
// unfortunately, so we have to delete forwarding rules then target pools serially.
538+
if err := ignoreNotFound(g.DeleteRegionForwardingRule(loadBalancerName, g.region)); err != nil {
539+
return err
540+
}
541+
542+
// TODO: Always or just with alpha feature flag?
539543
frs, err := g.ListRegionForwardingRules(g.region)
540544
if err != nil {
541545
return err
@@ -1125,8 +1129,7 @@ func equalPorts(existingPorts, newPorts []string, existingPortRange, newPortRang
11251129

11261130
func groupPortsByProtocol(ports []v1.ServicePort) map[v1.Protocol][]v1.ServicePort {
11271131
grouped := make(map[v1.Protocol][]v1.ServicePort)
1128-
for _, p := range ports {
1129-
port := p
1132+
for _, port := range ports {
11301133
grouped[port.Protocol] = append(grouped[port.Protocol], port)
11311134
}
11321135
return grouped
@@ -1195,7 +1198,6 @@ func (g *Cloud) firewallNeedsUpdate(name, serviceName, ipAddress string, ports [
11951198
return true, false, nil
11961199
}
11971200

1198-
11991201
func (g *Cloud) ensureHTTPHealthCheckFirewall(svc *v1.Service, serviceName, ipAddress, region, clusterID string, hosts []*gceInstance, hcName string, hcPort int32, isNodesHealthCheck bool) error {
12001202
// Prepare the firewall params for creating / checking.
12011203
desc := fmt.Sprintf(`{"kubernetes.io/cluster-id":"%s"}`, clusterID)

0 commit comments

Comments
 (0)