Unverified Commit 7704fb6e authored by Jamie Phillips's avatar Jamie Phillips Committed by GitHub

Exporting the AddFeatureGate function and adding a unit test for it. (#3661)

parent fc19b805
...@@ -57,13 +57,6 @@ func startKubelet(cfg *daemonconfig.Agent) error { ...@@ -57,13 +57,6 @@ func startKubelet(cfg *daemonconfig.Agent) error {
return executor.Kubelet(args) 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 // 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. // 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 { func ImageCredProvAvailable(cfg *daemonconfig.Agent) bool {
......
...@@ -134,7 +134,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string { ...@@ -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") logrus.Warn("Disabling pod PIDs limit feature due to missing cgroup pids support")
argsMap["cgroups-per-qos"] = "false" argsMap["cgroups-per-qos"] = "false"
argsMap["enforce-node-allocatable"] = "" 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 != "" { if kubeletRoot != "" {
argsMap["kubelet-cgroups"] = kubeletRoot argsMap["kubelet-cgroups"] = kubeletRoot
...@@ -143,7 +143,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string { ...@@ -143,7 +143,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
argsMap["runtime-cgroups"] = runtimeRoot argsMap["runtime-cgroups"] = runtimeRoot
} }
if system.RunningInUserNS() { 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, ",") argsMap["node-labels"] = strings.Join(cfg.NodeLabels, ",")
...@@ -156,7 +156,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string { ...@@ -156,7 +156,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
if ImageCredProvAvailable(cfg) { if ImageCredProvAvailable(cfg) {
logrus.Infof("Kubelet image credential provider bin dir and configuration file found.") 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-bin-dir"] = cfg.ImageCredProvBinDir
argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig
} }
......
...@@ -120,7 +120,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string { ...@@ -120,7 +120,7 @@ func kubeletArgs(cfg *config.Agent) map[string]string {
if ImageCredProvAvailable(cfg) { if ImageCredProvAvailable(cfg) {
logrus.Infof("Kubelet image credential provider bin dir and configuration file found.") 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-bin-dir"] = cfg.ImageCredProvBinDir
argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig argsMap["image-credential-provider-config"] = cfg.ImageCredProvConfig
} }
......
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
}
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)
}
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment