Skip to content

Commit e3347b5

Browse files
authored
Merge pull request kubernetes-sigs#3012 from tklauser/drop-x-exp-maps
🌱 Switch to Go 1.23+ stdlib `maps`/`slices` packages
2 parents c1331a5 + 6f1501d commit e3347b5

File tree

5 files changed

+9
-10
lines changed

5 files changed

+9
-10
lines changed

examples/scratch-env/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ require (
4040
github.com/prometheus/procfs v0.15.1 // indirect
4141
github.com/x448/float16 v0.8.4 // indirect
4242
go.uber.org/multierr v1.11.0 // indirect
43-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
4443
golang.org/x/net v0.30.0 // indirect
4544
golang.org/x/oauth2 v0.23.0 // indirect
4645
golang.org/x/sync v0.8.0 // indirect

examples/scratch-env/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
112112
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
113113
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
114114
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
115-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
116-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
117115
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
118116
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
119117
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/prometheus/client_model v0.6.1
1616
go.uber.org/goleak v1.3.0
1717
go.uber.org/zap v1.27.0
18-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
18+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
1919
golang.org/x/mod v0.21.0
2020
golang.org/x/sync v0.8.0
2121
golang.org/x/sys v0.26.0

pkg/cache/cache.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ package cache
1919
import (
2020
"context"
2121
"fmt"
22+
"maps"
2223
"net/http"
24+
"slices"
2325
"sort"
2426
"time"
2527

26-
"golang.org/x/exp/maps"
2728
corev1 "k8s.io/api/core/v1"
2829
"k8s.io/apimachinery/pkg/api/meta"
2930
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -465,7 +466,7 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
465466
if namespace == metav1.NamespaceAll {
466467
config.FieldSelector = fields.AndSelectors(
467468
appendIfNotNil(
468-
namespaceAllSelector(maps.Keys(byObject.Namespaces)),
469+
namespaceAllSelector(slices.Collect(maps.Keys(byObject.Namespaces))),
469470
config.FieldSelector,
470471
)...,
471472
)
@@ -495,7 +496,7 @@ func defaultOpts(config *rest.Config, opts Options) (Options, error) {
495496
if namespace == metav1.NamespaceAll {
496497
cfg.FieldSelector = fields.AndSelectors(
497498
appendIfNotNil(
498-
namespaceAllSelector(maps.Keys(opts.DefaultNamespaces)),
499+
namespaceAllSelector(slices.Collect(maps.Keys(opts.DefaultNamespaces))),
499500
cfg.FieldSelector,
500501
)...,
501502
)

pkg/cache/delegating_by_gvk_cache.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package cache
1818

1919
import (
2020
"context"
21+
"maps"
22+
"slices"
2123
"strings"
2224
"sync"
2325

24-
"golang.org/x/exp/maps"
2526
"k8s.io/apimachinery/pkg/runtime"
2627
"k8s.io/apimachinery/pkg/runtime/schema"
2728
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -73,7 +74,7 @@ func (dbt *delegatingByGVKCache) GetInformerForKind(ctx context.Context, gvk sch
7374
}
7475

7576
func (dbt *delegatingByGVKCache) Start(ctx context.Context) error {
76-
allCaches := maps.Values(dbt.caches)
77+
allCaches := slices.Collect(maps.Values(dbt.caches))
7778
allCaches = append(allCaches, dbt.defaultCache)
7879

7980
wg := &sync.WaitGroup{}
@@ -100,7 +101,7 @@ func (dbt *delegatingByGVKCache) Start(ctx context.Context) error {
100101

101102
func (dbt *delegatingByGVKCache) WaitForCacheSync(ctx context.Context) bool {
102103
synced := true
103-
for _, cache := range append(maps.Values(dbt.caches), dbt.defaultCache) {
104+
for _, cache := range append(slices.Collect(maps.Values(dbt.caches)), dbt.defaultCache) {
104105
if !cache.WaitForCacheSync(ctx) {
105106
synced = false
106107
}

0 commit comments

Comments
 (0)