Skip to content

Commit 86b4ce5

Browse files
committed
Clean up linter isuses (migrate sets.String)
1 parent a4e2c90 commit 86b4ce5

File tree

8 files changed

+33
-27
lines changed

8 files changed

+33
-27
lines changed

cmd/kubelet/app/options/options.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,27 @@ func (f *KubeletFlags) AddFlags(mainfs *pflag.FlagSet) {
313313

314314
// DEPRECATED FLAGS
315315
fs.DurationVar(&f.MinimumGCAge.Duration, "minimum-container-ttl-duration", f.MinimumGCAge.Duration, "Minimum age for a finished container before it is garbage collected. Examples: '300ms', '10s' or '2h45m'")
316-
fs.MarkDeprecated("minimum-container-ttl-duration", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
316+
mustMarkDeprecated(fs, "minimum-container-ttl-duration", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
317317
fs.Int32Var(&f.MaxPerPodContainerCount, "maximum-dead-containers-per-container", f.MaxPerPodContainerCount, "Maximum number of old instances to retain per container. Each container takes up some disk space.")
318-
fs.MarkDeprecated("maximum-dead-containers-per-container", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
318+
mustMarkDeprecated(fs, "maximum-dead-containers-per-container", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
319319
fs.Int32Var(&f.MaxContainerCount, "maximum-dead-containers", f.MaxContainerCount, "Maximum number of old instances of containers to retain globally. Each container takes up some disk space. To disable, set to a negative number.")
320-
fs.MarkDeprecated("maximum-dead-containers", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
320+
mustMarkDeprecated(fs, "maximum-dead-containers", "Use --eviction-hard or --eviction-soft instead. Will be removed in a future version.")
321321
fs.BoolVar(&f.RegisterSchedulable, "register-schedulable", f.RegisterSchedulable, "Register the node as schedulable. Won't have any effect if register-node is false.")
322-
fs.MarkDeprecated("register-schedulable", "will be removed in a future version")
322+
mustMarkDeprecated(fs, "register-schedulable", "will be removed in a future version")
323323
fs.BoolVar(&f.KeepTerminatedPodVolumes, "keep-terminated-pod-volumes", f.KeepTerminatedPodVolumes, "Keep terminated pod volumes mounted to the node after the pod terminates. Can be useful for debugging volume related issues.")
324-
fs.MarkDeprecated("keep-terminated-pod-volumes", "will be removed in a future version")
324+
mustMarkDeprecated(fs, "keep-terminated-pod-volumes", "will be removed in a future version")
325325
fs.StringVar(&f.ExperimentalMounterPath, "experimental-mounter-path", f.ExperimentalMounterPath, "[Experimental] Path of mounter binary. Leave empty to use the default mount.")
326-
fs.MarkDeprecated("experimental-mounter-path", "will be removed in 1.25 or later. in favor of using CSI.")
326+
mustMarkDeprecated(fs, "experimental-mounter-path", "will be removed in 1.25 or later. in favor of using CSI.")
327327
fs.StringVar(&f.CloudConfigFile, "cloud-config", f.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
328-
fs.MarkDeprecated("cloud-config", "will be removed in 1.25 or later, in favor of removing cloud provider code from Kubelet.")
328+
mustMarkDeprecated(fs, "cloud-config", "will be removed in 1.25 or later, in favor of removing cloud provider code from Kubelet.")
329329
fs.BoolVar(&f.ExperimentalNodeAllocatableIgnoreEvictionThreshold, "experimental-allocatable-ignore-eviction", f.ExperimentalNodeAllocatableIgnoreEvictionThreshold, "When set to 'true', Hard Eviction Thresholds will be ignored while calculating Node Allocatable. See https://kubernetes.io/docs/tasks/administer-cluster/reserve-compute-resources/ for more details. [default=false]")
330-
fs.MarkDeprecated("experimental-allocatable-ignore-eviction", "will be removed in 1.25 or later.")
330+
mustMarkDeprecated(fs, "experimental-allocatable-ignore-eviction", "will be removed in 1.25 or later.")
331+
}
332+
333+
func mustMarkDeprecated(fs *pflag.FlagSet, name, userMessage string) {
334+
if err := fs.MarkDeprecated(name, userMessage); err != nil {
335+
panic(err)
336+
}
331337
}
332338

333339
// addContainerRuntimeFlags adds flags to the container runtime, according to ContainerRuntimeOptions.

pkg/kubelet/cm/devicemanager/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ func setupPluginManager(t *testing.T, pluginSocketName string, m Manager) plugin
313313

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

pkg/kubelet/kubelet_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func newTestKubeletWithImageList(
215215
if err := os.MkdirAll(kubelet.rootDirectory, 0750); err != nil {
216216
t.Fatalf("can't mkdir(%q): %v", kubelet.rootDirectory, err)
217217
}
218-
kubelet.sourcesReady = podsource.NewSourcesReady(func(_ sets.String) bool { return true })
218+
kubelet.sourcesReady = podsource.NewSourcesReady(func(_ sets.Set[string]) bool { return true })
219219
kubelet.serviceLister = testServiceLister{}
220220
kubelet.serviceHasSynced = func() bool { return true }
221221
kubelet.nodeHasSynced = func() bool { return true }
@@ -735,7 +735,7 @@ func TestHandlePodRemovesWhenSourcesAreReady(t *testing.T) {
735735
{Pod: fakePod},
736736
}
737737
kubelet := testKubelet.kubelet
738-
kubelet.sourcesReady = podsource.NewSourcesReady(func(_ sets.String) bool { return ready })
738+
kubelet.sourcesReady = podsource.NewSourcesReady(func(_ sets.Set[string]) bool { return ready })
739739

740740
kubelet.HandlePodRemoves(pods)
741741
time.Sleep(2 * time.Second)

pkg/kubelet/pluginmanager/plugin_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestPluginRegistration(t *testing.T) {
131131
stopChan := make(chan struct{})
132132
defer close(stopChan)
133133
go func() {
134-
sourcesReady := podsource.NewSourcesReady(func(_ sets.String) bool { return true })
134+
sourcesReady := podsource.NewSourcesReady(func(_ sets.Set[string]) bool { return true })
135135
pluginManager.Run(sourcesReady, stopChan)
136136
}()
137137

pkg/kubelet/podsource/podsource.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type PodSource 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
// NewPodSource creates an object that can merge many configuration sources into a stream
@@ -79,7 +79,7 @@ func NewPodSource(mode PodSourceNotificationMode, recorder record.EventRecorder,
7979
pods: storage,
8080
mux: newMux(storage),
8181
updates: updates,
82-
sources: sets.String{},
82+
sources: sets.New[string](),
8383
}
8484
return podSource
8585
}
@@ -95,14 +95,14 @@ func (c *PodSource) 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 *PodSource) SeenAllSources(seenSources sets.String) bool {
98+
func (c *PodSource) 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", c.sources.UnsortedList(), "seenSources", seenSources)
105+
return seenSources.IsSuperset(c.sources) && c.pods.seenSources(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 PodSourceNotificatio
148148
pods: make(map[string]map[types.UID]*v1.Pod),
149149
mode: mode,
150150
updates: updates,
151-
sourcesSeen: sets.String{},
151+
sourcesSeen: sets.New[string](),
152152
recorder: recorder,
153153
startupSLIObserver: startupSLIObserver,
154154
}
@@ -324,14 +324,14 @@ func (s *podStorage) markSourceSet(source string) {
324324
s.sourcesSeen.Insert(source)
325325
}
326326

327-
func (s *podStorage) seenSources(sources ...string) bool {
327+
func (s *podStorage) seenSources(sources sets.Set[string]) bool {
328328
s.sourcesSeenLock.RLock()
329329
defer s.sourcesSeenLock.RUnlock()
330-
return s.sourcesSeen.HasAll(sources...)
330+
return s.sourcesSeen.IsSuperset(sources)
331331
}
332332

333333
func filterInvalidPods(pods []*v1.Pod, source string, recorder record.EventRecorder) (filtered []*v1.Pod) {
334-
names := sets.String{}
334+
names := sets.New[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/podsource/podsource_test.go

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

486486
eventBroadcaster := record.NewBroadcaster(record.WithContext(ctx))
487487
config := NewPodSource(PodSourceNotificationIncremental, eventBroadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: "kubelet"}), &mockPodStartupSLIObserver{})
488-
seenSources := sets.NewString(TestSource)
488+
seenSources := sets.New[string](TestSource)
489489
var wg sync.WaitGroup
490490
const iterations = 100
491491
wg.Add(2)

pkg/kubelet/podsource/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/volumemanager/volume_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ func runVolumeManager(manager VolumeManager) chan struct{} {
543543
stopCh := make(chan struct{})
544544
//readyCh := make(chan bool, 1)
545545
//readyCh <- true
546-
sourcesReady := podsource.NewSourcesReady(func(_ sets.String) bool { return true })
546+
sourcesReady := podsource.NewSourcesReady(func(_ sets.Set[string]) bool { return true })
547547
go manager.Run(sourcesReady, stopCh)
548548
return stopCh
549549
}

0 commit comments

Comments
 (0)