Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Adding ServiceNodeExclusion as a default flag for Controller Manager #2180

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/acsengine/defaults-controller-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 0 additions & 52 deletions pkg/acsengine/defaults-kubelet.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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(), ",")
}
52 changes: 52 additions & 0 deletions pkg/acsengine/defaults.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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(), ",")
}