-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add MinimumKubeletVersion authorization-mode if feature is on
Signed-off-by: Peter Hunt <[email protected]>
- Loading branch information
1 parent
49beb0d
commit 6d45957
Showing
3 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
pkg/operator/configobservation/node/minimum_kubelet_version.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package node | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
var ( | ||
ModeMinimumKubeletVersion = "MinimumKubeletVersion" | ||
authorizationModeFlag = "authorization-mode" | ||
) | ||
|
||
var configPath = []string{"apiServerArguments", authorizationModeFlag} | ||
|
||
func SetAPIServerArgumentsToEnforceMinimumKubeletVersion(config map[string]interface{}) error { | ||
apiServerArguments, found, err := unstructured.NestedStringSlice(config, configPath...) | ||
if err != nil { | ||
return err | ||
} | ||
if found { | ||
for _, arg := range apiServerArguments { | ||
if arg == ModeMinimumKubeletVersion { | ||
// Already specified! | ||
return nil | ||
} | ||
} | ||
apiServerArguments = append(apiServerArguments, ModeMinimumKubeletVersion) | ||
unstructured.RemoveNestedField(config, configPath...) | ||
} else { | ||
apiServerArguments = []string{ModeMinimumKubeletVersion} | ||
} | ||
|
||
return unstructured.SetNestedStringSlice(config, apiServerArguments, configPath...) | ||
} |
78 changes: 78 additions & 0 deletions
78
pkg/operator/configobservation/node/minimum_kubelet_version_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package node | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestSetAPIServerArgumentsToEnforceMinimumKubeletVersion(t *testing.T) { | ||
for _, tc := range []struct { | ||
name string | ||
existingConfig map[string]interface{} | ||
// featureGateAccessor featuregates.FeatureGateAccess | ||
expectedErr string | ||
expectedConfig map[string]interface{} | ||
}{ | ||
{ | ||
name: "should not fail if apiServerArguments not present", | ||
existingConfig: map[string]interface{}{ | ||
"fakeconfig": "fake", | ||
}, | ||
expectedConfig: map[string]interface{}{ | ||
"fakeconfig": "fake", | ||
"apiServerArguments": map[string]any{"authorization-mode": []any{"MinimumKubeletVersion"}}, | ||
}, | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "should not fail if authorization-mode not present", | ||
existingConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"fake": []any{"fake"}}, | ||
}, | ||
expectedConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"fake": []any{"fake"}, "authorization-mode": []any{"MinimumKubeletVersion"}}, | ||
}, | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "should not fail if MinimumKubeletVersion not present", | ||
existingConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"authorization-mode": []any{"fake"}}, | ||
}, | ||
expectedConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"authorization-mode": []any{"fake", "MinimumKubeletVersion"}}, | ||
}, | ||
expectedErr: "", | ||
}, | ||
{ | ||
name: "should not fail if MinimumKubeletVersion already present", | ||
existingConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"authorization-mode": []any{"MinimumKubeletVersion"}}, | ||
}, | ||
expectedConfig: map[string]interface{}{ | ||
"apiServerArguments": map[string]any{"authorization-mode": []any{"MinimumKubeletVersion"}}, | ||
}, | ||
expectedErr: "", | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := SetAPIServerArgumentsToEnforceMinimumKubeletVersion(tc.existingConfig) | ||
switch { | ||
case err == nil && len(tc.expectedErr) == 0: | ||
case err == nil && len(tc.expectedErr) > 0: | ||
t.Fatalf("missing err: %v", tc.expectedErr) | ||
|
||
case len(err.Error()) > 0 && len(tc.expectedErr) == 0: | ||
t.Fatal(err) | ||
case len(err.Error()) > 0 && len(tc.expectedErr) > 0 && !strings.Contains(err.Error(), tc.expectedErr): | ||
t.Fatalf("missing err: %v in \n%v", tc.expectedErr, err) | ||
} | ||
|
||
if diff := cmp.Diff(tc.expectedConfig, tc.existingConfig); diff != "" { | ||
t.Errorf("unexpected config:\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |