Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
d8a399f7
Commit
d8a399f7
authored
Aug 31, 2018
by
Tim Allclair
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Hide & warn on GA & deprecated feature gates
parent
eff30a31
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
45 deletions
+51
-45
BUILD
staging/src/k8s.io/apiserver/pkg/util/feature/BUILD
+4
-1
feature_gate.go
...ing/src/k8s.io/apiserver/pkg/util/feature/feature_gate.go
+17
-41
feature_gate_test.go
...rc/k8s.io/apiserver/pkg/util/feature/feature_gate_test.go
+30
-3
No files found.
staging/src/k8s.io/apiserver/pkg/util/feature/BUILD
View file @
d8a399f7
...
@@ -10,7 +10,10 @@ go_test(
...
@@ -10,7 +10,10 @@ go_test(
name = "go_default_test",
name = "go_default_test",
srcs = ["feature_gate_test.go"],
srcs = ["feature_gate_test.go"],
embed = [":go_default_library"],
embed = [":go_default_library"],
deps = ["//vendor/github.com/spf13/pflag:go_default_library"],
deps = [
"//vendor/github.com/spf13/pflag:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
],
)
)
go_library(
go_library(
...
...
staging/src/k8s.io/apiserver/pkg/util/feature/feature_gate.go
View file @
d8a399f7
...
@@ -145,54 +145,24 @@ func NewFeatureGate() *featureGate {
...
@@ -145,54 +145,24 @@ func NewFeatureGate() *featureGate {
// Set parses a string of the form "key1=value1,key2=value2,..." into a
// Set parses a string of the form "key1=value1,key2=value2,..." into a
// map[string]bool of known keys or returns an error.
// map[string]bool of known keys or returns an error.
func
(
f
*
featureGate
)
Set
(
value
string
)
error
{
func
(
f
*
featureGate
)
Set
(
value
string
)
error
{
f
.
lock
.
Lock
()
m
:=
make
(
map
[
string
]
bool
)
defer
f
.
lock
.
Unlock
()
// Copy existing state
known
:=
map
[
Feature
]
FeatureSpec
{}
for
k
,
v
:=
range
f
.
known
.
Load
()
.
(
map
[
Feature
]
FeatureSpec
)
{
known
[
k
]
=
v
}
enabled
:=
map
[
Feature
]
bool
{}
for
k
,
v
:=
range
f
.
enabled
.
Load
()
.
(
map
[
Feature
]
bool
)
{
enabled
[
k
]
=
v
}
for
_
,
s
:=
range
strings
.
Split
(
value
,
","
)
{
for
_
,
s
:=
range
strings
.
Split
(
value
,
","
)
{
if
len
(
s
)
==
0
{
if
len
(
s
)
==
0
{
continue
continue
}
}
arr
:=
strings
.
SplitN
(
s
,
"="
,
2
)
arr
:=
strings
.
SplitN
(
s
,
"="
,
2
)
k
:=
Feature
(
strings
.
TrimSpace
(
arr
[
0
]))
k
:=
strings
.
TrimSpace
(
arr
[
0
])
featureSpec
,
ok
:=
known
[
k
]
if
!
ok
{
return
fmt
.
Errorf
(
"unrecognized key: %s"
,
k
)
}
if
len
(
arr
)
!=
2
{
if
len
(
arr
)
!=
2
{
return
fmt
.
Errorf
(
"missing bool value for %s"
,
k
)
return
fmt
.
Errorf
(
"missing bool value for %s"
,
k
)
}
}
v
:=
strings
.
TrimSpace
(
arr
[
1
])
v
:=
strings
.
TrimSpace
(
arr
[
1
])
boolValue
,
err
:=
strconv
.
ParseBool
(
v
)
boolValue
,
err
:=
strconv
.
ParseBool
(
v
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid value of %s: %s, err: %v"
,
k
,
v
,
err
)
return
fmt
.
Errorf
(
"invalid value of %s=%s, err: %v"
,
k
,
v
,
err
)
}
enabled
[
k
]
=
boolValue
if
boolValue
&&
featureSpec
.
PreRelease
==
Deprecated
{
glog
.
Warningf
(
"enabling deprecated feature gate %s"
,
k
)
}
// Handle "special" features like "all alpha gates"
if
fn
,
found
:=
f
.
special
[
k
];
found
{
fn
(
known
,
enabled
,
boolValue
)
}
}
m
[
k
]
=
boolValue
}
}
return
f
.
SetFromMap
(
m
)
// Persist changes
f
.
known
.
Store
(
known
)
f
.
enabled
.
Store
(
enabled
)
glog
.
V
(
1
)
.
Infof
(
"feature gates: %v"
,
enabled
)
return
nil
}
}
// SetFromMap stores flag gates for known features from a map[string]bool or returns an error
// SetFromMap stores flag gates for known features from a map[string]bool or returns an error
...
@@ -212,15 +182,21 @@ func (f *featureGate) SetFromMap(m map[string]bool) error {
...
@@ -212,15 +182,21 @@ func (f *featureGate) SetFromMap(m map[string]bool) error {
for
k
,
v
:=
range
m
{
for
k
,
v
:=
range
m
{
k
:=
Feature
(
k
)
k
:=
Feature
(
k
)
_
,
ok
:=
known
[
k
]
featureSpec
,
ok
:=
known
[
k
]
if
!
ok
{
if
!
ok
{
return
fmt
.
Errorf
(
"unrecognized
key
: %s"
,
k
)
return
fmt
.
Errorf
(
"unrecognized
feature gate
: %s"
,
k
)
}
}
enabled
[
k
]
=
v
enabled
[
k
]
=
v
// Handle "special" features like "all alpha gates"
// Handle "special" features like "all alpha gates"
if
fn
,
found
:=
f
.
special
[
k
];
found
{
if
fn
,
found
:=
f
.
special
[
k
];
found
{
fn
(
known
,
enabled
,
v
)
fn
(
known
,
enabled
,
v
)
}
}
if
featureSpec
.
PreRelease
==
Deprecated
{
glog
.
Warningf
(
"Setting deprecated feature gate %s=%t. It will be removed in a future release."
,
k
,
v
)
}
else
if
featureSpec
.
PreRelease
==
GA
{
glog
.
Warningf
(
"Setting GA feature gate %s=%t. It will be removed in a future release."
,
k
,
v
)
}
}
}
// Persist changes
// Persist changes
...
@@ -302,14 +278,14 @@ func (f *featureGate) AddFlag(fs *pflag.FlagSet) {
...
@@ -302,14 +278,14 @@ func (f *featureGate) AddFlag(fs *pflag.FlagSet) {
}
}
// KnownFeatures returns a slice of strings describing the FeatureGate's known features.
// KnownFeatures returns a slice of strings describing the FeatureGate's known features.
// Deprecated and GA features are hidden from the list.
func
(
f
*
featureGate
)
KnownFeatures
()
[]
string
{
func
(
f
*
featureGate
)
KnownFeatures
()
[]
string
{
var
known
[]
string
var
known
[]
string
for
k
,
v
:=
range
f
.
known
.
Load
()
.
(
map
[
Feature
]
FeatureSpec
)
{
for
k
,
v
:=
range
f
.
known
.
Load
()
.
(
map
[
Feature
]
FeatureSpec
)
{
pre
:=
""
if
v
.
PreRelease
==
GA
||
v
.
PreRelease
==
Deprecated
{
if
v
.
PreRelease
!=
GA
{
continue
pre
=
fmt
.
Sprintf
(
"%s - "
,
v
.
PreRelease
)
}
}
known
=
append
(
known
,
fmt
.
Sprintf
(
"%s=true|false (%s
default=%t)"
,
k
,
pr
e
,
v
.
Default
))
known
=
append
(
known
,
fmt
.
Sprintf
(
"%s=true|false (%s
- default=%t)"
,
k
,
v
.
PreReleas
e
,
v
.
Default
))
}
}
sort
.
Strings
(
known
)
sort
.
Strings
(
known
)
return
known
return
known
...
...
staging/src/k8s.io/apiserver/pkg/util/feature/feature_gate_test.go
View file @
d8a399f7
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"testing"
"testing"
"github.com/spf13/pflag"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
)
)
func
TestFeatureGateFlag
(
t
*
testing
.
T
)
{
func
TestFeatureGateFlag
(
t
*
testing
.
T
)
{
...
@@ -43,13 +44,13 @@ func TestFeatureGateFlag(t *testing.T) {
...
@@ -43,13 +44,13 @@ func TestFeatureGateFlag(t *testing.T) {
},
},
},
},
{
{
arg
:
"fooBarBaz=
maybeidk
"
,
arg
:
"fooBarBaz=
true
"
,
expect
:
map
[
Feature
]
bool
{
expect
:
map
[
Feature
]
bool
{
allAlphaGate
:
false
,
allAlphaGate
:
false
,
testAlphaGate
:
false
,
testAlphaGate
:
false
,
testBetaGate
:
false
,
testBetaGate
:
false
,
},
},
parseError
:
"unrecognized
key
: fooBarBaz"
,
parseError
:
"unrecognized
feature gate
: fooBarBaz"
,
},
},
{
{
arg
:
"AllAlpha=false"
,
arg
:
"AllAlpha=false"
,
...
@@ -190,6 +191,32 @@ func TestFeatureGateFlagDefaults(t *testing.T) {
...
@@ -190,6 +191,32 @@ func TestFeatureGateFlagDefaults(t *testing.T) {
}
}
}
}
func
TestFeatureGateKnownFeatures
(
t
*
testing
.
T
)
{
// gates for testing
const
(
testAlphaGate
Feature
=
"TestAlpha"
testBetaGate
Feature
=
"TestBeta"
testGAGate
Feature
=
"TestGA"
testDeprecatedGate
Feature
=
"TestDeprecated"
)
// Don't parse the flag, assert defaults are used.
var
f
FeatureGate
=
NewFeatureGate
()
f
.
Add
(
map
[
Feature
]
FeatureSpec
{
testAlphaGate
:
{
Default
:
false
,
PreRelease
:
Alpha
},
testBetaGate
:
{
Default
:
true
,
PreRelease
:
Beta
},
testGAGate
:
{
Default
:
true
,
PreRelease
:
GA
},
testDeprecatedGate
:
{
Default
:
false
,
PreRelease
:
Deprecated
},
})
known
:=
strings
.
Join
(
f
.
KnownFeatures
(),
" "
)
assert
.
Contains
(
t
,
known
,
testAlphaGate
)
assert
.
Contains
(
t
,
known
,
testBetaGate
)
assert
.
NotContains
(
t
,
known
,
testGAGate
)
assert
.
NotContains
(
t
,
known
,
testDeprecatedGate
)
}
func
TestFeatureGateSetFromMap
(
t
*
testing
.
T
)
{
func
TestFeatureGateSetFromMap
(
t
*
testing
.
T
)
{
// gates for testing
// gates for testing
const
testAlphaGate
Feature
=
"TestAlpha"
const
testAlphaGate
Feature
=
"TestAlpha"
...
@@ -241,7 +268,7 @@ func TestFeatureGateSetFromMap(t *testing.T) {
...
@@ -241,7 +268,7 @@ func TestFeatureGateSetFromMap(t *testing.T) {
testAlphaGate
:
false
,
testAlphaGate
:
false
,
testBetaGate
:
false
,
testBetaGate
:
false
,
},
},
setmapError
:
"unrecognized
key
:"
,
setmapError
:
"unrecognized
feature gate
:"
,
},
},
}
}
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment