From df3e6b3d59eebdd7c06726a0a4c5fbb6766b6bde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Fern=C3=A1ndez=20Mart=C3=ADnez?= Date: Thu, 3 Dec 2020 16:31:11 +0100 Subject: [PATCH] Adapting REGEXP to docker requirements According to the `docker` CLI, when running a container with a wrong name, the following output is shown: ``` > docker run -it --name '$$' alpine docker: Error response from daemon: Invalid container name ($$), only [a-zA-Z0-9][a-zA-Z0-9_.-] are allowed. ``` Concatenating `container:` to the expected regular expression `[a-zA-Z0-9][a-zA-Z0-9_.-]` helps us rejecting wrong values. --- docs/content/en/schemas/v2beta10.json | 5 +-- docs/content/en/schemas/v2beta11.json | 5 ++- pkg/skaffold/schema/validation/validation.go | 2 +- .../schema/validation/validation_test.go | 45 ++++++++++++++++++- 4 files changed, 49 insertions(+), 8 deletions(-) diff --git a/docs/content/en/schemas/v2beta10.json b/docs/content/en/schemas/v2beta10.json index 51e4af8ab2d..ff66c9a27e8 100755 --- a/docs/content/en/schemas/v2beta10.json +++ b/docs/content/en/schemas/v2beta10.json @@ -992,12 +992,11 @@ }, "network": { "type": "string", - "description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `container:`: reuse another container's network stack. `none`: no networking in the container.", - "x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are host: use the host's networking stack. bridge: use the bridged network configuration. container:<name|id>: reuse another container's network stack. none: no networking in the container.", + "description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `none`: no networking in the container.", + "x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are host: use the host's networking stack. bridge: use the bridged network configuration. none: no networking in the container.", "enum": [ "host", "bridge", - "container:", "none" ] }, diff --git a/docs/content/en/schemas/v2beta11.json b/docs/content/en/schemas/v2beta11.json index e3bf3f0c0c1..3b3be8b011d 100755 --- a/docs/content/en/schemas/v2beta11.json +++ b/docs/content/en/schemas/v2beta11.json @@ -992,11 +992,12 @@ }, "network": { "type": "string", - "description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `none`: no networking in the container.", - "x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are host: use the host's networking stack. bridge: use the bridged network configuration. none: no networking in the container.", + "description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are `host`: use the host's networking stack. `bridge`: use the bridged network configuration. `container:`: reuse another container's network stack. `none`: no networking in the container.", + "x-intellij-html-description": "passed through to docker and overrides the network configuration of docker builder. If unset, use whatever is configured in the underlying docker daemon. Valid modes are host: use the host's networking stack. bridge: use the bridged network configuration. container:<name|id>: reuse another container's network stack. none: no networking in the container.", "enum": [ "host", "bridge", + "container:", "none" ] }, diff --git a/pkg/skaffold/schema/validation/validation.go b/pkg/skaffold/schema/validation/validation.go index 172af5b0ca8..b8c67aea4e9 100644 --- a/pkg/skaffold/schema/validation/validation.go +++ b/pkg/skaffold/schema/validation/validation.go @@ -189,7 +189,7 @@ func validateDockerNetworkMode(artifacts []*latest.Artifact) (errs []error) { if mode == "none" || mode == "bridge" || mode == "host" { continue } - containerRegExp := regexp.MustCompile("container:.+") + containerRegExp := regexp.MustCompile("^container:[a-zA-Z0-9][a-zA-Z0-9_.-]*$") if containerRegExp.MatchString(mode) { continue } diff --git a/pkg/skaffold/schema/validation/validation_test.go b/pkg/skaffold/schema/validation/validation_test.go index 086796e07d6..4462958e590 100644 --- a/pkg/skaffold/schema/validation/validation_test.go +++ b/pkg/skaffold/schema/validation/validation_test.go @@ -309,13 +309,54 @@ func TestValidateNetworkMode(t *testing.T) { shouldErr: true, }, { - description: "container's network stack", + description: "wrong container's network stack '-not-valid'", artifacts: []*latest.Artifact{ { ImageName: "image/container", ArtifactType: latest.ArtifactType{ DockerArtifact: &latest.DockerArtifact{ - NetworkMode: "Container:unique-identifier", + NetworkMode: "Container:-not-valid", + }, + }, + }, + }, + shouldErr: true, + }, + { + description: "wrong container's network stack 'fussball'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:fußball", + }, + }, + }, + }, + shouldErr: true, + }, + { + description: "container's network stack 'unique'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:unique", + }, + }, + }, + }, + }, + { + description: "container's network stack 'unique-id.123'", + artifacts: []*latest.Artifact{ + { + ImageName: "image/container", + ArtifactType: latest.ArtifactType{ + DockerArtifact: &latest.DockerArtifact{ + NetworkMode: "Container:unique-id.123", }, }, },