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

Option to mount HostPath in each Kaniko Pod to be used as cache volume #1690

Merged

Conversation

martinhoefling
Copy link
Contributor

The introduced HostPath option mounts a host path of a kubernetes node into the kaniko executor pod. This path can be prepopulated with kaniko-warmer and is used by setting --cache=true and --cache-dir on execution of kaniko.

@codecov-io
Copy link

codecov-io commented Feb 22, 2019

Codecov Report

Merging #1690 into master will decrease coverage by 0.1%.
The diff coverage is 10.52%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1690      +/-   ##
==========================================
- Coverage   56.74%   56.63%   -0.11%     
==========================================
  Files         183      183              
  Lines        7860     7875      +15     
==========================================
  Hits         4460     4460              
- Misses       2988     3001      +13     
- Partials      412      414       +2
Impacted Files Coverage Δ
pkg/skaffold/schema/latest/config.go 100% <ø> (ø) ⬆️
pkg/skaffold/build/cluster/sources/localdir.go 0% <0%> (ø) ⬆️
pkg/skaffold/build/cluster/sources/gcs.go 0% <0%> (ø) ⬆️
pkg/skaffold/build/cluster/kaniko.go 36.11% <0%> (-1.04%) ⬇️
pkg/skaffold/build/cluster/sources/sources.go 76.13% <13.33%> (-13.2%) ⬇️

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 eb9916f...6720ca6. Read the comment docs.

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

hey @martinhoefling, thanks for the PR and sorry for the late review! looks like you need to rebase here unfortunately. you'll need to move your config changes to the latest version. also, make sure that --cache=true is being added to the kaniko args before you add the --cache-dir flag. other than that this looks good!

@martinhoefling martinhoefling force-pushed the kaniko-host-path-cache branch 2 times, most recently from e271431 to 49f4d05 Compare March 30, 2019 20:48
@martinhoefling
Copy link
Contributor Author

@nkubala rebased. Can you check it again?

@nkubala
Copy link
Contributor

nkubala commented Apr 25, 2019

@martinhoefling sorry for the delay. we bumped the config version since the last review so you'll need to move your changes one more time to the latest version 😨 it's annoying I know, and I'll take responsibility for that. I'll merge this once you do!

@corneliusweig
Copy link
Contributor

corneliusweig commented Apr 26, 2019

@martinhoefling If you move the changes to the latest version, make sure v1beta10 has landed already. Otherwise you'll have the same problem again 😉

@martinhoefling
Copy link
Contributor Author

@corneliusweig ok, thx. How do I detect this? #2029 mentions v1beta9. Is there any other PR I should rebase on now?

@corneliusweig
Copy link
Contributor

So there is #2035, but honestly I'd wait until it is merged.

@martinhoefling
Copy link
Contributor Author

@nkubala, rebased tests fixed and config migrated to v1beta10.

@nkubala
Copy link
Contributor

nkubala commented May 7, 2019

hey @martinhoefling, thanks for addressing the config stuff. can you check out the failing integration test?

--- FAIL: TestRun/kaniko_local_with_sub_folder (0.11s)
        run_test.go:119: skaffold run: exit status 2, Generating tags...
             - gcr.io/k8s-skaffold/skaffold-example-sub -> gcr.io/k8s-skaffold/skaffold-example-sub:v0.28.0-24-gb9ad1a1
            Tags generated in 10.51041ms
            Starting build...
            Creating kaniko secret [e2esecret]...
            Building [gcr.io/k8s-skaffold/skaffold-example-sub]...
            Storing build context at /tmp/context-6154b45f3e0c80e2ca91a8ab4b0bb3a6.tar.gz

@corneliusweig
Copy link
Contributor

corneliusweig commented May 11, 2019

This PR needs a config-change label. Could it be automated to add this label, whenever latest/config.go changes?

@nkubala
Copy link
Contributor

nkubala commented May 16, 2019

@martinhoefling integration test is still failing. I don't want you to have to rebase again when we do the next config change 😬 PTAL!

@martinhoefling
Copy link
Contributor Author

@nkubala, I am struggling setting up the integration testcases locally. The logs aren’t very verbose. I have to check when I find some time for this. Maybe next week at Kubecon ;-)

@nkubala
Copy link
Contributor

nkubala commented May 16, 2019

no worries! since it's just the kaniko test failing, you can skip trying to run all the other ones locally (and skip installing all the necessary dependencies for them). if you have kaniko configured on a cluster, you can just set up your secret in the skaffold.yaml in that example directory.

make sure to swing by our both at kubecon and say hi! maybe someone can give you some pointers for the integration tests 😆

@martinhoefling
Copy link
Contributor Author

So when I run it locally (minikube), everything works fine except the push step.

Kaniko log output (via stern)

