Skip to content

Commit 7910442

Browse files
authored
Merge pull request containerd#3407 from apostasie/chore-lint
Lint for other platforms
2 parents 30c63cf + ca0f645 commit 7910442

28 files changed

+301
-369
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ clean:
7070
lint: lint-go lint-imports lint-yaml lint-shell
7171

7272
lint-go:
73-
cd $(MAKEFILE_DIR) && golangci-lint run $(VERBOSE_FLAG_LONG) ./...
73+
cd $(MAKEFILE_DIR) && GOOS=linux golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
74+
GOOS=windows golangci-lint run $(VERBOSE_FLAG_LONG) ./... && \
75+
GOOS=freebsd golangci-lint run $(VERBOSE_FLAG_LONG) ./...
7476

7577
lint-imports:
7678
cd $(MAKEFILE_DIR) && ./hack/lint-imports.sh

cmd/nerdctl/container/container_cp.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

cmd/nerdctl/container/container_cp_linux.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
package container
1818

1919
import (
20+
"errors"
2021
"fmt"
22+
"path/filepath"
23+
"strings"
2124

2225
"github.com/spf13/cobra"
2326

@@ -131,3 +134,46 @@ func processCpOptions(cmd *cobra.Command, args []string) (types.ContainerCpOptio
131134
func AddCpCommand(rootCmd *cobra.Command) {
132135
rootCmd.AddCommand(newCpCommand())
133136
}
137+
138+
var errFileSpecDoesntMatchFormat = errors.New("filespec must match the canonical format: [container:]file/path")
139+
140+
func parseCpFileSpec(arg string) (*cpFileSpec, error) {
141+
i := strings.Index(arg, ":")
142+
143+
// filespec starting with a semicolon is invalid
144+
if i == 0 {
145+
return nil, errFileSpecDoesntMatchFormat
146+
}
147+
148+
if filepath.IsAbs(arg) {
149+
// Explicit local absolute path, e.g., `C:\foo` or `/foo`.
150+
return &cpFileSpec{
151+
Container: nil,
152+
Path: arg,
153+
}, nil
154+
}
155+
156+
parts := strings.SplitN(arg, ":", 2)
157+
158+
if len(parts) == 1 || strings.HasPrefix(parts[0], ".") {
159+
// Either there's no `:` in the arg
160+
// OR it's an explicit local relative path like `./file:name.txt`.
161+
return &cpFileSpec{
162+
Path: arg,
163+
}, nil
164+
}
165+
166+
return &cpFileSpec{
167+
Container: &parts[0],
168+
Path: parts[1],
169+
}, nil
170+
}
171+
172+
type cpFileSpec struct {
173+
Container *string
174+
Path string
175+
}
176+
177+
func cpShellComplete(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
178+
return nil, cobra.ShellCompDirectiveFilterFileExt
179+
}

cmd/nerdctl/container/container_list_windows_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
type psTestContainer struct {
3333
name string
3434
labels map[string]string
35-
volumes []string
3635
network string
3736
}
3837

cmd/nerdctl/container/container_run_network_base_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"io"
2424
"net"
25-
"regexp"
2625
"strings"
2726
"testing"
2827

@@ -223,28 +222,3 @@ func baseTestRunPort(t *testing.T, nginxImage string, nginxIndexHTMLSnippet stri
223222
}
224223

225224
}
226-
227-
func valuesOfMapStringString(m map[string]string) map[string]struct{} {
228-
res := make(map[string]struct{})
229-
for _, v := range m {
230-
res[v] = struct{}{}
231-
}
232-
return res
233-
}
234-
235-
func extractHostPort(portMapping string, port string) (string, error) {
236-
// Regular expression to extract host port from port mapping information
237-
re := regexp.MustCompile(`(?P<containerPort>\d{1,5})/tcp ->.*?0.0.0.0:(?P<hostPort>\d{1,5}).*?`)
238-
portMappingLines := strings.Split(portMapping, "\n")
239-
for _, portMappingLine := range portMappingLines {
240-
// Find the matches
241-
matches := re.FindStringSubmatch(portMappingLine)
242-
// Check if there is a match
243-
if len(matches) >= 3 && matches[1] == port {
244-
// Extract the host port number
245-
hostPort := matches[2]
246-
return hostPort, nil
247-
}
248-
}
249-
return "", fmt.Errorf("could not extract host port from port mapping: %s", portMapping)
250-
}

cmd/nerdctl/container/container_run_network_linux_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,31 @@ import (
3737
"github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
3838
)
3939

40+
func extractHostPort(portMapping string, port string) (string, error) {
41+
// Regular expression to extract host port from port mapping information
42+
re := regexp.MustCompile(`(?P<containerPort>\d{1,5})/tcp ->.*?0.0.0.0:(?P<hostPort>\d{1,5}).*?`)
43+
portMappingLines := strings.Split(portMapping, "\n")
44+
for _, portMappingLine := range portMappingLines {
45+
// Find the matches
46+
matches := re.FindStringSubmatch(portMappingLine)
47+
// Check if there is a match
48+
if len(matches) >= 3 && matches[1] == port {
49+
// Extract the host port number
50+
hostPort := matches[2]
51+
return hostPort, nil
52+
}
53+
}
54+
return "", fmt.Errorf("could not extract host port from port mapping: %s", portMapping)
55+
}
56+
57+
func valuesOfMapStringString(m map[string]string) map[string]struct{} {
58+
res := make(map[string]struct{})
59+
for _, v := range m {
60+
res[v] = struct{}{}
61+
}
62+
return res
63+
}
64+
4065
// TestRunInternetConnectivity tests Internet connectivity with `apk update`
4166
func TestRunInternetConnectivity(t *testing.T) {
4267
base := testutil.NewBase(t)

cmd/nerdctl/container/container_run_network_windows_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,22 @@ func TestHnsEndpointsExistDuringContainerLifecycle(t *testing.T) {
126126
"tail", "-f",
127127
)
128128
t.Logf("Creating HNS lifecycle test container with command: %q", strings.Join(cmd.Command, " "))
129-
containerId := strings.TrimSpace(cmd.Run().Stdout())
130-
t.Logf("HNS endpoint lifecycle test container ID: %q", containerId)
129+
containerID := strings.TrimSpace(cmd.Run().Stdout())
130+
t.Logf("HNS endpoint lifecycle test container ID: %q", containerID)
131131

132132
// HNS endpoints should be allocated on container creation.
133-
assertHnsEndpointsExistence(t, true, containerId, testNet.Name)
133+
assertHnsEndpointsExistence(t, true, containerID, testNet.Name)
134134

135135
// Starting and stopping the container should NOT affect/change the endpoints.
136-
base.Cmd("start", containerId).AssertOK()
137-
assertHnsEndpointsExistence(t, true, containerId, testNet.Name)
136+
base.Cmd("start", containerID).AssertOK()
137+
assertHnsEndpointsExistence(t, true, containerID, testNet.Name)
138138

139-
base.Cmd("stop", containerId).AssertOK()
140-
assertHnsEndpointsExistence(t, true, containerId, testNet.Name)
139+
base.Cmd("stop", containerID).AssertOK()
140+
assertHnsEndpointsExistence(t, true, containerID, testNet.Name)
141141

142142
// Removing the container should remove the HNS endpoints.
143-
base.Cmd("rm", containerId).AssertOK()
144-
assertHnsEndpointsExistence(t, false, containerId, testNet.Name)
143+
base.Cmd("rm", containerID).AssertOK()
144+
assertHnsEndpointsExistence(t, false, containerID, testNet.Name)
145145
}
146146

147147
// Returns a network to be used for testing.

cmd/nerdctl/image/image_encrypt_linux_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ func TestImageEncryptJWE(t *testing.T) {
2929
testutil.RequiresBuild(t)
3030
testutil.DockerIncompatible(t)
3131
keyPair := helpers.NewJWEKeyPair(t)
32-
defer keyPair.Cleanup()
3332
base := testutil.NewBase(t)
3433
tID := testutil.Identifier(t)
3534
reg := testregistry.NewWithNoAuth(base, 0, false)
35+
36+
defer keyPair.Cleanup()
3637
defer reg.Cleanup(nil)
38+
3739
base.Cmd("pull", testutil.CommonImage).AssertOK()
3840
encryptImageRef := fmt.Sprintf("127.0.0.1:%d/%s:encrypted", reg.Port, tID)
39-
defer base.Cmd("rmi", encryptImageRef).Run()
4041
base.Cmd("image", "encrypt", "--recipient=jwe:"+keyPair.Pub, testutil.CommonImage, encryptImageRef).AssertOK()
4142
base.Cmd("image", "inspect", "--mode=native", "--format={{len .Index.Manifests}}", encryptImageRef).AssertOutExactly("1\n")
4243
base.Cmd("image", "inspect", "--mode=native", "--format={{json .Manifest.Layers}}", encryptImageRef).AssertOutContains("org.opencontainers.image.enc.keys.jwe")
4344
base.Cmd("push", encryptImageRef).AssertOK()
45+
46+
defer base.Cmd("rmi", encryptImageRef).Run()
47+
4448
// remove all local images (in the nerdctl-test namespace), to ensure that we do not have blobs of the original image.
4549
helpers.RmiAll(base)
4650
base.Cmd("pull", encryptImageRef).AssertFail() // defaults to --unpack=true, and fails due to missing prv key

pkg/cmd/container/run_cgroup_freebsd.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

pkg/cmd/container/run_cgroup_windows.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)