Skip to content

Commit 3b466d1

Browse files
authored
Merge pull request kubernetes#91971 from SergeyKanzhelev/renamesInContainer
fix linter issues for pkg/kubelet/container
2 parents d81ff38 + ee53488 commit 3b466d1

28 files changed

+122
-133
lines changed

pkg/kubelet/container/cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func getTestPodIDAndStatus(numContainers int) (types.UID, *PodStatus) {
4949
status = &PodStatus{ID: id}
5050
}
5151
for i := 0; i < numContainers; i++ {
52-
status.ContainerStatuses = append(status.ContainerStatuses, &ContainerStatus{Name: string(i)})
52+
status.ContainerStatuses = append(status.ContainerStatuses, &Status{Name: string(i)})
5353
}
5454
return id, status
5555
}

pkg/kubelet/container/container_gc.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import (
2323
"k8s.io/klog/v2"
2424
)
2525

26-
// ContainerGCPolicy specifies a policy for garbage collecting containers.
27-
type ContainerGCPolicy struct {
26+
// GCPolicy specifies a policy for garbage collecting containers.
27+
type GCPolicy struct {
2828
// Minimum age at which a container can be garbage collected, zero for no limit.
2929
MinAge time.Duration
3030

@@ -36,10 +36,10 @@ type ContainerGCPolicy struct {
3636
MaxContainers int
3737
}
3838

39-
// ContainerGC manages garbage collection of dead containers.
39+
// GC manages garbage collection of dead containers.
4040
//
4141
// Implementation is thread-compatible.
42-
type ContainerGC interface {
42+
type GC interface {
4343
// Garbage collect containers.
4444
GarbageCollect() error
4545
// Deletes all unused containers, including containers belonging to pods that are terminated but not deleted
@@ -58,14 +58,14 @@ type realContainerGC struct {
5858
runtime Runtime
5959

6060
// Policy for garbage collection.
61-
policy ContainerGCPolicy
61+
policy GCPolicy
6262

6363
// sourcesReadyProvider provides the readiness of kubelet configuration sources.
6464
sourcesReadyProvider SourcesReadyProvider
6565
}
6666

67-
// NewContainerGC creates a new instance of ContainerGC with the specified policy.
68-
func NewContainerGC(runtime Runtime, policy ContainerGCPolicy, sourcesReadyProvider SourcesReadyProvider) (ContainerGC, error) {
67+
// NewContainerGC creates a new instance of GC with the specified policy.
68+
func NewContainerGC(runtime Runtime, policy GCPolicy, sourcesReadyProvider SourcesReadyProvider) (GC, error) {
6969
if policy.MinAge < 0 {
7070
return nil, fmt.Errorf("invalid minimum garbage collection age: %v", policy.MinAge)
7171
}

pkg/kubelet/container/helpers.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ func HashContainer(container *v1.Container) uint64 {
107107
return uint64(hash.Sum32())
108108
}
109109

110-
// EnvVarsToMap constructs a map of environment name to value from a slice
110+
// envVarsToMap constructs a map of environment name to value from a slice
111111
// of env vars.
112-
func EnvVarsToMap(envs []EnvVar) map[string]string {
112+
func envVarsToMap(envs []EnvVar) map[string]string {
113113
result := map[string]string{}
114114
for _, env := range envs {
115115
result[env.Name] = env.Value
116116
}
117117
return result
118118
}
119119

120-
// V1EnvVarsToMap constructs a map of environment name to value from a slice
120+
// v1EnvVarsToMap constructs a map of environment name to value from a slice
121121
// of env vars.
122-
func V1EnvVarsToMap(envs []v1.EnvVar) map[string]string {
122+
func v1EnvVarsToMap(envs []v1.EnvVar) map[string]string {
123123
result := map[string]string{}
124124
for _, env := range envs {
125125
result[env.Name] = env.Value
@@ -132,7 +132,7 @@ func V1EnvVarsToMap(envs []v1.EnvVar) map[string]string {
132132
// container environment definitions. This does *not* include valueFrom substitutions.
133133
// TODO: callers should use ExpandContainerCommandAndArgs with a fully resolved list of environment.
134134
func ExpandContainerCommandOnlyStatic(containerCommand []string, envs []v1.EnvVar) (command []string) {
135-
mapping := expansion.MappingFuncFor(V1EnvVarsToMap(envs))
135+
mapping := expansion.MappingFuncFor(v1EnvVarsToMap(envs))
136136
if len(containerCommand) != 0 {
137137
for _, cmd := range containerCommand {
138138
command = append(command, expansion.Expand(cmd, mapping))
@@ -144,7 +144,7 @@ func ExpandContainerCommandOnlyStatic(containerCommand []string, envs []v1.EnvVa
144144
// ExpandContainerVolumeMounts expands the subpath of the given VolumeMount by replacing variable references with the values of given EnvVar.
145145
func ExpandContainerVolumeMounts(mount v1.VolumeMount, envs []EnvVar) (string, error) {
146146

147-
envmap := EnvVarsToMap(envs)
147+
envmap := envVarsToMap(envs)
148148
missingKeys := sets.NewString()
149149
expanded := expansion.Expand(mount.SubPathExpr, func(key string) string {
150150
value, ok := envmap[key]
@@ -162,7 +162,7 @@ func ExpandContainerVolumeMounts(mount v1.VolumeMount, envs []EnvVar) (string, e
162162

163163
// ExpandContainerCommandAndArgs expands the given Container's command by replacing variable references `with the values of given EnvVar.
164164
func ExpandContainerCommandAndArgs(container *v1.Container, envs []EnvVar) (command []string, args []string) {
165-
mapping := expansion.MappingFuncFor(EnvVarsToMap(envs))
165+
mapping := expansion.MappingFuncFor(envVarsToMap(envs))
166166

167167
if len(container.Command) != 0 {
168168
for _, cmd := range container.Command {
@@ -262,11 +262,11 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
262262
}
263263

264264
// SandboxToContainerState converts runtimeapi.PodSandboxState to
265-
// kubecontainer.ContainerState.
265+
// kubecontainer.State.
266266
// This is only needed because we need to return sandboxes as if they were
267267
// kubecontainer.Containers to avoid substantial changes to PLEG.
268268
// TODO: Remove this once it becomes obsolete.
269-
func SandboxToContainerState(state runtimeapi.PodSandboxState) ContainerState {
269+
func SandboxToContainerState(state runtimeapi.PodSandboxState) State {
270270
switch state {
271271
case runtimeapi.PodSandboxState_SANDBOX_READY:
272272
return ContainerStateRunning

pkg/kubelet/container/helpers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"github.com/google/go-cmp/cmp"
2525
"github.com/stretchr/testify/assert"
2626

27-
"k8s.io/api/core/v1"
27+
v1 "k8s.io/api/core/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
utilfeature "k8s.io/apiserver/pkg/util/feature"
3030
featuregatetesting "k8s.io/component-base/featuregate/testing"
@@ -43,7 +43,7 @@ func TestEnvVarsToMap(t *testing.T) {
4343
},
4444
}
4545

46-
varMap := EnvVarsToMap(vars)
46+
varMap := envVarsToMap(vars)
4747

4848
if e, a := len(vars), len(varMap); e != a {
4949
t.Errorf("Unexpected map length; expected: %d, got %d", e, a)
@@ -414,7 +414,7 @@ func TestShouldContainerBeRestarted(t *testing.T) {
414414
ID: pod.UID,
415415
Name: pod.Name,
416416
Namespace: pod.Namespace,
417-
ContainerStatuses: []*ContainerStatus{
417+
ContainerStatuses: []*Status{
418418
{
419419
Name: "alive",
420420
State: ContainerStateRunning,

pkg/kubelet/container/runtime.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ type Runtime interface {
9494
// If evictNonDeletedPods is set to true, containers and sandboxes belonging to pods
9595
// that are terminated, but not deleted will be evicted. Otherwise, only deleted pods will be GC'd.
9696
// TODO: Revisit this method and make it cleaner.
97-
GarbageCollect(gcPolicy ContainerGCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error
97+
GarbageCollect(gcPolicy GCPolicy, allSourcesReady bool, evictNonDeletedPods bool) error
9898
// Syncs the running pod into the desired pod.
9999
SyncPod(pod *v1.Pod, podStatus *PodStatus, pullSecrets []v1.Secret, backOff *flowcontrol.Backoff) PodSyncResult
100100
// KillPod kills all the containers of a pod. Pod may be nil, running pod must not be.
@@ -147,13 +147,13 @@ type ImageService interface {
147147
ImageStats() (*ImageStats, error)
148148
}
149149

150-
// ContainerAttacher interface allows to attach a container.
151-
type ContainerAttacher interface {
150+
// Attacher interface allows to attach a container.
151+
type Attacher interface {
152152
AttachContainer(id ContainerID, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) (err error)
153153
}
154154

155-
// ContainerCommandRunner interface allows to run command in a container.
156-
type ContainerCommandRunner interface {
155+
// CommandRunner interface allows to run command in a container.
156+
type CommandRunner interface {
157157
// RunInContainer synchronously executes the command in the container, and returns the output.
158158
// If the command completes with a non-0 exit code, a k8s.io/utils/exec.ExitError will be returned.
159159
RunInContainer(id ContainerID, cmd []string, timeout time.Duration) ([]byte, error)
@@ -250,18 +250,18 @@ func (id DockerID) ContainerID() ContainerID {
250250
}
251251
}
252252

253-
// ContainerState represents the state of a container
254-
type ContainerState string
253+
// State represents the state of a container
254+
type State string
255255

256256
const (
257257
// ContainerStateCreated indicates a container that has been created (e.g. with docker create) but not started.
258-
ContainerStateCreated ContainerState = "created"
258+
ContainerStateCreated State = "created"
259259
// ContainerStateRunning indicates a currently running container.
260-
ContainerStateRunning ContainerState = "running"
260+
ContainerStateRunning State = "running"
261261
// ContainerStateExited indicates a container that ran and completed ("stopped" in other contexts, although a created container is technically also "stopped").
262-
ContainerStateExited ContainerState = "exited"
262+
ContainerStateExited State = "exited"
263263
// ContainerStateUnknown encompasses all the states that we currently don't care about (like restarting, paused, dead).
264-
ContainerStateUnknown ContainerState = "unknown"
264+
ContainerStateUnknown State = "unknown"
265265
)
266266

267267
// Container provides the runtime information for a container, such as ID, hash,
@@ -282,7 +282,7 @@ type Container struct {
282282
// not managed by kubelet.
283283
Hash uint64
284284
// State is the state of the container.
285-
State ContainerState
285+
State State
286286
}
287287

288288
// PodStatus represents the status of the pod and its containers.
@@ -297,20 +297,20 @@ type PodStatus struct {
297297
// All IPs assigned to this pod
298298
IPs []string
299299
// Status of containers in the pod.
300-
ContainerStatuses []*ContainerStatus
300+
ContainerStatuses []*Status
301301
// Status of the pod sandbox.
302302
// Only for kuberuntime now, other runtime may keep it nil.
303303
SandboxStatuses []*runtimeapi.PodSandboxStatus
304304
}
305305

306-
// ContainerStatus represents the status of a container.
307-
type ContainerStatus struct {
306+
// Status represents the status of a container.
307+
type Status struct {
308308
// ID of the container.
309309
ID ContainerID
310310
// Name of the container.
311311
Name string
312312
// Status of the container.
313-
State ContainerState
313+
State State
314314
// Creation time of the container.
315315
CreatedAt time.Time
316316
// Start time of the container.
@@ -337,7 +337,7 @@ type ContainerStatus struct {
337337

338338
// FindContainerStatusByName returns container status in the pod status with the given name.
339339
// When there are multiple containers' statuses with the same name, the first match will be returned.
340-
func (podStatus *PodStatus) FindContainerStatusByName(containerName string) *ContainerStatus {
340+
func (podStatus *PodStatus) FindContainerStatusByName(containerName string) *Status {
341341
for _, containerStatus := range podStatus.ContainerStatuses {
342342
if containerStatus.Name == containerName {
343343
return containerStatus
@@ -347,8 +347,8 @@ func (podStatus *PodStatus) FindContainerStatusByName(containerName string) *Con
347347
}
348348

349349
// GetRunningContainerStatuses returns container status of all the running containers in a pod
350-
func (podStatus *PodStatus) GetRunningContainerStatuses() []*ContainerStatus {
351-
runningContainerStatuses := []*ContainerStatus{}
350+
func (podStatus *PodStatus) GetRunningContainerStatuses() []*Status {
351+
runningContainerStatuses := []*Status{}
352352
for _, containerStatus := range podStatus.ContainerStatuses {
353353
if containerStatus.State == ContainerStateRunning {
354354
runningContainerStatuses = append(runningContainerStatuses, containerStatus)
@@ -643,7 +643,7 @@ func ParsePodFullName(podFullName string) (string, string, error) {
643643
type Option func(Runtime)
644644

645645
// SortContainerStatusesByCreationTime sorts the container statuses by creation time.
646-
type SortContainerStatusesByCreationTime []*ContainerStatus
646+
type SortContainerStatusesByCreationTime []*Status
647647

648648
func (s SortContainerStatusesByCreationTime) Len() int { return len(s) }
649649
func (s SortContainerStatusesByCreationTime) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

pkg/kubelet/container/sync_result.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ var (
3939
ErrRunContainer = errors.New("RunContainerError")
4040
// ErrKillContainer returned when runtime failed to kill any of pod's containers.
4141
ErrKillContainer = errors.New("KillContainerError")
42-
// ErrVerifyNonRoot returned if the container or image will run as the root user.
43-
ErrVerifyNonRoot = errors.New("VerifyNonRootError")
44-
// ErrRunInitContainer returned when container init failed.
45-
ErrRunInitContainer = errors.New("RunInitContainerError")
4642
// ErrCreatePodSandbox returned when runtime failed to create a sandbox for pod.
4743
ErrCreatePodSandbox = errors.New("CreatePodSandboxError")
4844
// ErrConfigPodSandbox returned when runetime failed to get pod sandbox config from pod.
@@ -51,13 +47,6 @@ var (
5147
ErrKillPodSandbox = errors.New("KillPodSandboxError")
5248
)
5349

54-
var (
55-
// ErrSetupNetwork returned when network setup failed.
56-
ErrSetupNetwork = errors.New("SetupNetworkError")
57-
// ErrTeardownNetwork returned when network tear down failed.
58-
ErrTeardownNetwork = errors.New("TeardownNetworkError")
59-
)
60-
6150
// SyncAction indicates different kind of actions in SyncPod() and KillPod(). Now there are only actions
6251
// about start/kill container and setup/teardown network.
6352
type SyncAction string

pkg/kubelet/container/testing/fake_runtime.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (f *FakeRuntime) RemoveImage(image kubecontainer.ImageSpec) error {
348348
return f.Err
349349
}
350350

351-
func (f *FakeRuntime) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
351+
func (f *FakeRuntime) GarbageCollect(gcPolicy kubecontainer.GCPolicy, ready bool, evictNonDeletedPods bool) error {
352352
f.Lock()
353353
defer f.Unlock()
354354

@@ -406,7 +406,7 @@ type FakeContainerCommandRunner struct {
406406
Cmd []string
407407
}
408408

409-
var _ kubecontainer.ContainerCommandRunner = &FakeContainerCommandRunner{}
409+
var _ kubecontainer.CommandRunner = &FakeContainerCommandRunner{}
410410

411411
func (f *FakeContainerCommandRunner) RunInContainer(containerID kubecontainer.ContainerID, cmd []string, timeout time.Duration) ([]byte, error) {
412412
// record invoked values

pkg/kubelet/container/testing/runtime_mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (r *Mock) PortForward(pod *kubecontainer.Pod, port uint16, stream io.ReadWr
137137
return args.Error(0)
138138
}
139139

140-
func (r *Mock) GarbageCollect(gcPolicy kubecontainer.ContainerGCPolicy, ready bool, evictNonDeletedPods bool) error {
140+
func (r *Mock) GarbageCollect(gcPolicy kubecontainer.GCPolicy, ready bool, evictNonDeletedPods bool) error {
141141
args := r.Called(gcPolicy, ready, evictNonDeletedPods)
142142
return args.Error(0)
143143
}

pkg/kubelet/kubelet.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func NewMainKubelet(kubeCfg *kubeletconfiginternal.KubeletConfiguration,
405405
}
406406
}
407407

408-
containerGCPolicy := kubecontainer.ContainerGCPolicy{
408+
containerGCPolicy := kubecontainer.GCPolicy{
409409
MinAge: minimumGCAge.Duration,
410410
MaxPerPodContainer: int(maxPerPodContainerCount),
411411
MaxContainers: int(maxContainerCount),
@@ -870,7 +870,7 @@ type Kubelet struct {
870870
// Optional, defaults to /logs/ from /var/log
871871
logServer http.Handler
872872
// Optional, defaults to simple Docker implementation
873-
runner kubecontainer.ContainerCommandRunner
873+
runner kubecontainer.CommandRunner
874874

875875
// cAdvisor used for container information.
876876
cadvisor cadvisor.Interface
@@ -921,7 +921,7 @@ type Kubelet struct {
921921
recorder record.EventRecorder
922922

923923
// Policy for handling garbage collection of dead containers.
924-
containerGC kubecontainer.ContainerGC
924+
containerGC kubecontainer.GC
925925

926926
// Manager for image garbage collection.
927927
imageManager images.ImageGCManager

pkg/kubelet/kubelet_pods.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,7 @@ func (kl *Kubelet) convertStatusToAPIStatus(pod *v1.Pod, podStatus *kubecontaine
14891489
// convertToAPIContainerStatuses converts the given internal container
14901490
// statuses into API container statuses.
14911491
func (kl *Kubelet) convertToAPIContainerStatuses(pod *v1.Pod, podStatus *kubecontainer.PodStatus, previousStatus []v1.ContainerStatus, containers []v1.Container, hasInitContainers, isInitContainer bool) []v1.ContainerStatus {
1492-
convertContainerStatus := func(cs *kubecontainer.ContainerStatus) *v1.ContainerStatus {
1492+
convertContainerStatus := func(cs *kubecontainer.Status) *v1.ContainerStatus {
14931493
cid := cs.ID.String()
14941494
status := &v1.ContainerStatus{
14951495
Name: cs.Name,

0 commit comments

Comments
 (0)