Skip to content

Commit e661603

Browse files
authored
Merge pull request kubernetes#120844 from bzsuni/cleanup/sets/kubelet
[kubelet] Use a generic Set instead of a specified Set
2 parents 6ac6016 + a8d51f4 commit e661603

35 files changed

+103
-103
lines changed

pkg/kubelet/apis/config/helpers_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ func TestKubeletConfigurationPathFields(t *testing.T) {
3030
if i := kubeletConfigurationPathFieldPaths.Intersection(kubeletConfigurationNonPathFieldPaths); len(i) > 0 {
3131
t.Fatalf("expect the intersection of kubeletConfigurationPathFieldPaths and "+
3232
"KubeletConfigurationNonPathFields to be empty, got:\n%s",
33-
strings.Join(i.List(), "\n"))
33+
strings.Join(sets.List(i), "\n"))
3434
}
3535

3636
// ensure that kubeletConfigurationPathFields U kubeletConfigurationNonPathFields == allPrimitiveFieldPaths(KubeletConfiguration)
37-
expect := sets.NewString().Union(kubeletConfigurationPathFieldPaths).Union(kubeletConfigurationNonPathFieldPaths)
37+
expect := sets.New[string]().Union(kubeletConfigurationPathFieldPaths).Union(kubeletConfigurationNonPathFieldPaths)
3838
result := allPrimitiveFieldPaths(t, expect, reflect.TypeOf(&KubeletConfiguration{}), nil)
3939
if !expect.Equal(result) {
4040
// expected fields missing from result
@@ -46,38 +46,38 @@ func TestKubeletConfigurationPathFields(t *testing.T) {
4646
"If the field has been removed, please remove it from the kubeletConfigurationPathFieldPaths set "+
4747
"and the KubeletConfigurationPathRefs function, "+
4848
"or remove it from the kubeletConfigurationNonPathFieldPaths set, as appropriate:\n%s",
49-
strings.Join(missing.List(), "\n"))
49+
strings.Join(sets.List(missing), "\n"))
5050
}
5151
if len(unexpected) > 0 {
5252
t.Errorf("the following fields were in the result, but unexpected. "+
5353
"If the field is new, please add it to the kubeletConfigurationPathFieldPaths set "+
5454
"and the KubeletConfigurationPathRefs function, "+
5555
"or add it to the kubeletConfigurationNonPathFieldPaths set, as appropriate:\n%s",
56-
strings.Join(unexpected.List(), "\n"))
56+
strings.Join(sets.List(unexpected), "\n"))
5757
}
5858
}
5959
}
6060

