Skip to content

Commit 41375f3

Browse files
authored
Restore import path with uppercase characters in custom build ko example (#6286)
* Restore import path with uppercase characters I wasn't able to reproduce the issue described in #5492 and #5505, so this change restores the import path with the uppercase characters and the `ko://` prefix in the custom build example. I had to tweak some values to get the integration tests to run, because I don't have access to the `k8s-skaffold` project. Let's see if the build passes. Additional minor changes: - Bump the ko version in the custom build example. - Add the full path to the ko binary in the custom build script, in case `$GOPATH/bin` is not on the `PATH`. Once we move to Go 1.16 for our builds, we can use the `go install` command to install ko in the custom build shell script. * Look for ko binary in GOPATH/bin It's difficult to know what's on the `PATH` in different environments. This change to the custom builder example looks for the ko binary in the `GOPATH/bin` directory. * Remove tagPolicy from custom builder example Hypothesis: `tagPolicy: sha256` doesn't behave correctly with images sideloaded into kind snf k3d. Also fix conditional in custom build example shell script to prevent recompiling ko each time. * Sanitize image names before deciding what to load I was able to reproduce the issue locally and work out a fix. I'd be happy for feedback on whether I've chosen the right place to fix it. When determining which images to sideload (for kind and k3d), we compare `localImages` and `deployerImages`. The former from `skaffold.yaml`, and the latter from Kubernetes manifest files. The image names from Kubernetes manifests are sanitized in `pkg/skaffold/kubernetes/manifests/images.go#L51` (and `L113`) in the call to docker.ParseReference. The same doesn't happen to image names from `skaffold.yaml`. This change sanitizes these image names just for determining whether to sideload the images. In other parts of the code we look up image pipelines from `skaffold.yaml` using the image name, so I was hesitant to change how `localImages` is used (with 'raw' image names). The hypothesis from the previous commit is disproven, so I'm adding back the `sha256` tag policy in the custom builder example. To make the test case easier to identify from the build logs, I renamed the pod in the custom builder example. New hypothesis: Could this be related to the issues some users are reporting with images not being sideloaded when using Helm? E.g., #5159
1 parent fca70ba commit 41375f3

File tree

6 files changed

+22
-10
lines changed

6 files changed

+22
-10
lines changed

integration/examples/custom/build.sh

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
#!/usr/bin/env bash
22
set -e
33

4-
if ! [ -x "$(command -v ko)" ]; then
4+
if ! [ -x "$(go env GOPATH)/bin/ko" ]; then
55
pushd $(mktemp -d)
6-
go mod init tmp; GOFLAGS= go get github.com/google/ko/cmd/ko@v0.6.0
6+
curl -L https://github.com/google/ko/archive/v0.8.3.tar.gz | tar --strip-components 1 -zx
7+
go build -o $(go env GOPATH)/bin/ko .
78
popd
89
fi
910

10-
output=$(ko publish --local --preserve-import-paths --tags= . | tee)
11+
output=$($(go env GOPATH)/bin/ko publish --local --preserve-import-paths --tags= . | tee)
1112
ref=$(echo "$output" | tail -n1)
1213

1314
docker tag "$ref" "$IMAGE"
1415
if [[ "${PUSH_IMAGE}" == "true" ]]; then
16+
echo "Pushing $IMAGE"
1517
docker push "$IMAGE"
18+
else
19+
echo "Not pushing $IMAGE"
1620
fi
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
apiVersion: v1
22
kind: Pod
33
metadata:
4-
name: getting-started
4+
name: getting-started-custom
55
spec:
66
containers:
7-
- name: getting-started
8-
image: github.com/googlecontainertools/skaffold/examples/custom
7+
- name: getting-started-custom
8+
image: ko://github.com/GoogleContainerTools/skaffold/examples/custom

integration/examples/custom/skaffold.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: skaffold/v2beta21
22
kind: Config
33
build:
44
artifacts:
5-
- image: github.com/googlecontainertools/skaffold/examples/custom
5+
- image: ko://github.com/GoogleContainerTools/skaffold/examples/custom
66
custom:
77
buildCommand: ./build.sh
88
dependencies:

integration/run_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ var tests = []struct {
113113
{
114114
description: "custom builder",
115115
dir: "examples/custom",
116-
pods: []string{"getting-started"},
116+
pods: []string{"getting-started-custom"},
117117
},
118118
{
119119
description: "buildpacks Go",

pkg/skaffold/kubernetes/loader/load.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"k8s.io/client-go/tools/clientcmd/api"
2929

3030
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
31+
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
3132
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/graph"
3233
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
3334
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
@@ -60,7 +61,7 @@ func NewImageLoader(kubeContext string, cli *kubectl.CLI) *ImageLoader {
6061
func imagesToLoad(localImages, deployerImages, images []graph.Artifact) []graph.Artifact {
6162
local := map[string]bool{}
6263
for _, image := range localImages {
63-
local[image.ImageName] = true
64+
local[docker.SanitizeImageName(image.ImageName)] = true
6465
}
6566

6667
tracked := map[string]bool{}
@@ -72,7 +73,7 @@ func imagesToLoad(localImages, deployerImages, images []graph.Artifact) []graph.
7273

7374
var res []graph.Artifact
7475
for _, image := range images {
75-
if tracked[image.ImageName] {
76+
if tracked[docker.SanitizeImageName(image.ImageName)] {
7677
res = append(res, image)
7778
}
7879
}

pkg/skaffold/kubernetes/loader/load_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,13 @@ func TestImagesToLoad(t *testing.T) {
200200
builtImages: []graph.Artifact{{ImageName: "image1", Tag: "foo"}},
201201
expectedImages: nil,
202202
},
203+
{
204+
name: "single image marked as local, with ko prefix and Go import path with uppercase characters",
205+
localImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
206+
deployerImages: []graph.Artifact{{ImageName: "example.com/organization/image1", Tag: "Foo"}},
207+
builtImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
208+
expectedImages: []graph.Artifact{{ImageName: "ko://example.com/Organization/Image1", Tag: "Foo"}},
209+
},
203210
{
204211
name: "two images marked as local",
205212
localImages: []graph.Artifact{{ImageName: "image1", Tag: "foo"}, {ImageName: "image2", Tag: "bar"}},

0 commit comments

Comments
 (0)