Skip to content

Commit a2c5167

Browse files
committed
Cleanup more static check issues (S1*,ST*)
1 parent 8a495cb commit a2c5167

File tree

21 files changed

+99
-115
lines changed

21 files changed

+99
-115
lines changed

pkg/kubelet/cm/cpumanager/state/state_file.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"io/ioutil"
23-
"k8s.io/klog"
24-
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
2523
"os"
2624
"sync"
25+
26+
"k8s.io/klog"
27+
"k8s.io/kubernetes/pkg/kubelet/cm/cpuset"
2728
)
2829

2930
type stateFileData struct {
@@ -144,7 +145,6 @@ func (sf *stateFile) storeState() {
144145
if err = ioutil.WriteFile(sf.stateFilePath, content, 0644); err != nil {
145146
panic("[cpumanager] state file not written")
146147
}
147-
return
148148
}
149149

150150
func (sf *stateFile) GetCPUSet(containerID string) (cpuset.CPUSet, bool) {

pkg/kubelet/cm/devicemanager/manager_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ func TestDevicePluginReRegistration(t *testing.T) {
109109
t.Fatalf("timeout while waiting for manager update")
110110
}
111111
capacity, allocatable, _ := m.GetCapacity()
112-
resourceCapacity, _ := capacity[v1.ResourceName(testResourceName)]
113-
resourceAllocatable, _ := allocatable[v1.ResourceName(testResourceName)]
112+
resourceCapacity := capacity[v1.ResourceName(testResourceName)]
113+
resourceAllocatable := allocatable[v1.ResourceName(testResourceName)]
114114
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
115115
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
116116

@@ -125,8 +125,8 @@ func TestDevicePluginReRegistration(t *testing.T) {
125125
t.Fatalf("timeout while waiting for manager update")
126126
}
127127
capacity, allocatable, _ = m.GetCapacity()
128-
resourceCapacity, _ = capacity[v1.ResourceName(testResourceName)]
129-
resourceAllocatable, _ = allocatable[v1.ResourceName(testResourceName)]
128+
resourceCapacity = capacity[v1.ResourceName(testResourceName)]
129+
resourceAllocatable = allocatable[v1.ResourceName(testResourceName)]
130130
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
131131
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices shouldn't change.")
132132

@@ -142,8 +142,8 @@ func TestDevicePluginReRegistration(t *testing.T) {
142142
t.Fatalf("timeout while waiting for manager update")
143143
}
144144
capacity, allocatable, _ = m.GetCapacity()
145-
resourceCapacity, _ = capacity[v1.ResourceName(testResourceName)]
146-
resourceAllocatable, _ = allocatable[v1.ResourceName(testResourceName)]
145+
resourceCapacity = capacity[v1.ResourceName(testResourceName)]
146+
resourceAllocatable = allocatable[v1.ResourceName(testResourceName)]
147147
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
148148
require.Equal(t, int64(1), resourceAllocatable.Value(), "Devices of plugin previously registered should be removed.")
149149
p2.Stop()
@@ -178,8 +178,8 @@ func TestDevicePluginReRegistrationProbeMode(t *testing.T) {
178178
t.FailNow()
179179
}
180180
capacity, allocatable, _ := m.GetCapacity()
181-
resourceCapacity, _ := capacity[v1.ResourceName(testResourceName)]
182-
resourceAllocatable, _ := allocatable[v1.ResourceName(testResourceName)]
181+
resourceCapacity := capacity[v1.ResourceName(testResourceName)]
182+
resourceAllocatable := allocatable[v1.ResourceName(testResourceName)]
183183
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
184184
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
185185

@@ -194,8 +194,8 @@ func TestDevicePluginReRegistrationProbeMode(t *testing.T) {
194194
}
195195

196196
capacity, allocatable, _ = m.GetCapacity()
197-
resourceCapacity, _ = capacity[v1.ResourceName(testResourceName)]
198-
resourceAllocatable, _ = allocatable[v1.ResourceName(testResourceName)]
197+
resourceCapacity = capacity[v1.ResourceName(testResourceName)]
198+
resourceAllocatable = allocatable[v1.ResourceName(testResourceName)]
199199
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
200200
require.Equal(t, int64(2), resourceAllocatable.Value(), "Devices are not updated.")
201201

@@ -211,8 +211,8 @@ func TestDevicePluginReRegistrationProbeMode(t *testing.T) {
211211
}
212212

213213
capacity, allocatable, _ = m.GetCapacity()
214-
resourceCapacity, _ = capacity[v1.ResourceName(testResourceName)]
215-
resourceAllocatable, _ = allocatable[v1.ResourceName(testResourceName)]
214+
resourceCapacity = capacity[v1.ResourceName(testResourceName)]
215+
resourceAllocatable = allocatable[v1.ResourceName(testResourceName)]
216216
require.Equal(t, resourceCapacity.Value(), resourceAllocatable.Value(), "capacity should equal to allocatable")
217217
require.Equal(t, int64(1), resourceAllocatable.Value(), "Devices of previous registered should be removed")
218218
p2.Stop()

pkg/kubelet/cm/topologymanager/topology_manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ func (m *manager) calculateAffinity(pod v1.Pod, container v1.Container) Topology
164164
// Get the TopologyHints from a provider.
165165
hints := provider.GetTopologyHints(pod, container)
166166

167-
// If hints is nil, insert a single, preferred any-socket hint into allProviderHints.
168-
if hints == nil || len(hints) == 0 {
167+
// If hints is empty, insert a single, preferred any-socket hint into allProviderHints.
168+
if len(hints) == 0 {
169169
klog.Infof("[topologymanager] Hint Provider has no preference for socket affinity with any resource")
170170
affinity, _ := socketmask.NewSocketMask()
171171
affinity.Fill()
@@ -294,7 +294,7 @@ func (m *manager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitR
294294
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
295295
result := m.calculateAffinity(*pod, container)
296296
admitPod := m.policy.CanAdmitPodResult(result.Preferred)
297-
if admitPod.Admit == false {
297+
if !admitPod.Admit {
298298
return admitPod
299299
}
300300
c[container.Name] = result

pkg/kubelet/config/config_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ func TestPodUpdateAnnotations(t *testing.T) {
382382
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
383383

384384
pod := CreateValidPod("foo2", "new")
385-
pod.Annotations = make(map[string]string, 0)
385+
pod.Annotations = make(map[string]string)
386386
pod.Annotations["kubernetes.io/blah"] = "blah"
387387

388388
clone := pod.DeepCopy()
@@ -411,7 +411,7 @@ func TestPodUpdateLabels(t *testing.T) {
411411
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)
412412

413413
pod := CreateValidPod("foo2", "new")
414-
pod.Labels = make(map[string]string, 0)
414+
pod.Labels = make(map[string]string)
415415
pod.Labels["key"] = "value"
416416

417417
clone := pod.DeepCopy()
@@ -432,7 +432,7 @@ func TestPodRestore(t *testing.T) {
432432
defer os.RemoveAll(tmpDir)
433433

434434
pod := CreateValidPod("api-server", "kube-default")
435-
pod.Annotations = make(map[string]string, 0)
435+
pod.Annotations = make(map[string]string)
436436
pod.Annotations["kubernetes.io/config.source"] = kubetypes.ApiserverSource
437437
pod.Annotations[core.BootstrapCheckpointAnnotationKey] = "true"
438438

pkg/kubelet/config/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (s *sourceURL) extractFromURL() error {
106106
return fmt.Errorf("zero-length data received from %v", s.url)
107107
}
108108
// Short circuit if the data has not changed since the last time it was read.
109-
if bytes.Compare(data, s.data) == 0 {
109+
if bytes.Equal(data, s.data) {
110110
return nil
111111
}
112112
s.data = data

pkg/kubelet/container/testing/fake_runtime.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ import (
2929
"k8s.io/apimachinery/pkg/types"
3030
"k8s.io/client-go/util/flowcontrol"
3131
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
32-
. "k8s.io/kubernetes/pkg/kubelet/container"
32+
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
3333
"k8s.io/kubernetes/pkg/volume"
3434
)
3535

3636
type FakePod struct {
37-
Pod *Pod
37+
Pod *kubecontainer.Pod
3838
NetnsPath string
3939
}
4040

@@ -44,14 +44,14 @@ type FakeRuntime struct {
4444
CalledFunctions []string
4545
PodList []*FakePod
4646
AllPodList []*FakePod
47-
ImageList []Image
47+
ImageList []kubecontainer.Image
4848
APIPodStatus v1.PodStatus
49-
PodStatus PodStatus
49+
PodStatus kubecontainer.PodStatus
5050
StartedPods []string
5151
KilledPods []string
5252
StartedContainers []string
5353
KilledContainers []string
54-
RuntimeStatus *RuntimeStatus
54+
RuntimeStatus *kubecontainer.RuntimeStatus
5555
VersionInfo string
5656
APIVersionInfo string
5757
RuntimeType string
@@ -66,10 +66,10 @@ type FakeStreamingRuntime struct {
6666
*FakeRuntime
6767
}
6868

69-
var _ StreamingRuntime = &FakeStreamingRuntime{}
69+
var _ kubecontainer.StreamingRuntime = &FakeStreamingRuntime{}
7070

7171
// FakeRuntime should implement Runtime.
72-
var _ Runtime = &FakeRuntime{}
72+
var _ kubecontainer.Runtime = &FakeRuntime{}
7373

7474
type FakeVersion struct {
7575
Version string
@@ -90,18 +90,18 @@ func (fv *FakeVersion) Compare(other string) (int, error) {
9090
}
9191

9292
type podsGetter interface {
93-
GetPods(bool) ([]*Pod, error)
93+
GetPods(bool) ([]*kubecontainer.Pod, error)
9494
}
9595

9696
type FakeRuntimeCache struct {
9797
getter podsGetter
9898
}
9999

100-
func NewFakeRuntimeCache(getter podsGetter) RuntimeCache {
100+
func NewFakeRuntimeCache(getter podsGetter) kubecontainer.RuntimeCache {
101101
return &FakeRuntimeCache{getter}
102102
}
103103

104-
func (f *FakeRuntimeCache) GetPods() ([]*Pod, error) {
104+
func (f *FakeRuntimeCache) GetPods() ([]*kubecontainer.Pod, error) {
105105
return f.getter.GetPods(false)
106106
}
107107

@@ -177,35 +177,35 @@ func (f *FakeRuntime) Type() string {
177177
return f.RuntimeType
178178
}
179179

180-
func (f *FakeRuntime) Version() (Version, error) {
180+
func (f *FakeRuntime) Version() (kubecontainer.Version, error) {
181181
f.Lock()
182182
defer f.Unlock()
183183

184184
f.CalledFunctions = append(f.CalledFunctions, "Version")
185185
return &FakeVersion{Version: f.VersionInfo}, f.Err
186186
}
187187

188-
func (f *FakeRuntime) APIVersion() (Version, error) {
188+
func (f *FakeRuntime) APIVersion() (kubecontainer.Version, error) {
189189
f.Lock()
190190
defer f.Unlock()
191191

192192
f.CalledFunctions = append(f.CalledFunctions, "APIVersion")
193193
return &FakeVersion{Version: f.APIVersionInfo}, f.Err
194194
}
195195

196-
func (f *FakeRuntime) Status() (*RuntimeStatus, error) {
196+
func (f *FakeRuntime) Status() (*kubecontainer.RuntimeStatus, error) {
197197
f.Lock()
198198
defer f.Unlock()
199199

200200
f.CalledFunctions = append(f.CalledFunctions, "Status")
201201
return f.RuntimeStatus, f.StatusErr
202202
}
203203

204-
func (f *FakeRuntime) GetPods(all bool) ([]*Pod, error) {
204+
func (f *FakeRuntime) GetPods(all bool) ([]*kubecontainer.Pod, error) {
205205
f.Lock()
206206
defer f.Unlock()
207207

208-
var pods []*Pod
208+
var pods []*kubecontainer.Pod
209209

210210
f.CalledFunctions = append(f.CalledFunctions, "GetPods")
211211
if all {
@@ -220,7 +220,7 @@ func (f *FakeRuntime) GetPods(all bool) ([]*Pod, error) {
220220
return pods, f.Err
221221
}
222222

223-
func (f *FakeRuntime) SyncPod(pod *v1.Pod, _ *PodStatus, _ []v1.Secret, backOff *flowcontrol.Backoff) (result PodSyncResult) {
223+
func (f *FakeRuntime) SyncPod(pod *v1.Pod, _ *kubecontainer.PodStatus, _ []v1.Secret, backOff *flowcontrol.Backoff) (result kubecontainer.PodSyncResult) {
224224
f.Lock()
225225
defer f.Unlock()
226226

@@ -236,7 +236,7 @@ func (f *FakeRuntime) SyncPod(pod *v1.Pod, _ *PodStatus, _ []v1.Secret, backOff
236236
return
237237
}
238238

239-
func (f *FakeRuntime) KillPod(pod *v1.Pod, runningPod Pod, gracePeriodOverride *int64) error {
239+
func (f *FakeRuntime) KillPod(pod *v1.Pod, runningPod kubecontainer.Pod, gracePeriodOverride *int64) error {
240240
f.Lock()
241241
defer f.Unlock()
242242

@@ -274,7 +274,7 @@ func (f *FakeRuntime) KillContainerInPod(container v1.Container, pod *v1.Pod) er
274274
return f.Err
275275
}
276276

277-
func (f *FakeRuntime) GetPodStatus(uid types.UID, name, namespace string) (*PodStatus, error) {
277+
func (f *FakeRuntime) GetPodStatus(uid types.UID, name, namespace string) (*kubecontainer.PodStatus, error) {
278278
f.Lock()
279279
defer f.Unlock()
280280

@@ -283,23 +283,23 @@ func (f *FakeRuntime) GetPodStatus(uid types.UID, name, namespace string) (*PodS
283283
return &status, f.Err
284284
}
285285

286-
func (f *FakeRuntime) GetContainerLogs(_ context.Context, pod *v1.Pod, containerID ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) (err error) {
286+
func (f *FakeRuntime) GetContainerLogs(_ context.Context, pod *v1.Pod, containerID kubecontainer.ContainerID, logOptions *v1.PodLogOptions, stdout, stderr io.Writer) (err error) {
287287
f.Lock()
288288
defer f.Unlock()
289289

290290
f.CalledFunctions = append(f.CalledFunctions, "GetContainerLogs")
291291
return f.Err
292292
}
293293

294-
func (f *FakeRuntime) PullImage(image ImageSpec, pullSecrets []v1.Secret, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
294+
func (f *FakeRuntime) PullImage(image kubecontainer.ImageSpec, pullSecrets []v1.Secret, podSandboxConfig *runtimeapi.PodSandboxConfig) (string, error) {
295295
f.Lock()
296296
defer f.Unlock()
297297

298298
f.CalledFunctions = append(f.CalledFunctions, "PullImage")
299299
return image.Image, f.Err
300300
}
301301

302-
func (f *FakeRuntime) GetImageRef(image ImageSpec) (string, error) {
302+
func (f *FakeRuntime) GetImageRef(image kubecontainer.ImageSpec) (string, error) {
303303
f.Lock()
304304
defer f.Unlock()
305305

@@ -312,15 +312,15 @@ func (f *FakeRuntime) GetImageRef(image ImageSpec) (string, error) {
312312
return "", f.InspectErr
313313
}
314314

315-
func (f *FakeRuntime) ListImages() ([]Image, error) {
315+
func (f *FakeRuntime) ListImages() ([]kubecontainer.Image, error) {
316316
f.Lock()
317317
defer f.Unlock()
318318

319319
f.CalledFunctions = append(f.CalledFunctions, "ListImages")
320320
return f.ImageList, f.Err
321321
}
322322

323-
func (f *FakeRuntime) RemoveImage(image ImageSpec) error {
323+
func (f *FakeRuntime) RemoveImage(image kubecontainer.ImageSpec) error {
324324
f.Lock()
325325
defer f.Unlock()
326326

@@ -337,39 +337,39 @@ func (f *FakeRuntime) RemoveImage(image ImageSpec) error {
337337
return f.Err
338338
}
339339

340-
func (f *FakeRuntime) GarbageCollect(gcPolicy ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
340+
func (f *FakeRuntime) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
341341
f.Lock()
342342
defer f.Unlock()
343343

344344
f.CalledFunctions = append(f.CalledFunctions, "GarbageCollect")
345345
return f.Err
346346
}
347347

348-
func (f *FakeRuntime) DeleteContainer(containerID ContainerID) error {
348+
func (f *FakeRuntime) DeleteContainer(containerID kubecontainer.ContainerID) error {
349349
f.Lock()
350350
defer f.Unlock()
351351

352352
f.CalledFunctions = append(f.CalledFunctions, "DeleteContainer")
353353
return f.Err
354354
}
355355

356-
func (f *FakeRuntime) ImageStats() (*ImageStats, error) {
356+
func (f *FakeRuntime) ImageStats() (*kubecontainer.ImageStats, error) {
357357
f.Lock()
358358
defer f.Unlock()
359359

360360
f.CalledFunctions = append(f.CalledFunctions, "ImageStats")
361361
return nil, f.Err
362362
}
363363

364-
func (f *FakeStreamingRuntime) GetExec(id ContainerID, cmd []string, stdin, stdout, stderr, tty bool) (*url.URL, error) {
364+
func (f *FakeStreamingRuntime) GetExec(id kubecontainer.ContainerID, cmd []string, stdin, stdout, stderr, tty bool) (*url.URL, error) {
365365
f.Lock()
366366
defer f.Unlock()
367367

368368
f.CalledFunctions = append(f.CalledFunctions, "GetExec")
369369
return &url.URL{Host: FakeHost}, f.Err
370370
}
371371

372-
func (f *FakeStreamingRuntime) GetAttach(id ContainerID, stdin, stdout, stderr, tty bool) (*url.URL, error) {
372+
func (f *FakeStreamingRuntime) GetAttach(id kubecontainer.ContainerID, stdin, stdout, stderr, tty bool) (*url.URL, error) {
373373
f.Lock()
374374
defer f.Unlock()
375375

@@ -391,13 +391,13 @@ type FakeContainerCommandRunner struct {
391391
Err error
392392

393393
// actual values when invoked
394-
ContainerID ContainerID
394+
ContainerID kubecontainer.ContainerID
395395
Cmd []string
396396
}
397397

398-
var _ ContainerCommandRunner = &FakeContainerCommandRunner{}
398+
var _ kubecontainer.ContainerCommandRunner = &FakeContainerCommandRunner{}
399399

400-
func (f *FakeContainerCommandRunner) RunInContainer(containerID ContainerID, cmd []string, timeout time.Duration) ([]byte, error) {
400+
func (f *FakeContainerCommandRunner) RunInContainer(containerID kubecontainer.ContainerID, cmd []string, timeout time.Duration) ([]byte, error) {
401401
// record invoked values
402402
f.ContainerID = containerID
403403
f.Cmd = cmd

0 commit comments

Comments
 (0)