Skip to content

Commit

Permalink
Add workaround for missing maps package
Browse files Browse the repository at this point in the history
  • Loading branch information
avorima committed Mar 13, 2024
1 parent 8693a50 commit 42b8df2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cluster-autoscaler/cloudprovider/ionoscloud/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package ionoscloud

import (
"maps"
"sync"

"k8s.io/autoscaler/cluster-autoscaler/cloudprovider"
Expand Down Expand Up @@ -73,12 +72,21 @@ func (cache *IonosCache) SetInstancesCacheForNodeGroup(id string, instances []cl
cache.mutex.Lock()
defer cache.mutex.Unlock()

maps.DeleteFunc(cache.nodesToNodeGroups, func(_, nodeGroupID string) bool {
mapsDeleteFunc(cache.nodesToNodeGroups, func(_, nodeGroupID string) bool {
return nodeGroupID == id
})
cache.setInstancesCacheForNodeGroupNoLock(id, instances)
}

// placeholder for maps.DeleteFunc in go 1.21
func mapsDeleteFunc(m map[string]string, del func(k, v string) bool) {
for k, v := range m {
if del(k, v) {
delete(m, k)
}
}
}

func (cache *IonosCache) setInstancesCacheForNodeGroupNoLock(id string, instances []cloudprovider.Instance) {
for _, instance := range instances {
nodeID := convertToNodeID(instance.Id)
Expand Down

0 comments on commit 42b8df2

Please sign in to comment.