Skip to content

Commit

Permalink
Merge pull request #16559 from hakman/automated-cherry-pick-of-#16556…
Browse files Browse the repository at this point in the history
…-upstream-release-1.28

Automated cherry pick of #16556: cluster-autoscaler: Fix priority expander config
  • Loading branch information
k8s-ci-robot authored May 10, 2024
2 parents 199545f + 0a72efb commit 6b98059
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
version: 9.99.0
- id: k8s-1.15
manifest: cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml
manifestHash: 41dc4453160d8f9ae80a1b9beb288252649912296ca56dc3f70dda6cf3cbfaa1
manifestHash: 8170c20f6d8184dff873231d153b5f6d93f5d8dd75f739963f6d091b6b7f2187
name: cluster-autoscaler.addons.k8s.io
selector:
k8s-addon: cluster-autoscaler.addons.k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ spec:
apiVersion: v1
data:
priorities: |-
"0":
0:
- .*
"50":
- .*low.*
"100":
100:
- .*high.*
50:
- .*low.*
kind: ConfigMap
metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
version: 9.99.0
- id: k8s-1.15
manifest: cluster-autoscaler.addons.k8s.io/k8s-1.15.yaml
manifestHash: 9b04006b3916dbc0e5fe22f2a23a1fa72d1665e12fe1b96f4cd7707cb823f7d7
manifestHash: f63778b4b540b89fff019defd1eec7e2320233b6eb54b46897a00589f3fceb92
name: cluster-autoscaler.addons.k8s.io
selector:
k8s-addon: cluster-autoscaler.addons.k8s.io
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ spec:
apiVersion: v1
data:
priorities: |-
"0":
0:
- nodes.cas-priority-expander.example.com
"50":
- nodes-low-priority.cas-priority-expander.example.com
"100":
100:
- nodes-high-priority.cas-priority-expander.example.com
50:
- nodes-low-priority.cas-priority-expander.example.com
kind: ConfigMap
metadata:
creationTimestamp: null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ metadata:
k8s-addon: cluster-autoscaler.addons.k8s.io
k8s-app: cluster-autoscaler
data:
priorities: |-
{{- ClusterAutoscalerPriorities | ToYAML | nindent 4 }}
priorities: |- {{ ClusterAutoscalerPriorities | nindent 4 }}
{{ end }}
---
# Source: cluster-autoscaler/templates/deployment.yaml
Expand Down
16 changes: 12 additions & 4 deletions upup/pkg/fi/cloudup/template_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import (
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
"k8s.io/kops/upup/pkg/fi/cloudup/scaleway"
"k8s.io/kops/util/pkg/env"
"k8s.io/kops/util/pkg/maps"
"sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -337,19 +338,26 @@ func (tf *TemplateFunctions) AddTo(dest template.FuncMap, secretStore fi.SecretS
dest["UseServiceAccountExternalPermissions"] = tf.UseServiceAccountExternalPermissions

if cluster.Spec.ClusterAutoscaler != nil {
dest["ClusterAutoscalerPriorities"] = func() map[string][]string {
dest["ClusterAutoscalerPriorities"] = func() string {
priorities := make(map[string][]string)
if cluster.Spec.ClusterAutoscaler.CustomPriorityExpanderConfig != nil {
priorities = cluster.Spec.ClusterAutoscaler.CustomPriorityExpanderConfig
} else {
for name, spec := range tf.GetNodeInstanceGroups() {

if spec.Autoscale != nil {
priorities[fmt.Sprint(spec.AutoscalePriority)] = append(priorities[fmt.Sprint(spec.AutoscalePriority)], fmt.Sprintf("%s.%s", name, tf.ClusterName()))
priorities[strconv.Itoa(int(spec.AutoscalePriority))] = append(priorities[strconv.Itoa(int(spec.AutoscalePriority))], fmt.Sprintf("%s.%s", name, tf.ClusterName()))
}
}
}
return priorities

var prioritiesStr []string
for _, prio := range maps.SortedKeys(priorities) {
prioritiesStr = append(prioritiesStr, fmt.Sprintf("%s:", prio))
for _, value := range priorities[prio] {
prioritiesStr = append(prioritiesStr, fmt.Sprintf("- %s", value))
}
}
return strings.Join(prioritiesStr, "\n")
}
dest["CreateClusterAutoscalerPriorityConfig"] = func() bool {
return fi.ValueOf(cluster.Spec.ClusterAutoscaler.CreatePriorityExpenderConfig)
Expand Down
25 changes: 9 additions & 16 deletions util/pkg/maps/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,21 @@ limitations under the License.
package maps

import (
"reflect"
"sort"
"cmp"
"slices"

"golang.org/x/exp/maps"
)

// Keys returns the keys of a map
func Keys(m interface{}) []string {
var list []string

v := reflect.ValueOf(m)
if v.Kind() == reflect.Map {
for _, x := range v.MapKeys() {
list = append(list, x.String())
}
}

return list
func Keys[M ~map[K]V, K comparable, V any](m M) []K {
return maps.Keys(m)
}

// SortedKeys returns a list of sorted keys
func SortedKeys(m interface{}) []string {
list := Keys(m)
sort.Strings(list)
func SortedKeys[M ~map[K]V, K cmp.Ordered, V any](m M) []K {
list := maps.Keys(m)
slices.Sort(list)

return list
}

0 comments on commit 6b98059

Please sign in to comment.