6161
// allPrimitiveFieldPaths returns the set of field paths in type `tp`, rooted at `path`.
6262
// It recursively descends into the definition of type `tp` accumulating paths to primitive leaf fields or paths in `skipRecurseList`.
63-
func allPrimitiveFieldPaths(t *testing.T, skipRecurseList sets.String, tp reflect.Type, path *field.Path) sets.String {
63+
func allPrimitiveFieldPaths(t *testing.T, skipRecurseList sets.Set[string], tp reflect.Type, path *field.Path) sets.Set[string] {
6464
// if the current field path is in the list of paths we should not recurse into,
6565
// return here rather than descending and accumulating child field paths
6666
if pathStr := path.String(); len(pathStr) > 0 && skipRecurseList.Has(pathStr) {
67-
return sets.NewString(pathStr)
67+
return sets.New[string](pathStr)
6868
}
6969

70-
paths := sets.NewString()
70+
paths := sets.New[string]()
7171
switch tp.Kind() {
7272
case reflect.Pointer:
73-
paths.Insert(allPrimitiveFieldPaths(t, skipRecurseList, tp.Elem(), path).List()...)
73+
paths.Insert(sets.List(allPrimitiveFieldPaths(t, skipRecurseList, tp.Elem(), path))...)
7474
case reflect.Struct:
7575
for i := 0; i < tp.NumField(); i++ {
7676
field := tp.Field(i)
77-
paths.Insert(allPrimitiveFieldPaths(t, skipRecurseList, field.Type, path.Child(field.Name)).List()...)
77+
paths.Insert(sets.List(allPrimitiveFieldPaths(t, skipRecurseList, field.Type, path.Child(field.Name)))...)
7878
}
7979
case reflect.Map, reflect.Slice:
80-
paths.Insert(allPrimitiveFieldPaths(t, skipRecurseList, tp.Elem(), path.Key("*")).List()...)
80+
paths.Insert(sets.List(allPrimitiveFieldPaths(t, skipRecurseList, tp.Elem(), path.Key("*")))...)
8181
case reflect.Interface:
8282
t.Fatalf("unexpected interface{} field %s", path.String())
8383
default:
@@ -115,7 +115,7 @@ type bar struct {
115115
}
116116

117117
func TestAllPrimitiveFieldPaths(t *testing.T) {
118-
expect := sets.NewString(
118+
expect := sets.New[string](
119119
"str",
120120
"strptr",
121121
"ints[*]",
@@ -140,17 +140,17 @@ func TestAllPrimitiveFieldPaths(t *testing.T) {
140140
unexpected := result.Difference(expect)
141141

142142
if len(missing) > 0 {
143-
t.Errorf("the following fields were expected, but missing from the result:\n%s", strings.Join(missing.List(), "\n"))
143+
t.Errorf("the following fields were expected, but missing from the result:\n%s", strings.Join(sets.List(missing), "\n"))
144144
}
145145
if len(unexpected) > 0 {
146-
t.Errorf("the following fields were in the result, but unexpected:\n%s", strings.Join(unexpected.List(), "\n"))
146+
t.Errorf("the following fields were in the result, but unexpected:\n%s", strings.Join(sets.List(unexpected), "\n"))
147147
}
148148
}
149149
}
150150

151151
var (
152152
// KubeletConfiguration fields that contain file paths. If you update this, also update KubeletConfigurationPathRefs!
153-
kubeletConfigurationPathFieldPaths = sets.NewString(
153+
kubeletConfigurationPathFieldPaths = sets.New[string](
154154
"StaticPodPath",
155155
"Authentication.X509.ClientCAFile",
156156
"TLSCertFile",
@@ -160,7 +160,7 @@ var (
160160
)
161161

162162
// KubeletConfiguration fields that do not contain file paths.
163-
kubeletConfigurationNonPathFieldPaths = sets.NewString(
163+
kubeletConfigurationNonPathFieldPaths = sets.New[string](
164164
"Address",
165165
"AllowedUnsafeSysctls[*]",
166166
"Authentication.Anonymous.Enabled",

pkg/kubelet/cm/devicemanager/manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ func setupPluginManager(t *testing.T, pluginSocketName string, m Manager) plugin
312312
}
313313

314314
func runPluginManager(pluginManager pluginmanager.PluginManager) {
315-
// FIXME: Replace sets.String with sets.Set[string]
316-
sourcesReady := config.NewSourcesReady(func(_ sets.String) bool { return true })
315+
// FIXME: Replace sets.Set[string] with sets.Set[string]
316+
sourcesReady := config.NewSourcesReady(func(_ sets.Set[string]) bool { return true })
317317
go pluginManager.Run(sourcesReady, wait.NeverStop)
318318
}
319319

pkg/kubelet/config/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type PodConfig struct {
6767

6868
// contains the list of all configured sources
6969
sourcesLock sync.Mutex
70-
sources sets.String
70+
sources sets.Set[string]
7171
}
7272

7373
// NewPodConfig creates an object that can merge many configuration sources into a stream
@@ -79,7 +79,7 @@ func NewPodConfig(mode PodConfigNotificationMode, recorder record.EventRecorder,
7979
pods: storage,
8080
mux: newMux(storage),
8181
updates: updates,
82-
sources: sets.String{},
82+
sources: sets.Set[string]{},
8383
}
8484
return podConfig
8585
}
@@ -95,14 +95,14 @@ func (c *PodConfig) Channel(ctx context.Context, source string) chan<- interface
9595

9696
// SeenAllSources returns true if seenSources contains all sources in the
9797
// config, and also this config has received a SET message from each source.
98-
func (c *PodConfig) SeenAllSources(seenSources sets.String) bool {
98+
func (c *PodConfig) SeenAllSources(seenSources sets.Set[string]) bool {
9999
if c.pods == nil {
100100
return false
101101
}
102102
c.sourcesLock.Lock()
103103
defer c.sourcesLock.Unlock()
104-
klog.V(5).InfoS("Looking for sources, have seen", "sources", c.sources.List(), "seenSources", seenSources)
105-
return seenSources.HasAll(c.sources.List()...) && c.pods.seenSources(c.sources.List()...)
104+
klog.V(5).InfoS("Looking for sources, have seen", "sources", sets.List(c.sources), "seenSources", seenSources)
105+
return seenSources.HasAll(sets.List(c.sources)...) && c.pods.seenSources(sets.List(c.sources)...)
106106
}
107107

108108
// Updates returns a channel of updates to the configuration, properly denormalized.
@@ -132,7 +132,7 @@ type podStorage struct {
132132

133133
// contains the set of all sources that have sent at least one SET
134134
sourcesSeenLock sync.RWMutex
135-
sourcesSeen sets.String
135+
sourcesSeen sets.Set[string]
136136

137137
// the EventRecorder to use
138138
recorder record.EventRecorder
@@ -148,7 +148,7 @@ func newPodStorage(updates chan<- kubetypes.PodUpdate, mode PodConfigNotificatio
148148
pods: make(map[string]map[types.UID]*v1.Pod),
149149
mode: mode,
150150
updates: updates,
151-
sourcesSeen: sets.String{},
151+
sourcesSeen: sets.Set[string]{},
152152
recorder: recorder,
153153
startupSLIObserver: startupSLIObserver,
154154
}
@@ -331,7 +331,7 @@ func (s *podStorage) seenSources(sources ...string) bool {
331331
}
332332

333333
func filterInvalidPods(pods []*v1.Pod, source string, recorder record.EventRecorder) (filtered []*v1.Pod) {
334-
names := sets.String{}
334+
names := sets.Set[string]{}
335335
for i, pod := range pods {
336336
// Pods from each source are assumed to have passed validation individually.
337337
// This function only checks if there is any naming conflict.

pkg/kubelet/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ func TestPodConfigRace(t *testing.T) {
455455

456456
eventBroadcaster := record.NewBroadcaster(record.WithContext(tCtx))
457457
config := NewPodConfig(PodConfigNotificationIncremental, eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "kubelet"}), &mockPodStartupSLIObserver{})
458-
seenSources := sets.NewString(TestSource)
458+
seenSources := sets.New[string](TestSource)
459459
var wg sync.WaitGroup
460460
const iterations = 100
461461
wg.Add(2)

pkg/kubelet/config/sources.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
// SourcesReadyFn is function that returns true if the specified sources have been seen.
27-
type SourcesReadyFn func(sourcesSeen sets.String) bool
27+
type SourcesReadyFn func(sourcesSeen sets.Set[string]) bool
2828

2929
// SourcesReady tracks the set of configured sources seen by the kubelet.
3030
type SourcesReady interface {
@@ -37,7 +37,7 @@ type SourcesReady interface {
3737
// NewSourcesReady returns a SourcesReady with the specified function.
3838
func NewSourcesReady(sourcesReadyFn SourcesReadyFn) SourcesReady {
3939
return &sourcesImpl{
40-
sourcesSeen: sets.NewString(),
40+
sourcesSeen: sets.New[string](),
4141
sourcesReadyFn: sourcesReadyFn,
4242
}
4343
}
@@ -47,7 +47,7 @@ type sourcesImpl struct {
4747
// lock protects access to sources seen.
4848
lock sync.RWMutex
4949
// set of sources seen.
50-
sourcesSeen sets.String
50+
sourcesSeen sets.Set[string]
5151
// sourcesReady is a function that evaluates if the sources are ready.
5252
sourcesReadyFn SourcesReadyFn
5353
}

pkg/kubelet/configmap/configmap_manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ func (c *configMapManager) UnregisterPod(pod *v1.Pod) {
9898
c.manager.UnregisterPod(pod)
9999
}
100100

101-
func getConfigMapNames(pod *v1.Pod) sets.String {
102-
result := sets.NewString()
101+
func getConfigMapNames(pod *v1.Pod) sets.Set[string] {
102+
result := sets.New[string]()
103103
podutil.VisitPodConfigmapNames(pod, func(name string) bool {
104104
result.Insert(name)
105105
return true

pkg/kubelet/container/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func ExpandContainerCommandOnlyStatic(containerCommand []string, envs []v1.EnvVa
164164
func ExpandContainerVolumeMounts(mount v1.VolumeMount, envs []EnvVar) (string, error) {
165165

166166
envmap := envVarsToMap(envs)
167-
missingKeys := sets.NewString()
167+
missingKeys := sets.New[string]()
168168
expanded := expansion.Expand(mount.SubPathExpr, func(key string) string {
169169
value, ok := envmap[key]
170170
if !ok || len(value) == 0 {
@@ -174,7 +174,7 @@ func ExpandContainerVolumeMounts(mount v1.VolumeMount, envs []EnvVar) (string, e
174174
})
175175

176176
if len(missingKeys) > 0 {
177-
return "", fmt.Errorf("missing value for %s", strings.Join(missingKeys.List(), ", "))
177+
return "", fmt.Errorf("missing value for %s", strings.Join(sets.List(missingKeys), ", "))
178178
}
179179
return expanded, nil
180180
}

pkg/kubelet/images/image_gc_manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ func (im *realImageGCManager) GetImageList() ([]container.Image, error) {
232232
return im.imageCache.get(), nil
233233
}
234234

235-
func (im *realImageGCManager) detectImages(ctx context.Context, detectTime time.Time) (sets.String, error) {
235+
func (im *realImageGCManager) detectImages(ctx context.Context, detectTime time.Time) (sets.Set[string], error) {
236236
isRuntimeClassInImageCriAPIEnabled := utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClassInImageCriAPI)
237-
imagesInUse := sets.NewString()
237+
imagesInUse := sets.New[string]()
238238

239239
images, err := im.runtime.ListImages(ctx)
240240
if err != nil {
@@ -261,7 +261,7 @@ func (im *realImageGCManager) detectImages(ctx context.Context, detectTime time.
261261

262262
// Add new images and record those being used.
263263
now := time.Now()
264-
currentImages := sets.NewString()
264+
currentImages := sets.New[string]()
265265
im.imageRecordsLock.Lock()
266266
defer im.imageRecordsLock.Unlock()
267267
for _, image := range images {
@@ -554,7 +554,7 @@ func (ev byLastUsedAndDetected) Less(i, j int) bool {
554554
return ev[i].lastUsed.Before(ev[j].lastUsed)
555555
}
556556

557-
func isImageUsed(imageID string, imagesInUse sets.String) bool {
557+
func isImageUsed(imageID string, imagesInUse sets.Set[string]) bool {
558558
// Check the image ID.
559559
if _, ok := imagesInUse[imageID]; ok {
560560
return true

pkg/kubelet/kubelet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2241,7 +2241,7 @@ func (kl *Kubelet) SyncTerminatedPod(ctx context.Context, pod *v1.Pod, podStatus
22412241
func (kl *Kubelet) getPodsToSync() []*v1.Pod {
22422242
allPods := kl.podManager.GetPods()
22432243
podUIDs := kl.workQueue.GetWork()
2244-
podUIDSet := sets.NewString()
2244+
podUIDSet := sets.New[string]()
22452245
for _, podUID := range podUIDs {
22462246
podUIDSet.Insert(string(podUID))
22472247
}

pkg/kubelet/kubelet_node_status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (kl *Kubelet) tryRegisterWithAPIServer(node *v1.Node) bool {
130130
// reconcileHugePageResource will update huge page capacity for each page size and remove huge page sizes no longer supported
131131
func (kl *Kubelet) reconcileHugePageResource(initialNode, existingNode *v1.Node) bool {
132132
requiresUpdate := updateDefaultResources(initialNode, existingNode)
133-
supportedHugePageResources := sets.String{}
133+
supportedHugePageResources := sets.Set[string]{}
134134

135135
for resourceName := range initialNode.Status.Capacity {
136136
if !v1helper.IsHugePageResourceName(resourceName) {

0 commit comments

Comments
 (0)