+ kaniko-k8nhg › kaniko-init-container
+ kaniko-k8nhg › kaniko
kaniko-k8nhg kaniko INFO[0000] Downloading base image golang:1.12.5-alpine3.9
kaniko-k8nhg kaniko 2019/05/19 11:12:32 No matching credentials were found, falling back on anonymous
kaniko-k8nhg kaniko INFO[0001] Error while retrieving image from cache: geting file info: stat /cache/sha256:5ec3232b32e6876c0941d66d8392f667c77ca1ef14cafb85991deea4339b92da: no such file or directory
kaniko-k8nhg kaniko INFO[0001] Downloading base image golang:1.12.5-alpine3.9
kaniko-k8nhg kaniko 2019/05/19 11:12:34 No matching credentials were found, falling back on anonymous
kaniko-k8nhg kaniko INFO[0002] Using files from context: [/kaniko/buildcontext/main.go]
kaniko-k8nhg kaniko INFO[0002] Checking for cached layer gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d...
kaniko-k8nhg kaniko INFO[0002] No cached layer found for cmd RUN go build -o /app main.go
kaniko-k8nhg kaniko INFO[0002] Unpacking rootfs as cmd RUN go build -o /app main.go requires it.
kaniko-k8nhg kaniko INFO[0025] Taking snapshot of full filesystem...
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /kaniko, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /var/run, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /secret, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /dev, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /sys, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0026] Skipping paths under /proc, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0028] Using files from context: [/kaniko/buildcontext/main.go]
kaniko-k8nhg kaniko INFO[0028] COPY main.go .
kaniko-k8nhg kaniko INFO[0028] Taking snapshot of files...
kaniko-k8nhg kaniko INFO[0028] RUN go build -o /app main.go
kaniko-k8nhg kaniko INFO[0028] cmd: /bin/sh
kaniko-k8nhg kaniko INFO[0028] args: [-c go build -o /app main.go]
kaniko-k8nhg kaniko INFO[0028] Taking snapshot of full filesystem...
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /kaniko, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /var/run, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /secret, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /dev, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /sys, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Skipping paths under /proc, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/e0/e0d9637a42516f6aa3defff56cc9a4d3deaf96b2ade546448835c41bd63d82bc-a
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/98/9816bb371bccde8cb7bf5a44febdb32bbc327a0a5c2e940d9b8b3a402f62e4f0-d
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/b5/b5cb5076dbba489139e99e802f57979f0f7f4f96806267201ca4e383513a312b-a
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/5e/5eddca62332aaa6cb767cf6e8b4ce6b00d97ee63b3f549ac9586becdaea0f26c-d
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/c4/c483d510e0608431902a9e3aa9e162e4b88f745b790a07a1a4b45f22ef9013f4-a
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/31/311571a11a5934d4f63ba6daaa1b0a1e578ee13a1a373547131af1d9d157dbb4-d
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/e3/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855-d
kaniko-k8nhg kaniko INFO[0029] Adding whiteout for /root/.cache/go-build/77/77a522d1008cfd60284c5bd5cc6fc283abe7ef012d61d06d0fd6b1ff03becc68-a
kaniko-k8nhg kaniko INFO[0031] Pushing layer gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d to cache now
kaniko-k8nhg kaniko WARN[0031] error uploading layer to cache: failed to push to destination gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d: Get https://gcr.io/v2/token?scope=repository%3Ak8s-skaffold%2Fskaffold-example%2Fcache%3Apush%2Cpull&service=gcr.io: exit status 1
kaniko-k8nhg kaniko INFO[0031] Storing source image from stage 0 at path /kaniko/stages/0
kaniko-k8nhg kaniko INFO[0078] Deleting filesystem...
kaniko-k8nhg kaniko INFO[0078] Downloading base image alpine:3.9
kaniko-k8nhg kaniko 2019/05/19 11:13:51 No matching credentials were found, falling back on anonymous
kaniko-k8nhg kaniko INFO[0079] Error while retrieving image from cache: geting file info: stat /cache/sha256:bf1684a6e3676389ec861c602e97f27b03f14178e5bc3f70dce198f9f160cce9: no such file or directory
kaniko-k8nhg kaniko INFO[0079] Downloading base image alpine:3.9
kaniko-k8nhg kaniko 2019/05/19 11:13:52 No matching credentials were found, falling back on anonymous
kaniko-k8nhg kaniko INFO[0080] Taking snapshot of full filesystem...
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /kaniko, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /var/run, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /secret, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /dev, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /sys, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] Skipping paths under /proc, as it is a whitelisted directory
kaniko-k8nhg kaniko INFO[0081] CMD ["./app"]
kaniko-k8nhg kaniko INFO[0081] No files changed in this command, skipping snapshotting.
kaniko-k8nhg kaniko INFO[0081] COPY --from=builder /app .
kaniko-k8nhg kaniko INFO[0081] Taking snapshot of files...
kaniko-k8nhg kaniko error pushing image: failed to push to destination gcr.io/k8s-skaffold/skaffold-example:v0.29.0-75-g333737ef-dirty: Get https://gcr.io/v2/token?scope=repository%3Ak8s-skaffold%2Fskaffold-example%3Apush%2Cpull&scope=repository%3Alibrary%2Falpine%3Apull&service=gcr.io: exit status 1

