don't use index

This commit is contained in:
Benjamin Elder
2022-09-06 11:59:31 -07:00
parent 965bde6c90
commit bd637d823d

View File

@@ -95,8 +95,8 @@ type DerivedConfigData struct {
AdvertiseAddress string
// DockerStableTag is automatically derived from KubernetesVersion
DockerStableTag string
// SortedFeatureGateKeys allows us to iterate FeatureGates deterministically
SortedFeatureGateKeys []string
// SortedFeatureGates allows us to iterate FeatureGates deterministically
SortedFeatureGates []FeatureGate
// FeatureGatesString is of the form `Foo=true,Baz=false`
FeatureGatesString string
// RuntimeConfigString is of the form `Foo=true,Baz=false`
@@ -109,6 +109,11 @@ type DerivedConfigData struct {
CgroupDriver string
}
type FeatureGate struct {
Name string
Value bool
}
// Derive automatically derives DockerStableTag if not specified
func (c *ConfigData) Derive() {
// default cgroup driver
@@ -131,13 +136,17 @@ func (c *ConfigData) Derive() {
featureGateKeys = append(featureGateKeys, k)
}
sort.Strings(featureGateKeys)
c.SortedFeatureGateKeys = featureGateKeys
// create a sorted key=value,... string of FeatureGates
var featureGates []string
c.SortedFeatureGates = make([]FeatureGate, 0, len(c.FeatureGates))
featureGates := make([]string, 0, len(c.FeatureGates))
for _, k := range featureGateKeys {
v := c.FeatureGates[k]
featureGates = append(featureGates, fmt.Sprintf("%s=%t", k, v))
c.SortedFeatureGates = append(c.SortedFeatureGates, FeatureGate{
Name: k,
Value: v,
})
}
c.FeatureGatesString = strings.Join(featureGates, ",")
@@ -273,8 +282,8 @@ evictionHard:
nodefs.inodesFree: "0%"
imagefs.available: "0%"
{{if .FeatureGates}}featureGates:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{ index $.FeatureGates $key }}
{{ range $index, $gate := .SortedFeatureGates }}
"{{ $gate .Name }}": {{ $gate .Value }}
{{end}}{{end}}
{{if ne .KubeProxyMode "None"}}
---
@@ -284,8 +293,8 @@ metadata:
name: config
mode: "{{ .KubeProxyMode }}"
{{if .FeatureGates}}featureGates:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{ index $.FeatureGates $key }}
{{ range $index, $gate := .SortedFeatureGates }}
"{{ $gate .Name }}": {{ $gate .Value }}
{{end}}{{end}}
iptables:
minSyncPeriod: 1s
@@ -410,8 +419,8 @@ evictionHard:
nodefs.inodesFree: "0%"
imagefs.available: "0%"
{{if .FeatureGates}}featureGates:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{ index $.FeatureGates $key }}
{{ range $index, $gate := .SortedFeatureGates }}
"{{ $gate .Name }}": {{ $gate .Value }}
{{end}}{{end}}
{{if .DisableLocalStorageCapacityIsolation}}localStorageCapacityIsolation: false{{end}}
{{if ne .KubeProxyMode "None"}}
@@ -422,8 +431,8 @@ metadata:
name: config
mode: "{{ .KubeProxyMode }}"
{{if .FeatureGates}}featureGates:
{{ range $key := .SortedFeatureGateKeys }}
"{{ $key }}": {{ index $.FeatureGates $key }}
{{ range $index, $gate := .SortedFeatureGates }}
"{{ $gate .Name }}": {{ $gate .Value }}
{{end}}{{end}}
iptables:
minSyncPeriod: 1s