mirror of
https://github.com/containerd/containerd.git
synced 2026-11-06 05:17:02 +00:00
Remove loop variable copies
Signed-off-by: Austin Vazquez <macedonv@amazon.com>
This commit is contained in:
70 files changed
+1
-125
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
||||
linters:
|
||||
enable:
|
||||
- depguard # Checks for dependencies that should not be (re)introduced. See "linter-settings" for further details.
|
||||
# - copyloopvar # Checks for loop variable copies in Go 1.22+
|
||||
- copyloopvar # Checks for loop variable copies in Go 1.22+
|
||||
- gofmt
|
||||
- goimports
|
||||
- gosec
|
||||
|
||||
@@ -181,7 +181,6 @@ func containerFromProto(containerpb *containersapi.Container) containers.Contain
|
||||
}
|
||||
extensions := make(map[string]typeurl.Any)
|
||||
for k, v := range containerpb.Extensions {
|
||||
v := v
|
||||
extensions[k] = v
|
||||
}
|
||||
return containers.Container{
|
||||
@@ -203,7 +202,6 @@ func containersFromProto(containerspb []*containersapi.Container) []containers.C
|
||||
var containers []containers.Container
|
||||
|
||||
for _, container := range containerspb {
|
||||
container := container
|
||||
containers = append(containers, containerFromProto(container))
|
||||
}
|
||||
|
||||
|
||||
@@ -142,7 +142,6 @@ func imagesFromProto(imagespb []*imagesapi.Image) []images.Image {
|
||||
var images []images.Image
|
||||
|
||||
for _, image := range imagespb {
|
||||
image := image
|
||||
images = append(images, imageFromProto(image))
|
||||
}
|
||||
|
||||
|
||||
@@ -172,7 +172,6 @@ func TestCopy(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testcase := range testcases {
|
||||
testcase := testcase
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
err := Copy(context.Background(),
|
||||
&testcase.writer,
|
||||
|
||||
@@ -165,8 +165,6 @@ func (c *defaultConverter) convertManifest(ctx context.Context, cs content.Store
|
||||
var mu sync.Mutex
|
||||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
for i, l := range manifest.Layers {
|
||||
i := i
|
||||
l := l
|
||||
oldDiffID, err := images.GetDiffID(ctx, cs, l)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -249,8 +247,6 @@ func (c *defaultConverter) convertIndex(ctx context.Context, cs content.Store, d
|
||||
var mu sync.Mutex
|
||||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
for i, mani := range index.Manifests {
|
||||
i := i
|
||||
mani := mani
|
||||
labelKey := fmt.Sprintf("containerd.io/gc.ref.content.m.%d", i)
|
||||
eg.Go(func() error {
|
||||
if mani.Platform != nil && !c.platformMC.Match(*mani.Platform) {
|
||||
|
||||
@@ -154,8 +154,6 @@ func WalkNotEmpty(ctx context.Context, handler Handler, descs ...ocispec.Descrip
|
||||
func Dispatch(ctx context.Context, handler Handler, limiter *semaphore.Weighted, descs ...ocispec.Descriptor) error {
|
||||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
for _, desc := range descs {
|
||||
desc := desc
|
||||
|
||||
if limiter != nil {
|
||||
if err := limiter.Acquire(ctx, 1); err != nil {
|
||||
return err
|
||||
|
||||
@@ -72,7 +72,6 @@ func TestUsageCalculation(t *testing.T) {
|
||||
},
|
||||
// TODO: Add test with snapshot
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
ctx := logtest.WithT(context.Background(), t)
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@ func TestWithLabels(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
lease := newLease(tc.initialLabels)
|
||||
err := WithLabels(tc.labels)(lease)
|
||||
@@ -66,7 +65,6 @@ func TestWithLabels(t *testing.T) {
|
||||
})
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
tc := tc
|
||||
t.Run(tc.name+"-WithLabel", func(t *testing.T) {
|
||||
lease := newLease(tc.initialLabels)
|
||||
for k, v := range tc.labels {
|
||||
|
||||
@@ -148,7 +148,6 @@ func TestContainersList(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
result := result
|
||||
checkContainersEqual(t, &result, testset[result.ID], "list results did not match")
|
||||
}
|
||||
})
|
||||
@@ -618,7 +617,6 @@ func TestContainersCreateUpdateDelete(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
testcase := testcase
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
testcase.original.ID = testcase.name
|
||||
if testcase.input.ID == "" {
|
||||
|
||||
@@ -171,7 +171,6 @@ func startGCContext(ctx context.Context, collectors map[gc.ResourceType]Collecto
|
||||
if len(collectors) > 0 {
|
||||
contexts = map[gc.ResourceType]CollectionContext{}
|
||||
for rt, collector := range collectors {
|
||||
rt := rt
|
||||
c, err := collector.StartCollection(ctx)
|
||||
if err != nil {
|
||||
// Only skipping this resource this round
|
||||
|
||||
@@ -128,7 +128,6 @@ func TestImagesList(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, result := range results {
|
||||
result := result
|
||||
checkImagesEqual(t, &result, testset[result.Name], "list results did not match")
|
||||
}
|
||||
})
|
||||
@@ -531,7 +530,6 @@ func TestImagesCreateUpdateDelete(t *testing.T) {
|
||||
cause: errdefs.ErrNotFound,
|
||||
},
|
||||
} {
|
||||
testcase := testcase
|
||||
t.Run(testcase.name, func(t *testing.T) {
|
||||
testcase.original.Name = testcase.name
|
||||
if testcase.input.Name == "" {
|
||||
|
||||
@@ -99,7 +99,6 @@ func (o *oomCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
o.mu.Lock()
|
||||
defer o.mu.Unlock()
|
||||
for _, t := range o.set {
|
||||
t := t
|
||||
c := atomic.LoadInt64(&t.count)
|
||||
ch <- prometheus.MustNewConstMetric(o.desc, prometheus.CounterValue, float64(c), t.id, t.namespace)
|
||||
}
|
||||
|
||||
@@ -207,7 +207,6 @@ func TestContentEncoding(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.encodingHeader, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
content := make([]byte, 128)
|
||||
|
||||
@@ -525,7 +525,6 @@ func Test_dockerPusher_push(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
desc := ocispec.Descriptor{
|
||||
MediaType: test.args.mediatype,
|
||||
|
||||
@@ -53,7 +53,6 @@ func FromProto(sandboxpb *types.Sandbox) Sandbox {
|
||||
|
||||
extensions := make(map[string]typeurl.Any)
|
||||
for k, v := range sandboxpb.Extensions {
|
||||
v := v
|
||||
extensions[k] = v
|
||||
}
|
||||
|
||||
|
||||
@@ -198,7 +198,6 @@ func TestStore(t *testing.T) {
|
||||
Images: []string{"registry.test/index:latest"},
|
||||
},
|
||||
} {
|
||||
testCase := testCase
|
||||
for _, a := range testCase.Annotations {
|
||||
name := testCase.Name + "_" + a
|
||||
dgst := digest.Canonical.FromString(name)
|
||||
|
||||
@@ -128,7 +128,6 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima
|
||||
}
|
||||
|
||||
for _, desc := range descriptors {
|
||||
desc := desc
|
||||
imgs, err := is.Store(ctx, desc, ts.images)
|
||||
if err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
|
||||
@@ -120,7 +120,6 @@ func TestGetSupportedPlatform(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
testCase := testCase
|
||||
t.Run(testCase.Name, func(t *testing.T) {
|
||||
m, sp := getSupportedPlatform(testCase.UnpackConfig, testCase.SupportedPlatforms)
|
||||
|
||||
|
||||
@@ -453,7 +453,6 @@ func (u *Unpacker) fetch(ctx context.Context, h images.Handler, layers []ocispec
|
||||
tracing.Attribute("layer.media.size", desc.Size),
|
||||
tracing.Attribute("layer.media.digest", desc.Digest.String()),
|
||||
)
|
||||
desc := desc
|
||||
var ch chan struct{}
|
||||
if done != nil {
|
||||
ch = done[i]
|
||||
|
||||
@@ -80,7 +80,6 @@ func TestAdditionalGids(t *testing.T) {
|
||||
}
|
||||
|
||||
for i, tc := range testCases {
|
||||
i, tc := i, tc
|
||||
tBasename := fmt.Sprintf("case-%d", i)
|
||||
t.Run(tBasename, func(t *testing.T) {
|
||||
t.Log(tc.description)
|
||||
|
||||
@@ -1583,7 +1583,6 @@ func TestIssue9103(t *testing.T) {
|
||||
expectedStatus: Stopped,
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
tName := fmt.Sprintf("%s%d", id, idx)
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
container, err := client.NewContainer(ctx, tName,
|
||||
|
||||
@@ -234,7 +234,6 @@ func TestExportAllCases(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := testContext(t)
|
||||
|
||||
@@ -674,7 +674,6 @@ func TestTransferImport(t *testing.T) {
|
||||
Opts: []image.StoreOpt{image.WithDigestRef("registry.test/basename", true, false)},
|
||||
},
|
||||
} {
|
||||
testCase := testCase
|
||||
t.Run(testCase.Name, func(t *testing.T) {
|
||||
tc := tartest.TarContext{}
|
||||
files := []tartest.WriterToTar{
|
||||
|
||||
@@ -79,7 +79,6 @@ func TestMigration(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range migrationTests {
|
||||
tc := tc
|
||||
t.Run(tc.Name, func(t *testing.T) {
|
||||
buf := bytes.NewBuffer(nil)
|
||||
cmd := exec.Command("containerd", "-c", tc.File, "config", "migrate")
|
||||
|
||||
@@ -82,7 +82,6 @@ func TestContainerSymlinkVolumes(t *testing.T) {
|
||||
createFileFn: symlinkedFileInSymlinkedFolder,
|
||||
},
|
||||
} {
|
||||
testCase := testCase // capture range variable
|
||||
t.Run(name, func(t *testing.T) {
|
||||
testPodLogDir := t.TempDir()
|
||||
testVolDir := t.TempDir()
|
||||
|
||||
@@ -487,7 +487,6 @@ func ValidateImageConfig(ctx context.Context, c *ImageConfig) ([]deprecation.War
|
||||
c.Registry.Configs = make(map[string]RegistryConfig)
|
||||
}
|
||||
for endpoint, auth := range c.Registry.Auths {
|
||||
auth := auth
|
||||
u, err := url.Parse(endpoint)
|
||||
if err != nil {
|
||||
return warnings, fmt.Errorf("failed to parse registry url %q from `registry.auths`: %w", endpoint, err)
|
||||
|
||||
@@ -299,7 +299,6 @@ func TestHostAccessingSandbox(t *testing.T) {
|
||||
{"Security Context namespace host access", hostNamespace, true},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := hostAccessingSandbox(tt.config); got != tt.want {
|
||||
t.Errorf("hostAccessingSandbox() = %v, want %v", got, tt.want)
|
||||
|
||||
@@ -116,7 +116,6 @@ func TestValidateStreamServer(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
tlsMode, err := getStreamListenerMode(&test.config)
|
||||
if test.expectErr {
|
||||
|
||||
@@ -394,7 +394,6 @@ func (a *API) ListContainers() []nri.Container {
|
||||
case cri.ContainerState_CONTAINER_UNKNOWN:
|
||||
continue
|
||||
}
|
||||
ctr := ctr
|
||||
containers = append(containers, a.nriContainer(&ctr, nil))
|
||||
}
|
||||
return containers
|
||||
|
||||
@@ -175,7 +175,6 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
}
|
||||
var runtimeHandler *runtime.RuntimeHandler
|
||||
for _, f := range c.runtimeHandlers {
|
||||
f := f
|
||||
if f.Name == sandbox.Metadata.RuntimeHandler {
|
||||
runtimeHandler = f
|
||||
break
|
||||
|
||||
@@ -247,7 +247,6 @@ func TestContainerCapabilities(t *testing.T) {
|
||||
excludes: util.SubtractStringSlice(allCaps, "CAP_SYS_ADMIN"),
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||
ociRuntime := config.Runtime{}
|
||||
@@ -429,7 +428,6 @@ func TestContainerAndSandboxPrivileged(t *testing.T) {
|
||||
expectError: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Linux.SecurityContext.Privileged = test.containerPrivileged
|
||||
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||
@@ -471,7 +469,6 @@ func TestPrivilegedBindMount(t *testing.T) {
|
||||
expectedCgroupFSRO: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||
sandboxConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||
@@ -588,7 +585,6 @@ func TestMountPropagation(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
c.os.(*ostesting.FakeOS).LookupMountFn = test.fakeLookupMountFn
|
||||
@@ -645,7 +641,6 @@ func TestPidNamespace(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{Pid: test.pidNS}
|
||||
spec, err := c.buildContainerSpec(currentPlatform, testID, testSandboxID, testPid, "", testContainerName, testImageName, containerConfig, sandboxConfig, imageConfig, nil, ociRuntime, nil)
|
||||
@@ -811,7 +806,6 @@ func TestUserNamespace(t *testing.T) {
|
||||
err: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Linux.SecurityContext.NamespaceOptions = &runtime.NamespaceOption{UsernsOptions: test.userNS}
|
||||
// By default, set sandbox and container config to the same (this is
|
||||
@@ -991,7 +985,6 @@ func TestGenerateSeccompSecurityProfileSpecOpts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
cri := &criService{}
|
||||
cri.config.UnsetSeccompProfile = test.defaultProfile
|
||||
@@ -1167,7 +1160,6 @@ func TestGenerateApparmorSpecOpts(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
asp := test.sp
|
||||
csp, err := generateApparmorSecurityProfile(test.profile)
|
||||
@@ -1273,7 +1265,6 @@ func TestMaskedAndReadonlyPaths(t *testing.T) {
|
||||
privileged: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c.config.DisableProcMount = test.disableProcMount
|
||||
containerConfig.Linux.SecurityContext.MaskedPaths = test.masked
|
||||
@@ -1329,7 +1320,6 @@ func TestHostname(t *testing.T) {
|
||||
expectedEnv: "HOSTNAME=real-hostname",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
sandboxConfig.Hostname = test.hostname
|
||||
sandboxConfig.Linux.SecurityContext = &runtime.LinuxSandboxSecurityContext{
|
||||
@@ -1510,7 +1500,6 @@ additional-group-for-root:x:22222:root
|
||||
expected: runtimespec.User{UID: 1000, GID: 2000, AdditionalGids: []uint32{2000, 3333}},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig, sandboxConfig, imageConfig, _ := getCreateContainerTestData()
|
||||
containerConfig.Linux.SecurityContext = test.securityContext
|
||||
@@ -1579,7 +1568,6 @@ func TestNonRootUserAndDevices(t *testing.T) {
|
||||
expectedDeviceGID: *testDevice.GID,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c.config.DeviceOwnershipFromSecurityContext = test.deviceOwnershipFromSecurityContext
|
||||
containerConfig.Linux.SecurityContext.RunAsUser = test.uid
|
||||
@@ -1657,7 +1645,6 @@ func TestPrivilegedDevices(t *testing.T) {
|
||||
expectAllDevicesAllowed: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||
sandboxConfig.Linux.SecurityContext.Privileged = test.privileged
|
||||
|
||||
@@ -135,7 +135,6 @@ func TestPodAnnotationPassthroughContainerSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||
@@ -209,7 +208,6 @@ func TestContainerSpecCommand(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config, _, imageConfig, _ := getCreateContainerTestData()
|
||||
config.Command = test.criEntrypoint
|
||||
@@ -351,7 +349,6 @@ func TestVolumeMounts(t *testing.T) {
|
||||
expectedMappings: idmap,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := &imagespec.ImageConfig{
|
||||
Volumes: test.imageVolumes,
|
||||
@@ -497,7 +494,6 @@ func TestContainerAnnotationPassthroughContainerSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
containerConfig, sandboxConfig, imageConfig, specCheck := getCreateContainerTestData()
|
||||
@@ -750,7 +746,6 @@ func TestLinuxContainerMounts(t *testing.T) {
|
||||
expectedMounts: nil,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := &runtime.ContainerConfig{
|
||||
Metadata: &runtime.ContainerMetadata{
|
||||
|
||||
@@ -245,7 +245,6 @@ func TestHostProcessRequirements(t *testing.T) {
|
||||
expectError: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
containerConfig.Windows.SecurityContext.HostProcess = test.containerHostProcess
|
||||
sandboxConfig.Windows.SecurityContext = &runtime.WindowsSandboxSecurityContext{
|
||||
|
||||
@@ -157,7 +157,6 @@ func TestFilterContainers(t *testing.T) {
|
||||
expect: []*runtime.Container{testContainers[2]},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
filtered := c.filterCRIContainers(testContainers, test.filter)
|
||||
assert.Equal(t, test.expect, filtered, test.desc)
|
||||
@@ -351,7 +350,6 @@ func TestListContainers(t *testing.T) {
|
||||
expect: expectedContainers[:1],
|
||||
},
|
||||
} {
|
||||
testdata := testdata
|
||||
t.Run(testdata.desc, func(t *testing.T) {
|
||||
resp, err := c.ListContainers(context.Background(), &runtime.ListContainersRequest{Filter: testdata.filter})
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -70,7 +70,6 @@ func TestSetContainerRemoving(t *testing.T) {
|
||||
expectErr: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
container, err := containerstore.NewContainer(
|
||||
containerstore.Metadata{ID: testID},
|
||||
|
||||
@@ -84,7 +84,6 @@ func TestSetContainerStarting(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
container, err := containerstore.NewContainer(
|
||||
containerstore.Metadata{ID: testID},
|
||||
|
||||
@@ -68,7 +68,6 @@ func TestContainerMetricsCPUNanoCoreUsage(t *testing.T) {
|
||||
expectedNanoCoreUsageSecond: 0,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
container, err := containerstore.NewContainer(
|
||||
containerstore.Metadata{ID: test.id},
|
||||
@@ -126,7 +125,6 @@ func TestGetWorkingSet(t *testing.T) {
|
||||
expected: 0,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := getWorkingSet(test.memory)
|
||||
assert.Equal(t, test.expected, got)
|
||||
@@ -162,7 +160,6 @@ func TestGetWorkingSetV2(t *testing.T) {
|
||||
expected: 0,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := getWorkingSetV2(test.memory)
|
||||
assert.Equal(t, test.expected, got)
|
||||
@@ -200,7 +197,6 @@ func TestGetAvailableBytes(t *testing.T) {
|
||||
expected: 5000 - 500,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := getAvailableBytes(test.memory, test.workingSetBytes)
|
||||
assert.Equal(t, test.expected, got)
|
||||
@@ -234,7 +230,6 @@ func TestGetAvailableBytesV2(t *testing.T) {
|
||||
expected: 5000 - 500,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := getAvailableBytesV2(test.memory, test.workingSetBytes)
|
||||
assert.Equal(t, test.expected, got)
|
||||
@@ -342,7 +337,6 @@ func TestContainerMetricsMemory(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got, err := c.memoryContainerStats("ID", test.metrics, timestamp)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -145,7 +145,6 @@ func TestToCRIContainerStatus(t *testing.T) {
|
||||
expectedReason: errorExitReason,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
|
||||
metadata, ctnr, status, _, expected := getContainerStatusTestData(t)
|
||||
@@ -240,7 +239,6 @@ func TestContainerStatus(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
metadata, ctnr, status, image, expected := getContainerStatusTestData(t)
|
||||
|
||||
@@ -65,7 +65,6 @@ func TestWaitContainerStop(t *testing.T) {
|
||||
expectErr: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
container, err := containerstore.NewContainer(
|
||||
|
||||
@@ -236,7 +236,6 @@ func TestUpdateOCILinuxResource(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
config := criconfig.Config{
|
||||
RuntimeConfig: criconfig.RuntimeConfig{
|
||||
|
||||
@@ -79,7 +79,6 @@ func TestGetUserFromImage(t *testing.T) {
|
||||
name: "test",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
actualUID, actualName := getUserFromImage(test.user)
|
||||
assert.Equal(t, test.uid, actualUID)
|
||||
@@ -148,7 +147,6 @@ systemd_cgroup = true
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
opts, err := criconfig.GenerateRuntimeOptions(test.r)
|
||||
assert.NoError(t, err)
|
||||
@@ -221,7 +219,6 @@ func TestEnvDeduplication(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
var spec runtimespec.Spec
|
||||
if len(test.existing) > 0 {
|
||||
@@ -344,7 +341,6 @@ func TestValidateTargetContainer(t *testing.T) {
|
||||
expectError: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
targetContainer, err := c.validateTargetContainer(testSandboxID, test.targetContainerID)
|
||||
if test.expectError {
|
||||
@@ -408,7 +404,6 @@ func TestHostNetwork(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if hostNetwork(tt.c) != tt.expected {
|
||||
t.Errorf("failed hostNetwork got %t expected %t", hostNetwork(tt.c), tt.expected)
|
||||
|
||||
@@ -41,7 +41,6 @@ func (c *CRIImageService) CheckImages(ctx context.Context) error {
|
||||
var wg sync.WaitGroup
|
||||
for _, i := range cImages {
|
||||
wg.Add(1)
|
||||
i := i
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
// TODO: Check platform/snapshot combination. Snapshot check should come first
|
||||
|
||||
@@ -113,7 +113,6 @@ func TestParseAuth(t *testing.T) {
|
||||
expectedSecret: testPasswd,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
u, s, err := ParseAuth(test.auth, test.host)
|
||||
assert.Equal(t, test.expectErr, err != nil)
|
||||
@@ -272,7 +271,6 @@ func TestRegistryEndpoints(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c, _ := newTestCRIService()
|
||||
c.config.Registry.Mirrors = test.mirrors
|
||||
@@ -340,7 +338,6 @@ func TestDefaultScheme(t *testing.T) {
|
||||
expected: "https",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := defaultScheme(test.host)
|
||||
assert.Equal(t, test.expected, got)
|
||||
@@ -366,7 +363,6 @@ func TestEncryptedImagePullOpts(t *testing.T) {
|
||||
expectedOpts: 0,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c, _ := newTestCRIService()
|
||||
c.config.ImageDecryption.KeyModel = test.keyModel
|
||||
|
||||
@@ -112,7 +112,6 @@ func TestGetUserFromImage(t *testing.T) {
|
||||
name: "test",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
actualUID, actualName := getUserFromImage(test.user)
|
||||
assert.Equal(t, test.uid, actualUID)
|
||||
|
||||
@@ -119,7 +119,6 @@ func TestRuntimeSnapshotter(t *testing.T) {
|
||||
expectSnapshotter: "devmapper",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
cri, _ := newTestCRIService()
|
||||
cri.config = criconfig.DefaultImageConfig()
|
||||
|
||||
@@ -60,7 +60,6 @@ func TestGetCgroupsPath(t *testing.T) {
|
||||
expected: "/test-id",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
got := getCgroupsPath(test.cgroupsParent, testID)
|
||||
assert.Equal(t, test.expected, got)
|
||||
|
||||
@@ -86,7 +86,6 @@ func TestInitSelinuxOpts(t *testing.T) {
|
||||
expectErr: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
processLabel, mountLabel, err := initLabelsFromOpt(test.selinuxOpt)
|
||||
if test.expectErr {
|
||||
@@ -167,7 +166,6 @@ func TestCheckSelinuxLevel(t *testing.T) {
|
||||
expectNoMatch: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
err := checkSelinuxLevel(test.level)
|
||||
if test.expectNoMatch {
|
||||
|
||||
@@ -90,7 +90,6 @@ func TestEnvDeduplication(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
var spec runtimespec.Spec
|
||||
if len(test.existing) > 0 {
|
||||
|
||||
@@ -422,7 +422,6 @@ func TestLinuxSandboxContainerSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newControllerService()
|
||||
c.config.RootDir = t.TempDir()
|
||||
@@ -704,7 +703,6 @@ options timeout:1
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newControllerService()
|
||||
c.os.(*ostesting.FakeOS).HostnameFn = func() (string, error) {
|
||||
@@ -778,7 +776,6 @@ options timeout:1
|
||||
`,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
resolvContent, err := parseDNSOptions(test.servers, test.searches, test.options)
|
||||
if test.expectErr {
|
||||
|
||||
@@ -100,7 +100,6 @@ func TestSandboxContainerSpec(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newControllerService()
|
||||
config, imageConfig, specCheck := getRunPodSandboxTestData(c.config)
|
||||
@@ -153,7 +152,6 @@ func TestTypeurlMarshalUnmarshalSandboxMeta(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
meta := &sandboxstore.Metadata{
|
||||
ID: "1",
|
||||
|
||||
@@ -69,7 +69,6 @@ func (c *criService) recover(ctx context.Context) error {
|
||||
|
||||
eg, ctx2 := errgroup.WithContext(ctx)
|
||||
for _, sandbox := range sandboxes {
|
||||
sandbox := sandbox
|
||||
eg.Go(func() error {
|
||||
sb, err := podSandboxLoader.RecoverContainer(ctx2, sandbox)
|
||||
if err != nil {
|
||||
@@ -150,7 +149,6 @@ func (c *criService) recover(ctx context.Context) error {
|
||||
}
|
||||
|
||||
for _, sb := range c.sandboxStore.List() {
|
||||
sb := sb
|
||||
status := sb.Status.Get()
|
||||
if status.State == sandboxstore.StateNotReady {
|
||||
continue
|
||||
@@ -169,7 +167,6 @@ func (c *criService) recover(ctx context.Context) error {
|
||||
}
|
||||
eg, ctx2 = errgroup.WithContext(ctx)
|
||||
for _, container := range containers {
|
||||
container := container
|
||||
eg.Go(func() error {
|
||||
cntr, err := c.loadContainer(ctx2, container)
|
||||
if err != nil {
|
||||
|
||||
@@ -91,7 +91,6 @@ func TestRuntimeConfig(t *testing.T) {
|
||||
expectedCgroupDriver: runtime.CgroupDriver_SYSTEMD,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
c.config.RuntimeConfig.ContainerdConfig.DefaultRuntimeName = test.defaultRuntime
|
||||
|
||||
@@ -74,7 +74,6 @@ func TestToCRISandbox(t *testing.T) {
|
||||
expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
status := sandboxstore.Status{
|
||||
CreatedAt: createdAt,
|
||||
@@ -216,7 +215,6 @@ func TestFilterSandboxes(t *testing.T) {
|
||||
expect: []*runtime.PodSandbox{testSandboxes[2]},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
filtered := c.filterCRISandboxes(testSandboxes, test.filter)
|
||||
assert.Equal(t, test.expect, filtered, test.desc)
|
||||
|
||||
@@ -122,7 +122,6 @@ func TestToCNIPortMappings(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
assert.Equal(t, test.cniPortMappings, toCNIPortMappings(test.criPortMappings))
|
||||
})
|
||||
@@ -176,7 +175,6 @@ func TestSelectPodIP(t *testing.T) {
|
||||
expectedAdditionalIPs: []string{"2001:db8:85a3::8a2e:370:7334", "2001:db8:85a3::8a2e:370:7335", "192.168.17.45"},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
var ipConfigs []*cni.IPConfig
|
||||
for _, ip := range test.ips {
|
||||
|
||||
@@ -39,7 +39,6 @@ func (c *criService) ListPodSandboxStats(
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for i, sandbox := range sandboxes {
|
||||
i, sandbox := i, sandbox
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -49,7 +49,6 @@ func TestGetUsageNanoCores(t *testing.T) {
|
||||
expectedNanoCoreUsageSecond: 450,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
container, err := containerstore.NewContainer(
|
||||
containerstore.Metadata{ID: ID},
|
||||
@@ -362,7 +361,6 @@ func Test_criService_podSandboxStats(t *testing.T) {
|
||||
expectError: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
actualPodStats, actualContainerStats, err := c.toPodSandboxStats(test.sandbox, test.metrics, test.containers, currentStatsTimestamp)
|
||||
if test.expectError {
|
||||
@@ -567,7 +565,6 @@ func Test_criService_saveSandBoxMetrics(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
c.sandboxStore.Add(sandboxstore.Sandbox{
|
||||
|
||||
@@ -125,7 +125,6 @@ func TestPodSandboxStatus(t *testing.T) {
|
||||
expectedState: runtime.PodSandboxState_SANDBOX_NOTREADY,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
expected.State = test.expectedState
|
||||
got := toCRISandboxStatus(metadata, test.state, createdAt, ip, additionalIPs)
|
||||
|
||||
@@ -55,7 +55,6 @@ func TestWaitSandboxStop(t *testing.T) {
|
||||
expectErr: false,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
c := newTestCRIService()
|
||||
sandbox := sandboxstore.NewSandbox(
|
||||
|
||||
@@ -97,7 +97,6 @@ func TestUpdateRuntimeConfig(t *testing.T) {
|
||||
expectCNIConfig: true,
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
testDir := t.TempDir()
|
||||
templateName := filepath.Join(testDir, "template")
|
||||
|
||||
@@ -76,7 +76,6 @@ func TestGetRepoDigestAndTag(t *testing.T) {
|
||||
expectedRepoTag: "",
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
named, err := reference.ParseDockerRef(test.ref)
|
||||
assert.NoError(t, err)
|
||||
|
||||
@@ -131,7 +131,6 @@ func TestPassThroughAnnotationsFilter(t *testing.T) {
|
||||
},
|
||||
},
|
||||
} {
|
||||
test := test
|
||||
t.Run(test.desc, func(t *testing.T) {
|
||||
passthroughAnnotations := GetPassthroughAnnotations(test.podAnnotations, test.runtimePodAnnotations)
|
||||
assert.Equal(t, test.passthroughAnnotations, passthroughAnnotations)
|
||||
|
||||
@@ -70,7 +70,6 @@ func TestParseRelease(t *testing.T) {
|
||||
{in: "3.-8", expectedErr: fmt.Errorf(`failed to parse kernel version "3.-8": expected integer`)},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.in, func(t *testing.T) {
|
||||
version, err := parseRelease(tc.in)
|
||||
if tc.expectedErr != nil {
|
||||
@@ -129,7 +128,6 @@ func TestGreaterEqualThan(t *testing.T) {
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
tc := tc
|
||||
t.Run(tc.doc+": "+tc.in.String(), func(t *testing.T) {
|
||||
ok, err := GreaterEqualThan(tc.in)
|
||||
if err != nil {
|
||||
|
||||
@@ -71,7 +71,6 @@ guest:x:405:100:guest:/dev/null:/sbin/nologin
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(fmt.Sprintf("user %d", testCase.userID), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Spec{
|
||||
@@ -131,7 +130,6 @@ guest:x:405:100:guest:/dev/null:/sbin/nologin
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.user, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Spec{
|
||||
@@ -201,7 +199,6 @@ sys:x:3:root,bin,adm
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.user, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Spec{
|
||||
@@ -605,7 +602,6 @@ daemon:x:2:root,bin,daemon
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Spec{
|
||||
@@ -663,7 +659,6 @@ func TestWithAppendAdditionalGroupsNoEtcGroup(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
testCase := testCase
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := Spec{
|
||||
|
||||
@@ -587,7 +587,6 @@ func TestDevShmSize(t *testing.T) {
|
||||
|
||||
expected := "1024k"
|
||||
for _, s := range ss {
|
||||
s := s
|
||||
if err := WithDevShmSize(1024)(nil, nil, nil, &s); err != nil {
|
||||
if err != ErrNoShmMount {
|
||||
t.Fatal(err)
|
||||
|
||||
@@ -57,7 +57,6 @@ func TestImageLayersLabel(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
sampleLayers := make([]imagespec.Descriptor, 0, tt.layersNum)
|
||||
for i := 0; i < tt.layersNum; i++ {
|
||||
|
||||
@@ -255,7 +255,6 @@ func BenchmarkIngests(b *testing.B) {
|
||||
512 << 10,
|
||||
1 << 20,
|
||||
} {
|
||||
size := size
|
||||
b.Run(fmt.Sprint(size), func(b *testing.B) {
|
||||
b.StopTimer()
|
||||
blobs := generateBlobs(b, int64(b.N), size)
|
||||
|
||||
@@ -106,7 +106,6 @@ func (m *monitor) reconcile(ctx context.Context) error {
|
||||
}
|
||||
var wgNSLoop sync.WaitGroup
|
||||
for _, name := range ns {
|
||||
name := name
|
||||
wgNSLoop.Add(1)
|
||||
go func() {
|
||||
defer wgNSLoop.Done()
|
||||
@@ -118,7 +117,6 @@ func (m *monitor) reconcile(ctx context.Context) error {
|
||||
}
|
||||
var wgChangesLoop sync.WaitGroup
|
||||
for _, c := range changes {
|
||||
c := c
|
||||
wgChangesLoop.Add(1)
|
||||
go func() {
|
||||
defer wgChangesLoop.Done()
|
||||
|
||||
@@ -28,7 +28,6 @@ func containersToProto(containers []containers.Container) []*api.Container {
|
||||
var containerspb []*api.Container
|
||||
|
||||
for _, image := range containers {
|
||||
image := image
|
||||
containerspb = append(containerspb, containerToProto(&image))
|
||||
}
|
||||
|
||||
@@ -68,7 +67,6 @@ func containerFromProto(containerpb *api.Container) containers.Container {
|
||||
}
|
||||
extensions := make(map[string]typeurl.Any)
|
||||
for k, v := range containerpb.Extensions {
|
||||
v := v
|
||||
extensions[k] = v
|
||||
}
|
||||
return containers.Container{
|
||||
|
||||
@@ -27,7 +27,6 @@ func imagesToProto(images []images.Image) []*imagesapi.Image {
|
||||
var imagespb []*imagesapi.Image
|
||||
|
||||
for _, image := range images {
|
||||
image := image
|
||||
imagespb = append(imagespb, imageToProto(&image))
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,6 @@ func (l *Local) Plugins(ctx context.Context, fs ...string) (*api.PluginsResponse
|
||||
var plugins []*api.Plugin
|
||||
allPlugins := l.getPlugins()
|
||||
for _, p := range allPlugins {
|
||||
p := p
|
||||
if filter.Match(adaptPlugin(p)) {
|
||||
plugins = append(plugins, p)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user