diff --git a/pkg/cloudprovider/providers/gce/gce.go b/pkg/cloudprovider/providers/gce/gce.go index 4698c52b0e5..80ba27f8345 100644 --- a/pkg/cloudprovider/providers/gce/gce.go +++ b/pkg/cloudprovider/providers/gce/gce.go @@ -269,9 +269,7 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err // By default, fetch token from GCE metadata server cloudConfig.TokenSource = google.ComputeTokenSource("") cloudConfig.UseMetadataServer = true - - featureMap := make(map[string]bool) - cloudConfig.AlphaFeatureGate = &AlphaFeatureGate{featureMap} + cloudConfig.AlphaFeatureGate = NewAlphaFeatureGate([]string{}) if configFile != nil { if configFile.Global.ApiEndpoint != "" { cloudConfig.ApiEndpoint = configFile.Global.ApiEndpoint @@ -289,19 +287,7 @@ func generateCloudConfig(configFile *ConfigFile) (cloudConfig *CloudConfig, err cloudConfig.NodeTags = configFile.Global.NodeTags cloudConfig.NodeInstancePrefix = configFile.Global.NodeInstancePrefix - - alphaFeatureGate, err := NewAlphaFeatureGate(configFile.Global.AlphaFeatures) - if err != nil { - glog.Errorf("Encountered error for creating alpha feature gate: %v", err) - } - cloudConfig.AlphaFeatureGate = alphaFeatureGate - } else { - // initialize AlphaFeatureGate when no AlphaFeatures are configured. - alphaFeatureGate, err := NewAlphaFeatureGate([]string{}) - if err != nil { - glog.Errorf("Encountered error for initializing alpha feature gate: %v", err) - } - cloudConfig.AlphaFeatureGate = alphaFeatureGate + cloudConfig.AlphaFeatureGate = NewAlphaFeatureGate(configFile.Global.AlphaFeatures) } // retrieve projectID and zone diff --git a/pkg/cloudprovider/providers/gce/gce_alpha.go b/pkg/cloudprovider/providers/gce/gce_alpha.go index 6e227252773..8cff6583b47 100644 --- a/pkg/cloudprovider/providers/gce/gce_alpha.go +++ b/pkg/cloudprovider/providers/gce/gce_alpha.go @@ -18,8 +18,6 @@ package gce import ( "fmt" - - utilerrors "k8s.io/apimachinery/pkg/util/errors" ) const ( @@ -33,10 +31,7 @@ const ( ) // All known alpha features -var knownAlphaFeatures = map[string]bool{ - AlphaFeatureNetworkTiers: true, - AlphaFeatureNetworkEndpointGroup: true, -} +var knownAlphaFeatures = map[string]bool{} type AlphaFeatureGate struct { features map[string]bool @@ -46,17 +41,16 @@ func (af *AlphaFeatureGate) Enabled(key string) bool { return af.features[key] } -func NewAlphaFeatureGate(features []string) (*AlphaFeatureGate, error) { - errList := []error{} +func NewAlphaFeatureGate(features []string) *AlphaFeatureGate { featureMap := make(map[string]bool) for _, name := range features { if _, ok := knownAlphaFeatures[name]; !ok { - errList = append(errList, fmt.Errorf("alpha feature %q is not supported.", name)) + featureMap[name] = false } else { featureMap[name] = true } } - return &AlphaFeatureGate{featureMap}, utilerrors.NewAggregate(errList) + return &AlphaFeatureGate{featureMap} } func (gce *GCECloud) alphaFeatureEnabled(feature string) error { diff --git a/pkg/cloudprovider/providers/gce/gce_disks_test.go b/pkg/cloudprovider/providers/gce/gce_disks_test.go index 1a0b1240cf9..bb8242fcf16 100644 --- a/pkg/cloudprovider/providers/gce/gce_disks_test.go +++ b/pkg/cloudprovider/providers/gce/gce_disks_test.go @@ -39,10 +39,7 @@ func TestCreateDisk_Basic(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: []string{"zone1"}, @@ -157,10 +154,7 @@ func TestCreateDisk_DiskAlreadyExists(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -266,10 +260,7 @@ func TestCreateDisk_MultiZone(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1", "zone2", "zone3"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -298,10 +289,7 @@ func TestDeleteDisk_Basic(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -338,10 +326,7 @@ func TestDeleteDisk_NotFound(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -366,10 +351,7 @@ func TestDeleteDisk_ResourceBeingUsed(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -400,10 +382,7 @@ func TestDeleteDisk_SameDiskMultiZone(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1", "zone2", "zone3"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -437,10 +416,7 @@ func TestDeleteDisk_DiffDiskMultiZone(t *testing.T) { gceRegion := "fake-region" zonesWithNodes := []string{"zone1"} fakeManager := newFakeManager(gceProjectId, gceRegion) - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -478,10 +454,7 @@ func TestGetAutoLabelsForPD_Basic(t *testing.T) { diskName := "disk" diskType := DiskTypeSSD const sizeGb int64 = 128 - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -518,10 +491,7 @@ func TestGetAutoLabelsForPD_NoZone(t *testing.T) { diskName := "disk" diskType := DiskTypeStandard const sizeGb int64 = 128 - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -576,10 +546,7 @@ func TestGetAutoLabelsForPD_DiskNotFoundAndNoZone(t *testing.T) { zonesWithNodes := []string{} fakeManager := newFakeManager(gceProjectId, gceRegion) diskName := "disk" - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -608,10 +575,7 @@ func TestGetAutoLabelsForPD_DupDisk(t *testing.T) { zone := "us-west1-b" const sizeGb int64 = 128 - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, @@ -649,10 +613,7 @@ func TestGetAutoLabelsForPD_DupDiskNoZone(t *testing.T) { diskType := DiskTypeStandard const sizeGb int64 = 128 - alphaFeatureGate, featureGateErr := NewAlphaFeatureGate([]string{}) - if featureGateErr != nil { - t.Error(featureGateErr) - } + alphaFeatureGate := NewAlphaFeatureGate([]string{}) gce := GCECloud{ manager: fakeManager, managedZones: zonesWithNodes, diff --git a/pkg/cloudprovider/providers/gce/gce_loadbalancer_utils_test.go b/pkg/cloudprovider/providers/gce/gce_loadbalancer_utils_test.go index 1dcdb19beea..754d023b052 100644 --- a/pkg/cloudprovider/providers/gce/gce_loadbalancer_utils_test.go +++ b/pkg/cloudprovider/providers/gce/gce_loadbalancer_utils_test.go @@ -79,7 +79,7 @@ func fakeGCECloud(vals TestClusterValues) (*GCECloud, error) { fakeManager := newFakeManager(vals.ProjectID, vals.Region) zonesWithNodes := createNodeZones([]string{vals.ZoneName}) - alphaFeatureGate, err := NewAlphaFeatureGate([]string{}) + alphaFeatureGate := NewAlphaFeatureGate([]string{}) if err != nil { return nil, err } diff --git a/pkg/cloudprovider/providers/gce/gce_test.go b/pkg/cloudprovider/providers/gce/gce_test.go index a36027627c0..c7267d2908d 100644 --- a/pkg/cloudprovider/providers/gce/gce_test.go +++ b/pkg/cloudprovider/providers/gce/gce_test.go @@ -538,26 +538,22 @@ func TestNewAlphaFeatureGate(t *testing.T) { alphaFeatures []string expectEnabled []string expectDisabled []string - expectError bool }{ // enable foo bar { alphaFeatures: []string{"foo", "bar"}, expectEnabled: []string{"foo", "bar"}, expectDisabled: []string{"aaa"}, - expectError: false, }, // no alpha feature { alphaFeatures: []string{}, expectEnabled: []string{}, expectDisabled: []string{"foo", "bar"}, - expectError: false, }, // unsupported alpha feature { alphaFeatures: []string{"aaa", "foo"}, - expectError: true, expectEnabled: []string{"foo"}, expectDisabled: []string{"aaa"}, }, @@ -566,16 +562,11 @@ func TestNewAlphaFeatureGate(t *testing.T) { alphaFeatures: []string{"foo"}, expectEnabled: []string{"foo"}, expectDisabled: []string{"bar"}, - expectError: false, }, } for _, tc := range testCases { - featureGate, err := NewAlphaFeatureGate(tc.alphaFeatures) - - if (tc.expectError && err == nil) || (!tc.expectError && err != nil) { - t.Errorf("Expect error to be %v, but got error %v", tc.expectError, err) - } + featureGate := NewAlphaFeatureGate(tc.alphaFeatures) for _, key := range tc.expectEnabled { if !featureGate.Enabled(key) { diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index d4ec18e3c40..f25d5978ef5 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -72,12 +72,9 @@ func setupProviderConfig() error { managedZones = []string{zone} } - gceAlphaFeatureGate, err := gcecloud.NewAlphaFeatureGate([]string{ + gceAlphaFeatureGate := gcecloud.NewAlphaFeatureGate([]string{ gcecloud.AlphaFeatureNetworkEndpointGroup, }) - if err != nil { - glog.Errorf("Encountered error for creating alpha feature gate: %v", err) - } gceCloud, err := gcecloud.CreateGCECloud(&gcecloud.CloudConfig{ ApiEndpoint: framework.TestContext.CloudConfig.ApiEndpoint, diff --git a/test/e2e/network/scale/localrun/ingress_scale.go b/test/e2e/network/scale/localrun/ingress_scale.go index 87c898e3ae6..62c44e31614 100644 --- a/test/e2e/network/scale/localrun/ingress_scale.go +++ b/test/e2e/network/scale/localrun/ingress_scale.go @@ -106,11 +106,7 @@ func main() { } // Initializing a GCE client. - gceAlphaFeatureGate, err := gcecloud.NewAlphaFeatureGate([]string{}) - if err != nil { - glog.Errorf("Encountered error for creating alpha feature gate: %v", err) - os.Exit(1) - } + gceAlphaFeatureGate := gcecloud.NewAlphaFeatureGate([]string{}) gceCloud, err := gcecloud.CreateGCECloud(&gcecloud.CloudConfig{ ProjectID: cloudConfig.ProjectID, Region: cloudConfig.Region,