Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore import path with uppercase characters in custom build ko example #6286

Merged
merged 4 commits into from
Aug 11, 2021

Conversation

halvards
Copy link
Contributor

@halvards halvards commented Jul 26, 2021

Fixes: #5505
Related: #5492 #6041

Description

Updated: 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).

To make the custom builder test case easier to identify from the build logs, I renamed the pod in the example.

Hypothesis: Could this be related to the issues some users are reporting with images not being sideloaded when using Helm? E.g., #5159

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.

@halvards halvards requested a review from a team as a code owner July 26, 2021 07:14
@halvards halvards requested a review from tejal29 July 26, 2021 07:14
@google-cla google-cla bot added the cla: yes label Jul 26, 2021
@codecov
Copy link

codecov bot commented Jul 26, 2021

Codecov Report

Merging #6286 (cda18cc) into main (73d1ec9) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #6286   +/-   ##
=======================================
  Coverage   70.38%   70.38%           
=======================================
  Files         501      501           
  Lines       22755    22755           
=======================================
  Hits        16015    16015           
  Misses       5696     5696           
  Partials     1044     1044           
Impacted Files Coverage Δ
pkg/skaffold/kubernetes/loader/load.go 68.83% <100.00%> (ø)
pkg/skaffold/docker/parse.go 87.39% <0.00%> (-0.85%) ⬇️
pkg/skaffold/util/tar.go 65.51% <0.00%> (+2.29%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 73d1ec9...cda18cc. Read the comment docs.

@gsquared94 gsquared94 added the kokoro:force-run forces a kokoro re-run on a PR label Aug 6, 2021
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Aug 6, 2021
Copy link
Contributor

@gsquared94 gsquared94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tejal29 tejal29 added the kokoro:force-run forces a kokoro re-run on a PR label Aug 10, 2021
@tejal29 tejal29 enabled auto-merge (squash) August 10, 2021 21:06
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Aug 10, 2021
@tejal29
Copy link
Member

tejal29 commented Aug 10, 2021

@halvards not sure why kokoro job keeps failing.

This is the error. Is it related to go v1.16?

go: downloading gopkg.in/warnings.v0 v0.1.2
go: downloading github.com/xanzy/ssh-agent v0.2.1
go: downloading github.com/mitchellh/go-homedir v1.1.0
/root/go/pkg/mod/github.com/google/[email protected]/licenses/embed.go:4:2: package embed is not in GOROOT (/usr/local/go/src/embed)
/root/go/pkg/mod/github.com/google/[email protected]/licenses/embed.go:5:2: package io/fs is not in GOROOT (/usr/local/go/src/io/fs)
make: *** [cmd/skaffold/app/cmd/statik/statik.go] Error 1
Makefile:314: recipe for target 'cmd/skaffold/app/cmd/statik/statik.go' failed
The command '/bin/sh -c make clean out/skaffold VERSION=$VERSION && mv out/skaffold /usr/bin/skaffold && rm -rf secrets $SECRET cmd/skaffold/app/cmd/statik/statik.go' returned a non-zero code: 2
Command exited with non-zero status 2
1.94user 0.64system 1:18.74elapsed 3%CPU (0avgtext+0avgdata 62504maxresident)k
784inputs+80outputs (3major+167544minor)pagefaults 0swaps
Makefile:197: recipe for target 'skaffold-builder' failed
make: *** [skaffold-builder] Error 2


[ID: 5150685] Build finished after 100 secs, exit value: 2


Warning: Permanently added 'localhost' (ED25519) to the list of known hosts.
[14:09:55] Collecting build artifacts from build VM
Build script failed with exit code: 2
/export/hda3/borglet/local_ram_fs_dirs/0.kokoro-executor-gcp_ubuntu-dynamic-prod-1955066109.jenkins_slave.kokoro-dedicated.1745906410558.c8564a224093156f/alloc/builder/kokoro_builder.par/google3/devtools/kokoro/jenkins/slave/kokoro_builder.py:277: DeprecationWarning: The 'warn' function is deprecated, use 'warning' instead

@halvards
Copy link
Contributor Author

@halvards not sure why kokoro job keeps failing.

This is the error. Is it related to go v1.16?

Thanks for the heads up. Not sure, I'll take a look at this tomorrow.

@nkubala
Copy link
Contributor

nkubala commented Aug 11, 2021

@halvards this should be fixed by rebasing onto the latest commit from main (just tried it locally)...though i'm honestly not sure why 😅

I wasn't able to reproduce the issue described in GoogleContainerTools#5492 and GoogleContainerTools#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.
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.
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.
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., GoogleContainerTools#5159
@tejal29
Copy link
Member

tejal29 commented Aug 11, 2021

just did a rebase for you. Hopefully this attempt will succeed.

@tejal29 tejal29 added the kokoro:force-run forces a kokoro re-run on a PR label Aug 11, 2021
@tejal29
Copy link
Member

tejal29 commented Aug 11, 2021

ahh kokoro run didn't happen. Running one now.

@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Aug 11, 2021
@tejal29 tejal29 merged commit 41375f3 into GoogleContainerTools:main Aug 11, 2021
@halvards halvards deleted the fix-5505 branch August 11, 2021 23:36
halvards added a commit to halvards/skaffold that referenced this pull request Aug 16, 2021
Decide on how ko builder users should specify the location of
`package main` for their images.

Previous discussion: GoogleContainerTools#6054 (comment)

Tracking: GoogleContainerTools#6041
Related: GoogleContainerTools#6054, GoogleContainerTools#6286
halvards added a commit to halvards/skaffold that referenced this pull request Aug 16, 2021
Decide on how ko builder users should specify the location of
`package main` for their images.

Previous discussion: GoogleContainerTools#6054 (comment)

Tracking: GoogleContainerTools#6041
Related: GoogleContainerTools#6054, GoogleContainerTools#6286
tejal29 pushed a commit that referenced this pull request Aug 16, 2021
* Refine ko builder behavior for main packages

Decide on how ko builder users should specify the location of
`package main` for their images.

Previous discussion: #6054 (comment)

Tracking: #6041
Related: #6054, #6286

* Improve explanation of the Target config field

Clarify how a blank value works, and also how users can use a pattern
with wildcards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate why SanitizeImageName isn't being called
5 participants