mirror of https://github.com/k3s-io/k3s
Don't panic if the feature-gate flag was not used
parent
f77576bc2b
commit
34bd1e391e
|
@ -156,11 +156,10 @@ func (f *featureGate) Type() string {
|
|||
|
||||
func (f *featureGate) lookup(key string) bool {
|
||||
defaultValue := f.known[key].enabled
|
||||
if f.enabled == nil {
|
||||
panic(fmt.Sprintf("--%s has not been parsed", flagName))
|
||||
}
|
||||
if v, ok := f.enabled[key]; ok {
|
||||
return v
|
||||
if f.enabled != nil {
|
||||
if v, ok := f.enabled[key]; ok {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
|
||||
|
|
|
@ -139,3 +139,21 @@ func TestFeatureGateFlag(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFeatureGateFlagDefaults(t *testing.T) {
|
||||
// gates for testing
|
||||
const testAlphaGate = "TestAlpha"
|
||||
const testBetaGate = "TestBeta"
|
||||
|
||||
// Don't parse the flag, assert defaults are used.
|
||||
f := DefaultFeatureGate
|
||||
f.known[testAlphaGate] = featureSpec{false, alpha}
|
||||
f.known[testBetaGate] = featureSpec{true, beta}
|
||||
|
||||
if f.lookup(testAlphaGate) != false {
|
||||
t.Errorf("Expected false")
|
||||
}
|
||||
if f.lookup(testBetaGate) != true {
|
||||
t.Errorf("Expected true")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue