Skip to content

Commit 72ed8d1

Browse files
committed
controller support for mixed protocol LB services
1 parent 9b33c10 commit 72ed8d1

File tree

3 files changed

+343
-152
lines changed

3 files changed

+343
-152
lines changed

providers/gce/gce_alpha.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ const (
2727
// AlphaFeatureSkipIGsManagement enabled L4 Regional Backend Services and
2828
// disables instance group management in service controller
2929
AlphaFeatureSkipIGsManagement = "SkipIGsManagement"
30+
31+
// AlphaFeatureMultiProtocolLB allows services to use multiple protocols in the same LoadBalancer.
32+
AlphaFeatureMultiProtocolLB = "MultiProtocolLB"
3033
)
3134

3235
// AlphaFeatureGate contains a mapping of alpha features to whether they are enabled

providers/gce/gce_loadbalancer.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -148,23 +148,25 @@ func (g *Cloud) EnsureLoadBalancer(ctx context.Context, clusterName string, svc
148148
// Services with multiples protocols are not supported by this controller, warn the users and sets
149149
// the corresponding Service Status Condition.
150150
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1435-mixed-protocol-lb
151-
if err := checkMixedProtocol(svc.Spec.Ports); err != nil {
152-
if hasLoadBalancerPortsError(svc) {
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+
}
153168
return nil, err
154169
}
155-
klog.Warningf("Ignoring service %s/%s using different ports protocols", svc.Namespace, svc.Name)
156-
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancers with multiple protocols are not supported.")
157-
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
158-
metav1apply.Condition().
159-
WithType(v1.LoadBalancerPortsError).
160-
WithStatus(metav1.ConditionTrue).
161-
WithReason(v1.LoadBalancerPortsErrorReason).
162-
WithMessage("LoadBalancer with multiple protocols are not supported"))
163-
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
164-
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
165-
return nil, errApply
166-
}
167-
return nil, err
168170
}
169171

170172
klog.V(4).Infof("EnsureLoadBalancer(%v, %v, %v, %v, %v): ensure %v loadbalancer", clusterName, svc.Namespace, svc.Name, loadBalancerName, g.region, desiredScheme)
@@ -231,19 +233,21 @@ func (g *Cloud) UpdateLoadBalancer(ctx context.Context, clusterName string, svc
231233
// Services with multiples protocols are not supported by this controller, warn the users and sets
232234
// the corresponding Service Status Condition, but keep processing the Update to not break upgrades.
233235
// https://github.com/kubernetes/enhancements/tree/master/keps/sig-network/1435-mixed-protocol-lb
234-
if err := checkMixedProtocol(svc.Spec.Ports); err != nil && !hasLoadBalancerPortsError(svc) {
235-
klog.Warningf("Ignoring update for service %s/%s using different ports protocols", svc.Namespace, svc.Name)
236-
g.eventRecorder.Event(svc, v1.EventTypeWarning, v1.LoadBalancerPortsErrorReason, "LoadBalancer with multiple protocols are not supported.")
237-
svcApplyStatus := corev1apply.ServiceStatus().WithConditions(
238-
metav1apply.Condition().
239-
WithType(v1.LoadBalancerPortsError).
240-
WithStatus(metav1.ConditionTrue).
241-
WithReason(v1.LoadBalancerPortsErrorReason).
242-
WithMessage("LoadBalancer with multiple protocols are not supported"))
243-
svcApply := corev1apply.Service(svc.Name, svc.Namespace).WithStatus(svcApplyStatus)
244-
if _, errApply := g.client.CoreV1().Services(svc.Namespace).ApplyStatus(ctx, svcApply, metav1.ApplyOptions{FieldManager: "gce-cloud-controller", Force: true}); errApply != nil {
245-
// the error is retried by the controller loop
246-
return errApply
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+
}
247251
}
248252
}
249253

0 commit comments

Comments
 (0)