Skaffold output

╰─ skaffold build                          
Generating tags...
 - gcr.io/k8s-skaffold/skaffold-example -> gcr.io/k8s-skaffold/skaffold-example:v0.29.0-75-g333737ef-dirty
Tags generated in 94.654838ms
Starting build...
Creating kaniko secret [e2esecret]...
Building [gcr.io/k8s-skaffold/skaffold-example]...
Storing build context at /var/folders/1v/yx3p9mgj7_s7wgm1n2bl6f2c0000gn/T/context-275142bf6d2450ac7a24cc6ea06e698b.tar.gz
INFO[0000] Downloading base image golang:1.12.5-alpine3.9 
2019/05/19 11:12:32 No matching credentials were found, falling back on anonymous
INFO[0001] Error while retrieving image from cache: geting file info: stat /cache/sha256:5ec3232b32e6876c0941d66d8392f667c77ca1ef14cafb85991deea4339b92da: no such file or directory 
INFO[0001] Downloading base image golang:1.12.5-alpine3.9 
2019/05/19 11:12:34 No matching credentials were found, falling back on anonymous
INFO[0002] Using files from context: [/kaniko/buildcontext/main.go] 
INFO[0002] Checking for cached layer gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d... 
INFO[0002] No cached layer found for cmd RUN go build -o /app main.go 
INFO[0002] Unpacking rootfs as cmd RUN go build -o /app main.go requires it. 
INFO[0025] Taking snapshot of full filesystem...        
INFO[0026] Skipping paths under /kaniko, as it is a whitelisted directory 
INFO[0026] Skipping paths under /var/run, as it is a whitelisted directory 
INFO[0026] Skipping paths under /secret, as it is a whitelisted directory 
INFO[0026] Skipping paths under /dev, as it is a whitelisted directory 
INFO[0026] Skipping paths under /sys, as it is a whitelisted directory 
INFO[0026] Skipping paths under /proc, as it is a whitelisted directory 
INFO[0028] Using files from context: [/kaniko/buildcontext/main.go] 
INFO[0028] COPY main.go .                               
INFO[0028] Taking snapshot of files...                  
INFO[0028] RUN go build -o /app main.go                 
INFO[0028] cmd: /bin/sh                                 
INFO[0028] args: [-c go build -o /app main.go]          
INFO[0028] Taking snapshot of full filesystem...        
INFO[0029] Skipping paths under /kaniko, as it is a whitelisted directory 
INFO[0029] Skipping paths under /var/run, as it is a whitelisted directory 
INFO[0029] Skipping paths under /secret, as it is a whitelisted directory 
INFO[0029] Skipping paths under /dev, as it is a whitelisted directory 
INFO[0029] Skipping paths under /sys, as it is a whitelisted directory 
INFO[0029] Skipping paths under /proc, as it is a whitelisted directory 
INFO[0029] Adding whiteout for /root/.cache/go-build/e0/e0d9637a42516f6aa3defff56cc9a4d3deaf96b2ade546448835c41bd63d82bc-a 
INFO[0029] Adding whiteout for /root/.cache/go-build/98/9816bb371bccde8cb7bf5a44febdb32bbc327a0a5c2e940d9b8b3a402f62e4f0-d 
INFO[0029] Adding whiteout for /root/.cache/go-build/b5/b5cb5076dbba489139e99e802f57979f0f7f4f96806267201ca4e383513a312b-a 
INFO[0029] Adding whiteout for /root/.cache/go-build/5e/5eddca62332aaa6cb767cf6e8b4ce6b00d97ee63b3f549ac9586becdaea0f26c-d 
INFO[0029] Adding whiteout for /root/.cache/go-build/c4/c483d510e0608431902a9e3aa9e162e4b88f745b790a07a1a4b45f22ef9013f4-a 
INFO[0029] Adding whiteout for /root/.cache/go-build/31/311571a11a5934d4f63ba6daaa1b0a1e578ee13a1a373547131af1d9d157dbb4-d 
INFO[0029] Adding whiteout for /root/.cache/go-build/e3/e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855-d 
INFO[0029] Adding whiteout for /root/.cache/go-build/77/77a522d1008cfd60284c5bd5cc6fc283abe7ef012d61d06d0fd6b1ff03becc68-a 
INFO[0031] Pushing layer gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d to cache now 
WARN[0031] error uploading layer to cache: failed to push to destination gcr.io/k8s-skaffold/skaffold-example/cache:c359c409a751382136cd47fdfb486fb7bf9b0f429f178eafb547f33382bb898d: Get https://gcr.io/v2/token?scope=repository%3Ak8s-skaffold%2Fskaffold-example%2Fcache%3Apush%2Cpull&service=gcr.io: exit status 1 
INFO[0031] Storing source image from stage 0 at path /kaniko/stages/0 
INFO[0078] Deleting filesystem...                       
INFO[0078] Downloading base image alpine:3.9            
2019/05/19 11:13:51 No matching credentials were found, falling back on anonymous
INFO[0079] Error while retrieving image from cache: geting file info: stat /cache/sha256:bf1684a6e3676389ec861c602e97f27b03f14178e5bc3f70dce198f9f160cce9: no such file or directory 
INFO[0079] Downloading base image alpine:3.9            
2019/05/19 11:13:52 No matching credentials were found, falling back on anonymous
INFO[0080] Taking snapshot of full filesystem...        
INFO[0081] Skipping paths under /kaniko, as it is a whitelisted directory 
INFO[0081] Skipping paths under /var/run, as it is a whitelisted directory 
INFO[0081] Skipping paths under /secret, as it is a whitelisted directory 
INFO[0081] Skipping paths under /dev, as it is a whitelisted directory 
INFO[0081] Skipping paths under /sys, as it is a whitelisted directory 
INFO[0081] Skipping paths under /proc, as it is a whitelisted directory 
INFO[0081] CMD ["./app"]                                
INFO[0081] No files changed in this command, skipping snapshotting. 
INFO[0081] COPY --from=builder /app .                   
INFO[0081] Taking snapshot of files...                  
error pushing image: failed to push to destination gcr.io/k8s-skaffold/skaffold-example:v0.29.0-75-g333737ef-dirty: Get https://gcr.io/v2/token?scope=repository%3Ak8s-skaffold%2Fskaffold-example%3Apush%2Cpull&scope=repository%3Alibrary%2Falpine%3Apull&service=gcr.io: exit status 1
Complete in 1m29.529767478s
FATA[0089] build failed: building [gcr.io/k8s-skaffold/skaffold-example]: kaniko build for [gcr.io/k8s-skaffold/skaffold-example]: waiting for pod to complete: condition error: pod already in terminal phase: Failed 

