complish feature gate dependency in kubeadm

This commit is contained in:
stewart-yu 2017-11-20 16:48:40 +08:00
parent 3df3c580b7
commit 51fe9299f6
2 changed files with 50 additions and 0 deletions

View File

@ -155,5 +155,22 @@ func NewFeatureGate(f *FeatureList, value string) (map[string]bool, error) {
featureGate[k] = boolValue
}
ResolveFeatureGateDependencies(featureGate)
return featureGate, nil
}
// ResolveFeatureGateDependencies resolve dependencies between feature gates
func ResolveFeatureGateDependencies(featureGate map[string]bool) {
// if StoreCertsInSecrets enabled, SelfHosting should enabled
if Enabled(featureGate, StoreCertsInSecrets) {
featureGate[SelfHosting] = true
}
// if HighAvailability enabled, both StoreCertsInSecrets and SelfHosting should enabled
if Enabled(featureGate, HighAvailability) && !Enabled(featureGate, StoreCertsInSecrets) {
featureGate[SelfHosting] = true
featureGate[StoreCertsInSecrets] = true
}
}

View File

@ -156,3 +156,36 @@ func TestValidateVersion(t *testing.T) {
}
}
}
func TestResolveFeatureGateDependencies(t *testing.T) {
var tests = []struct {
inputFeatures map[string]bool
expectedFeatures map[string]bool
}{
{ // no flags
inputFeatures: map[string]bool{},
expectedFeatures: map[string]bool{},
},
{ // others flags
inputFeatures: map[string]bool{"SupportIPVSProxyMode": true},
expectedFeatures: map[string]bool{"SupportIPVSProxyMode": true},
},
{ // just StoreCertsInSecrets flags
inputFeatures: map[string]bool{"StoreCertsInSecrets": true},
expectedFeatures: map[string]bool{"StoreCertsInSecrets": true, "SelfHosting": true},
},
{ // just HighAvailability flags
inputFeatures: map[string]bool{"HighAvailability": true},
expectedFeatures: map[string]bool{"HighAvailability": true, "StoreCertsInSecrets": true, "SelfHosting": true},
},
}
for _, test := range tests {
ResolveFeatureGateDependencies(test.inputFeatures)
if !reflect.DeepEqual(test.inputFeatures, test.expectedFeatures) {
t.Errorf("ResolveFeatureGateDependencies failed, expected: %v, got: %v", test.inputFeatures, test.expectedFeatures)
}
}
}