Skip to content

Commit f5a5bf6

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

File tree

3 files changed

+123
-207
lines changed

3 files changed

+123
-207
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

0 commit comments

Comments
 (0)