Skip to content

Commit 20d280c

Browse files
committed
Replace golang.org/x/exp/maps with the standard library's maps package.
Signed-off-by: Feruzjon Muyassarov <[email protected]>
1 parent 6a10142 commit 20d280c

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ require (
2121
github.com/spf13/cobra v1.9.1
2222
github.com/stretchr/testify v1.10.0
2323
github.com/vektra/errors v0.0.0-20140903201135-c64d83aba85a
24-
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
2524
golang.org/x/net v0.35.0
2625
golang.org/x/time v0.10.0
2726
google.golang.org/grpc v1.70.0
@@ -146,6 +145,7 @@ require (
146145
go.uber.org/multierr v1.11.0 // indirect
147146
go.uber.org/zap v1.27.0 // indirect
148147
golang.org/x/crypto v0.33.0 // indirect
148+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
149149
golang.org/x/mod v0.22.0 // indirect
150150
golang.org/x/oauth2 v0.24.0 // indirect
151151
golang.org/x/sync v0.11.0 // indirect

pkg/apis/nfd/nodefeaturerule/expression.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ package nodefeaturerule
1919
import (
2020
"fmt"
2121
"regexp"
22+
"slices"
2223
"sort"
2324
"strconv"
2425
strings "strings"
2526

26-
"golang.org/x/exp/maps"
27+
"maps"
28+
2729
"k8s.io/klog/v2"
2830

2931
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/api/nfd/v1alpha1"
@@ -177,7 +179,7 @@ func evaluateMatchExpressionKeys(m *nfdv1alpha1.MatchExpression, name string, ke
177179
if klogV := klog.V(3); klogV.Enabled() {
178180
klogV.InfoS("matched keys", "matchResult", matched, "matchKey", name, "matchOp", m.Op)
179181
} else if klogV := klog.V(4); klogV.Enabled() {
180-
k := maps.Keys(keys)
182+
k := slices.Collect(maps.Keys(keys))
181183
sort.Strings(k)
182184
klogV.InfoS("matched keys", "matchResult", matched, "matchKey", name, "matchOp", m.Op, "inputKeys", k)
183185
}

pkg/nfd-worker/nfd-worker.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ import (
2323
"os"
2424
"path/filepath"
2525
"regexp"
26+
"slices"
2627
"sort"
2728
"strings"
2829
"time"
2930

31+
"maps"
32+
3033
"github.com/prometheus/client_golang/prometheus"
3134
"github.com/prometheus/client_golang/prometheus/promhttp"
32-
"golang.org/x/exp/maps"
3335
"golang.org/x/net/context"
3436
"k8s.io/apimachinery/pkg/api/errors"
3537
"k8s.io/apimachinery/pkg/types"
@@ -394,7 +396,7 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
394396
}
395397
}
396398

397-
w.featureSources = maps.Values(featureSources)
399+
w.featureSources = slices.Collect(maps.Values(featureSources))
398400

399401
sort.Slice(w.featureSources, func(i, j int) bool { return w.featureSources[i].Name() < w.featureSources[j].Name() })
400402

@@ -426,7 +428,7 @@ func (w *nfdWorker) configureCore(c coreConfig) error {
426428
}
427429
}
428430

429-
w.labelSources = maps.Values(labelSources)
431+
w.labelSources = slices.Collect(maps.Values(labelSources))
430432

431433
sort.Slice(w.labelSources, func(i, j int) bool {
432434
iP, jP := w.labelSources[i].Priority(), w.labelSources[j].Priority()

pkg/utils/flags.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ import (
2121
"flag"
2222
"fmt"
2323
"regexp"
24+
"slices"
2425
"sort"
2526
"strings"
2627
"time"
2728

28-
"golang.org/x/exp/maps"
29+
"maps"
2930
)
3031

3132
// RegexpVal is a wrapper for regexp command line flags
@@ -60,7 +61,7 @@ func (a *StringSetVal) String() string {
6061
if *a == nil {
6162
return ""
6263
}
63-
vals := maps.Keys(*a)
64+
vals := slices.Collect(maps.Keys(*a))
6465
sort.Strings(vals)
6566
return strings.Join(vals, ",")
6667
}

source/pci/pci.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ package pci
1818

1919
import (
2020
"fmt"
21+
"slices"
2122
"strings"
2223

23-
"golang.org/x/exp/maps"
24+
"maps"
25+
2426
"k8s.io/klog/v2"
2527

2628
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/api/nfd/v1alpha1"
@@ -103,7 +105,7 @@ func (s *pciSource) GetLabels() (source.FeatureLabels, error) {
103105
}
104106
}
105107
if len(configLabelFields) > 0 {
106-
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", maps.Keys(configLabelFields))
108+
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", slices.Collect(maps.Keys(configLabelFields)))
107109
}
108110
if len(deviceLabelFields) == 0 {
109111
deviceLabelFields = []string{"class", "vendor"}

source/usb/usb.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ package usb
1818

1919
import (
2020
"fmt"
21+
"slices"
2122
"strings"
2223

23-
"golang.org/x/exp/maps"
24+
"maps"
25+
2426
"k8s.io/klog/v2"
2527

2628
nfdv1alpha1 "sigs.k8s.io/node-feature-discovery/api/nfd/v1alpha1"
@@ -106,7 +108,7 @@ func (s *usbSource) GetLabels() (source.FeatureLabels, error) {
106108
}
107109
}
108110
if len(configLabelFields) > 0 {
109-
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", maps.Keys(configLabelFields))
111+
klog.InfoS("ignoring invalid fields in deviceLabelFields", "invalidFieldNames", slices.Collect(maps.Keys(configLabelFields)))
110112
}
111113
if len(deviceLabelFields) == 0 {
112114
deviceLabelFields = defaultDeviceLabelFields()

0 commit comments

Comments
 (0)