Skaffold version:

skaffold version
v0.29.0-75-g333737ef-dirty
  • host path patches

Btw, skaffold 0.29 produces the same output.

For the push step, I need to set up a registry to push first.

@martinhoefling
Copy link
Contributor Author

@nkubala I pushed my latest rebase. I'll try catch up at kubecon.

@martinhoefling
Copy link
Contributor Author

@nkubala, got it - the latest commit should fix the issue when no cache config is given at all. That was only the case in the 'kaniko-sub-folder' testdata. I looked at the local example before, where cache is set to {}.

Can you rerun the integration tests and see if this solves the issue?

@@ -229,6 +229,9 @@ type KanikoCache struct {
// Repo is a remote repository to store cached layers. If none is specified, one will be
// inferred from the image name. See [Kaniko Caching](https://github.com/GoogleContainerTools/kaniko#caching).
Repo string `yaml:"repo,omitempty"`
// HostPath specifies a path on the host that is mounted to each pod as read only cache volume containing base images.
// If set, must exist on each node and prepopulated with kaniko-warmer.
HostPath string `yaml:"hostPath,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This change should only be in the latest config version, right?

Copy link
Contributor

@corneliusweig corneliusweig left a comment

Choose a reason for hiding this comment

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

Hi @martinhoefling, you need to merge in master once more, because skaffold config version v1beta10 has been frozen (See #2109). Your changeset should only touch docs/content/en/schemas/v1beta11.json. Currently, it also affects v1beta6 which must be an error.

Hopefully, this will be the last time. Enjoy kubecon!

PS: Can you also list your addition in the comments to Upgrade() in pkg/skaffold/schema/v1beta10/upgrade.go? This may lead to further merge conflicts with other PRs though..

@nkubala
Copy link
Contributor

nkubala commented May 20, 2019

@martinhoefling thanks for seeing this one through! enjoy Kubecon, and be sure to say hi to our team at the booth :)

@nkubala nkubala merged commit e978520 into GoogleContainerTools:master May 20, 2019
@martinhoefling
Copy link
Contributor Author

@codecov-io @nkubala thx for your help!

@martinhoefling martinhoefling deleted the kaniko-host-path-cache branch May 21, 2019 08:56
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.

None yet

6 participants