Skip to content

Commit 613cd04

Browse files
authored
Merge pull request kubernetes#90064 from neolit123/1.19-fix-authz-warning
kubeadm: fix misleading warning for authz modes
2 parents 775feed + 6cfd772 commit 613cd04

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

cmd/kubeadm/app/phases/controlplane/manifests.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,31 @@ func getAuthzModes(authzModeExtraArgs string) string {
222222

223223
// only return the user provided mode if at least one was valid
224224
if len(mode) > 0 {
225-
klog.Warningf("the default kube-apiserver authorization-mode is %q; using %q",
226-
strings.Join(defaultMode, ","),
227-
strings.Join(mode, ","),
228-
)
225+
if !compareAuthzModes(defaultMode, mode) {
226+
klog.Warningf("the default kube-apiserver authorization-mode is %q; using %q",
227+
strings.Join(defaultMode, ","),
228+
strings.Join(mode, ","),
229+
)
230+
}
229231
return strings.Join(mode, ",")
230232
}
231233
}
232234
return strings.Join(defaultMode, ",")
233235
}
234236

237+
// compareAuthzModes compares two given authz modes and returns false if they do not match
238+
func compareAuthzModes(a, b []string) bool {
239+
if len(a) != len(b) {
240+
return false
241+
}
242+
for i, m := range a {
243+
if m != b[i] {
244+
return false
245+
}
246+
}
247+
return true
248+
}
249+
235250
func isValidAuthzMode(authzMode string) bool {
236251
allModes := []string{
237252
kubeadmconstants.ModeNode,

cmd/kubeadm/app/phases/controlplane/manifests_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,3 +1144,43 @@ func TestIsValidAuthzMode(t *testing.T) {
11441144
})
11451145
}
11461146
}
1147+
1148+
func TestCompareAuthzModes(t *testing.T) {
1149+
var tests = []struct {
1150+
name string
1151+
modesA []string
1152+
modesB []string
1153+
equal bool
1154+
}{
1155+
{
1156+
name: "modes match",
1157+
modesA: []string{"a", "b", "c"},
1158+
modesB: []string{"a", "b", "c"},
1159+
equal: true,
1160+
},
1161+
{
1162+
name: "modes order does not match",
1163+
modesA: []string{"a", "c", "b"},
1164+
modesB: []string{"a", "b", "c"},
1165+
},
1166+
{
1167+
name: "modes do not match; A has less modes",
1168+
modesA: []string{"a", "b"},
1169+
modesB: []string{"a", "b", "c"},
1170+
},
1171+
{
1172+
name: "modes do not match; B has less modes",
1173+
modesA: []string{"a", "b", "c"},
1174+
modesB: []string{"a", "b"},
1175+
},
1176+
}
1177+
1178+
for _, rt := range tests {
1179+
t.Run(rt.name, func(t *testing.T) {
1180+
equal := compareAuthzModes(rt.modesA, rt.modesB)
1181+
if equal != rt.equal {
1182+
t.Errorf("failed compareAuthzModes:\nexpected:\n%v\nsaw:\n%v", rt.equal, equal)
1183+
}
1184+
})
1185+
}
1186+
}

0 commit comments

Comments
 (0)