From 501081e64fe56d4542d9315704327343efd51277 Mon Sep 17 00:00:00 2001 From: Pavithra Ramesh Date: Fri, 2 Aug 2019 10:34:02 -0700 Subject: [PATCH] Moved nil check inside AlphaFeatureGate.Enabled --- .../src/k8s.io/legacy-cloud-providers/gce/gce_alpha.go | 3 +++ .../gce/gce_loadbalancer_internal.go | 8 ++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_alpha.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_alpha.go index d3e70b9153e..efb57c0abd5 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_alpha.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_alpha.go @@ -38,6 +38,9 @@ type AlphaFeatureGate struct { // Enabled returns true if the provided alpha feature is enabled func (af *AlphaFeatureGate) Enabled(key string) bool { + if af == nil || af.features == nil { + return false + } return af.features[key] } diff --git a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go index 27b02ce2a2a..9b0c109da00 100644 --- a/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go +++ b/staging/src/k8s.io/legacy-cloud-providers/gce/gce_loadbalancer_internal.go @@ -36,12 +36,8 @@ const ( allInstances = "ALL" ) -func (g *Cloud) usesSubsets() bool { - return g.AlphaFeatureGate != nil && g.AlphaFeatureGate.Enabled(AlphaFeatureILBSubsets) -} - func (g *Cloud) ensureInternalLoadBalancer(clusterName, clusterID string, svc *v1.Service, existingFwdRule *compute.ForwardingRule, nodes []*v1.Node) (*v1.LoadBalancerStatus, error) { - if g.usesSubsets() { + if g.AlphaFeatureGate.Enabled(AlphaFeatureILBSubsets) { return nil, cloudprovider.ImplementedElsewhere } @@ -210,7 +206,7 @@ func (g *Cloud) clearPreviousInternalResources(svc *v1.Service, loadBalancerName // updateInternalLoadBalancer is called when the list of nodes has changed. Therefore, only the instance groups // and possibly the backend service need to be updated. func (g *Cloud) updateInternalLoadBalancer(clusterName, clusterID string, svc *v1.Service, nodes []*v1.Node) error { - if g.usesSubsets() { + if g.AlphaFeatureGate.Enabled(AlphaFeatureILBSubsets) { return cloudprovider.ImplementedElsewhere } g.sharedResourceLock.Lock()