From a8e484be75ebaf07bd4b1490525ad03a1e2b3859 Mon Sep 17 00:00:00 2001 From: Bhargav Nookala Date: Mon, 29 Jan 2018 13:20:30 -0800 Subject: [PATCH] Adding ServiceNodeExclusion as a default flag for Controller Manager --- pkg/acsengine/defaults-controller-manager.go | 3 ++ pkg/acsengine/defaults-kubelet.go | 52 -------------------- pkg/acsengine/defaults.go | 52 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/pkg/acsengine/defaults-controller-manager.go b/pkg/acsengine/defaults-controller-manager.go index 156bc3f7db..f44079e40a 100644 --- a/pkg/acsengine/defaults-controller-manager.go +++ b/pkg/acsengine/defaults-controller-manager.go @@ -64,6 +64,9 @@ func setControllerManagerConfig(cs *api.ContainerService) { } } + // Enables Node Exclusion from Services (toggled on agent nodes by the alpha.service-controller.kubernetes.io/exclude-balancer label). + addDefaultFeatureGates(o.KubernetesConfig.ControllerManagerConfig, o.OrchestratorVersion, "1.9.0", "ServiceNodeExclusion=true") + // We don't support user-configurable values for the following, // so any of the value assignments below will override user-provided values var overrideControllerManagerConfig map[string]string diff --git a/pkg/acsengine/defaults-kubelet.go b/pkg/acsengine/defaults-kubelet.go index f6de6bb7f4..5539323a0b 100644 --- a/pkg/acsengine/defaults-kubelet.go +++ b/pkg/acsengine/defaults-kubelet.go @@ -1,11 +1,7 @@ package acsengine import ( - "bytes" - "fmt" - "sort" "strconv" - "strings" "github.com/Azure/acs-engine/pkg/api" "github.com/Azure/acs-engine/pkg/helpers" @@ -114,20 +110,6 @@ func setKubeletConfig(cs *api.ContainerService) { } } -// combine user-provided --feature-gates vals with defaults -// a minimum k8s version may be declared as required for defaults assignment -func addDefaultFeatureGates(m map[string]string, version string, minVersion string, defaults string) { - if minVersion != "" { - if isKubernetesVersionGe(version, minVersion) { - m["--feature-gates"] = combineValues(m["--feature-gates"], defaults) - } else { - m["--feature-gates"] = combineValues(m["--feature-gates"], "") - } - } else { - m["--feature-gates"] = combineValues(m["--feature-gates"], defaults) - } -} - func setMissingKubeletValues(p *api.KubernetesConfig, d map[string]string) { if p.KubeletConfig == nil { p.KubeletConfig = d @@ -148,37 +130,3 @@ func copyMap(input map[string]string) map[string]string { } return copy } -func combineValues(inputs ...string) string { - var valueMap map[string]string - valueMap = make(map[string]string) - for _, input := range inputs { - applyValueStringToMap(valueMap, input) - } - return mapToString(valueMap) -} - -func applyValueStringToMap(valueMap map[string]string, input string) { - values := strings.Split(input, ",") - for index := 0; index < len(values); index++ { - // trim spaces (e.g. if the input was "foo=true, bar=true" - we want to drop the space after the comma) - value := strings.Trim(values[index], " ") - valueParts := strings.Split(value, "=") - if len(valueParts) == 2 { - valueMap[valueParts[0]] = valueParts[1] - } - } -} - -func mapToString(valueMap map[string]string) string { - // Order by key for consistency - keys := []string{} - for key := range valueMap { - keys = append(keys, key) - } - sort.Strings(keys) - var buf bytes.Buffer - for _, key := range keys { - buf.WriteString(fmt.Sprintf("%s=%s,", key, valueMap[key])) - } - return strings.TrimSuffix(buf.String(), ",") -} diff --git a/pkg/acsengine/defaults.go b/pkg/acsengine/defaults.go index 5916b77964..14865f6f99 100644 --- a/pkg/acsengine/defaults.go +++ b/pkg/acsengine/defaults.go @@ -1,9 +1,12 @@ package acsengine import ( + "bytes" "encoding/binary" "fmt" "net" + "sort" + "strings" "github.com/Azure/acs-engine/pkg/api" "github.com/Azure/acs-engine/pkg/api/common" @@ -757,3 +760,52 @@ func isKubernetesVersionGe(actualVersion, version string) bool { constraint, _ := semver.NewConstraint(">=" + version) return constraint.Check(orchestratorVersion) } + +// combine user-provided --feature-gates vals with defaults +// a minimum k8s version may be declared as required for defaults assignment +func addDefaultFeatureGates(m map[string]string, version string, minVersion string, defaults string) { + if minVersion != "" { + if isKubernetesVersionGe(version, minVersion) { + m["--feature-gates"] = combineValues(m["--feature-gates"], defaults) + } else { + m["--feature-gates"] = combineValues(m["--feature-gates"], "") + } + } else { + m["--feature-gates"] = combineValues(m["--feature-gates"], defaults) + } +} + +func combineValues(inputs ...string) string { + var valueMap map[string]string + valueMap = make(map[string]string) + for _, input := range inputs { + applyValueStringToMap(valueMap, input) + } + return mapToString(valueMap) +} + +func applyValueStringToMap(valueMap map[string]string, input string) { + values := strings.Split(input, ",") + for index := 0; index < len(values); index++ { + // trim spaces (e.g. if the input was "foo=true, bar=true" - we want to drop the space after the comma) + value := strings.Trim(values[index], " ") + valueParts := strings.Split(value, "=") + if len(valueParts) == 2 { + valueMap[valueParts[0]] = valueParts[1] + } + } +} + +func mapToString(valueMap map[string]string) string { + // Order by key for consistency + keys := []string{} + for key := range valueMap { + keys = append(keys, key) + } + sort.Strings(keys) + var buf bytes.Buffer + for _, key := range keys { + buf.WriteString(fmt.Sprintf("%s=%s,", key, valueMap[key])) + } + return strings.TrimSuffix(buf.String(), ",") +}