Merge pull request #61441 from agau4779/remove-alphagate-validation

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

[GCE] Remove validation of Alpha Feature Gates

**What this PR does / why we need it**:
As per discussion with @bowei, @freehan, and @nicksardo , remove validation on Alpha Feature Gates so we can be more flexible with adding or removing new features.

**Release note**:
```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-03-26 09:31:29 -07:00 committed by GitHub
commit df7ee3a543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 110 deletions

View File

@ -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

View File

@ -18,8 +18,6 @@ package gce
import (
"fmt"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
)
const (
@ -32,12 +30,6 @@ const (
AlphaFeatureNetworkEndpointGroup = "NetworkEndpointGroup"
)
// All known alpha features
var knownAlphaFeatures = map[string]bool{
AlphaFeatureNetworkTiers: true,
AlphaFeatureNetworkEndpointGroup: true,
}
type AlphaFeatureGate struct {
features map[string]bool
}
@ -46,17 +38,12 @@ 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))
} else {
featureMap[name] = true
}
featureMap[name] = true
}
return &AlphaFeatureGate{featureMap}, utilerrors.NewAggregate(errList)
return &AlphaFeatureGate{featureMap}
}
func (gce *GCECloud) alphaFeatureEnabled(feature string) error {

View File

@ -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,

View File

@ -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
}

View File

@ -531,51 +531,39 @@ func getTestOperation() *computev1.Operation {
}
func TestNewAlphaFeatureGate(t *testing.T) {
knownAlphaFeatures["foo"] = true
knownAlphaFeatures["bar"] = true
testCases := []struct {
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"},
expectDisabled: []string{},
},
// enable foo
{
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) {
@ -588,8 +576,6 @@ func TestNewAlphaFeatureGate(t *testing.T) {
}
}
}
delete(knownAlphaFeatures, "foo")
delete(knownAlphaFeatures, "bar")
}
func TestGetRegionInURL(t *testing.T) {

View File

@ -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,

View File

@ -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,