Skip to content

Commit 752edc8

Browse files
committed
fix: Sanitize image names when default repo unset
This change ensures that image names from `skaffold.yaml` are sanitized even when the Skaffold default repo is not set. This is relevant for ko images with names that consist of the `ko://` scheme prefixed, followed by a Go import path that may contain uppercase characters, e.g., `ko://github.com/GoogleContainerTools/skaffold/cmd/skaffold`. Fixes: GoogleContainerTools#6675 Tracking: GoogleContainerTools#6041 Related: GoogleContainerTools#4952
1 parent f15f502 commit 752edc8

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/skaffold/build/scheduler.go

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"golang.org/x/sync/errgroup"
2727

2828
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
29+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
2930
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
3031
eventV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/event/v2"
3132
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
@@ -152,5 +153,6 @@ func performBuild(ctx context.Context, cw io.Writer, tags tag.ImageTags, artifac
152153
if !present {
153154
return "", fmt.Errorf("unable to find tag for image %s", artifact.ImageName)
154155
}
156+
tag = docker.SanitizeImageName(tag)
155157
return build(ctx, cw, artifact, tag)
156158
}

pkg/skaffold/build/scheduler_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ func TestGetBuild(t *testing.T) {
5858
expectedTag: "skaffold/image1:v0.0.1@sha256:abac",
5959
expectedOut: "Building [skaffold/image1]...\nbuild succeeds",
6060
},
61+
{
62+
description: "tag with ko scheme prefix and Go import path with uppercase characters is sanitized",
63+
buildArtifact: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string) (string, error) {
64+
out.Write([]byte("build succeeds"))
65+
return fmt.Sprintf("%s@sha256:abac", tag), nil
66+
},
67+
tags: tag.ImageTags{
68+
"skaffold/image1": "ko://github.com/GoogleContainerTools/skaffold/cmd/skaffold:v0.0.1",
69+
},
70+
expectedTag: "github.com/googlecontainertools/skaffold/cmd/skaffold:v0.0.1@sha256:abac",
71+
expectedOut: "Building [skaffold/image1]...\nbuild succeeds",
72+
},
6173
{
6274
description: "build fails",
6375
buildArtifact: func(ctx context.Context, out io.Writer, artifact *latestV1.Artifact, tag string) (string, error) {

0 commit comments

Comments
 (0)