Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubeadm: fix misleading warning for authz modes #90064

Merged
merged 1 commit into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 19 additions & 4 deletions cmd/kubeadm/app/phases/controlplane/manifests.go
Expand Up @@ -222,16 +222,31 @@ func getAuthzModes(authzModeExtraArgs string) string {

// only return the user provided mode if at least one was valid
if len(mode) > 0 {
klog.Warningf("the default kube-apiserver authorization-mode is %q; using %q",
strings.Join(defaultMode, ","),
strings.Join(mode, ","),
)
if !compareAuthzModes(defaultMode, mode) {
klog.Warningf("the default kube-apiserver authorization-mode is %q; using %q",
strings.Join(defaultMode, ","),
strings.Join(mode, ","),
)
}
return strings.Join(mode, ",")
}
}
return strings.Join(defaultMode, ",")
}

// compareAuthzModes compares two given authz modes and returns false if they do not match
func compareAuthzModes(a, b []string) bool {
if len(a) != len(b) {
return false
}
for i, m := range a {
if m != b[i] {
return false
}
}
return true
}

func isValidAuthzMode(authzMode string) bool {
allModes := []string{
kubeadmconstants.ModeNode,
Expand Down
40 changes: 40 additions & 0 deletions cmd/kubeadm/app/phases/controlplane/manifests_test.go
Expand Up @@ -1144,3 +1144,43 @@ func TestIsValidAuthzMode(t *testing.T) {
})
}
}

func TestCompareAuthzModes(t *testing.T) {
var tests = []struct {
name string
modesA []string
modesB []string
equal bool
}{
{
name: "modes match",
modesA: []string{"a", "b", "c"},
modesB: []string{"a", "b", "c"},
equal: true,
},
{
name: "modes order does not match",
modesA: []string{"a", "c", "b"},
modesB: []string{"a", "b", "c"},
},
{
name: "modes do not match; A has less modes",
modesA: []string{"a", "b"},
modesB: []string{"a", "b", "c"},
},
{
name: "modes do not match; B has less modes",
modesA: []string{"a", "b", "c"},
modesB: []string{"a", "b"},
},
}

for _, rt := range tests {
t.Run(rt.name, func(t *testing.T) {
equal := compareAuthzModes(rt.modesA, rt.modesB)
if equal != rt.equal {
t.Errorf("failed compareAuthzModes:\nexpected:\n%v\nsaw:\n%v", rt.equal, equal)
}
})
}
}