mirror of https://github.com/k3s-io/k3s
Exporting the AddFeatureGate function and adding a unit test for it. (#3661)
parent
fc19b805d5
commit
7704fb6ee5
|
@ -57,13 +57,6 @@ func startKubelet(cfg *daemonconfig.Agent) error {
|
|||
return executor.Kubelet(args)
|
||||
}
|
||||
|
||||
func addFeatureGate(current, new string) string {
|
||||
if current == "" {
|
||||
return new
|
||||
}
|
||||
return current + "," + new
|
||||
}
|
||||
|
||||
// ImageCredProvAvailable checks to see if the kubelet image credential provider bin dir and config
|
||||
// files exist and are of the correct types. This is exported so that it may be used by downstream projects.
|
||||
func ImageCredProvAvailable(cfg *daemonconfig.Agent) bool {
|
||||
|
|
|
@ -134,7 +134,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
|
|||
logrus.Warn("Disabling pod PIDs limit feature due to missing cgroup pids support")
|
||||
argsMap["cgroups-per-qos"] = "false"
|
||||
argsMap["enforce-node-allocatable"] = ""
|
||||
argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "SupportPodPidsLimit=false")
|
||||
argsMap["feature-gates"] = util.AddFeatureGate(argsMap["feature-gates"], "SupportPodPidsLimit=false")
|
||||
}
|
||||
if kubeletRoot != "" {
|
||||
argsMap["kubelet-cgroups"] = kubeletRoot
|
||||
|
@ -143,7 +143,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
|
|||
argsMap["runtime-cgroups"] = runtimeRoot
|
||||
}
|
||||
if system.RunningInUserNS() {
|
||||
argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "DevicePlugins=false")
|
||||
argsMap["feature-gates"] = util.AddFeatureGate(argsMap["feature-gates"], "DevicePlugins=false")
|
||||
}
|
||||
|
||||
argsMap["node-labels"] = strings.Join(cfg.NodeLabels, ",")
|
||||
|
@ -156,7 +156,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
|
|||
|
||||
if ImageCredProvAvailable(cfg) {
|
||||
logrus.Infof("Kubelet image credential provider bin dir and configuration file found.")
|
||||
argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "KubeletCredentialProviders=true")
|
||||
argsMap["feature-gates"] = util.AddFeatureGate(argsMap["feature-gates"], "KubeletCredentialProviders=true")
|
||||
argsMap["image-credential-provider-bin-dir"] = cfg.ImageCredProvBinDir
|
||||
argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig
|
||||
}
|
||||
|
|
|
@ -120,7 +120,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
|
|||
|
||||
if ImageCredProvAvailable(cfg) {
|
||||
logrus.Infof("Kubelet image credential provider bin dir and configuration file found.")
|
||||
argsMap["feature-gates"] = addFeatureGate(argsMap["feature-gates"], "KubeletCredentialProviders=true")
|
||||
argsMap["feature-gates"] = util.AddFeatureGate(argsMap["feature-gates"], "KubeletCredentialProviders=true")
|
||||
argsMap["image-credential-provider-bin-dir"] = cfg.ImageCredProvBinDir
|
||||
argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package util
|
||||
|
||||
// AddFeatureGate correctly appends a feature gate key pair to the feature gates CLI switch.
|
||||
func AddFeatureGate(current, new string) string {
|
||||
if current == "" {
|
||||
return new
|
||||
}
|
||||
return current + "," + new
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAddFeatureGate(t *testing.T) {
|
||||
type args struct {
|
||||
currentArg string
|
||||
featureGate string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "Feature gate added to empty arg",
|
||||
args: args{
|
||||
currentArg: "",
|
||||
featureGate: "SupportPodPidsLimit=false",
|
||||
},
|
||||
want: "SupportPodPidsLimit=false",
|
||||
},
|
||||
{
|
||||
name: "Feature gate added to existing arg",
|
||||
args: args{
|
||||
currentArg: "SupportPodPidsLimit=false",
|
||||
featureGate: "DevicePlugins=false",
|
||||
},
|
||||
want: "SupportPodPidsLimit=false,DevicePlugins=false",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := AddFeatureGate(tt.args.currentArg, tt.args.featureGate)
|
||||
if got != tt.want {
|
||||
t.Errorf("error, should be " + tt.want + ", but got " + got)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue