GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.77k stars 1.44k forks source link

Warmer ignores result of `cache-ttl` #928

Open cvgw opened 4 years ago

cvgw commented 4 years ago

Actual behavior Cache warmer does not return an error and does not remove expired images from the cache. The function used to check for the presence of a cached image takes options containing the value of cache-ttl. This function does not return an error when the cached image is found but expired. https://github.com/GoogleContainerTools/kaniko/blob/9ebee24bf332e89817844125de1225ba0247b573/pkg/cache/cache.go#L135

and the warmer code does not check if the return image is nil

https://github.com/GoogleContainerTools/kaniko/blob/9ebee24bf332e89817844125de1225ba0247b573/pkg/cache/warm.go#L56

Expected behavior Either the cache warmer does not accept the cache-ttl flag OR The cache warmer re-downloads an image to the cache when it is expired OR The cache warmer deletes an image from the cache when it is expired OR The cache warmer exits with an error code when an image is expired

To Reproduce Steps to reproduce the behavior: If the base image was not present, the file will be written to the cache and the cache warmer will output some traces:

$ docker run -v ${PWD}:/cache gcr.io/kaniko-project/warmer:latest \
             --cache-dir=/cache -v debug -i ubuntu:latest --cache-ttl=10h
DEBU[0000] /cache                                       
DEBU[0000] [ubuntu:latest]                              
DEBU[0002] Wrote ubuntu:latest to cache

If the base image was already in the cache and is not expired according to the --cache-ttl option, nothing special happens beside a specific trace:

$ docker run -v ${PWD}:/cache gcr.io/kaniko-project/warmer:latest \
             --cache-dir=/cache -v debug -i ubuntu:latest --cache-ttl=10h
DEBU[0000] /cache                                       
DEBU[0000] [ubuntu:latest]                              
INFO[0000] Found sha256:2695d3e10e69cc500a16eae6d6629c803c43ab075fa5ce60813a0fc49c47e859 in local cache 
INFO[0000] Found manifest at /cache/sha256:2695d3e10e69cc500a16eae6d6629c803c43ab075fa5ce60813a0fc49c47e859.json 

If it's expired, nothing special happens but the trace is different:

$ docker run -v ${PWD}:/cache gcr.io/kaniko-project/warmer:latest --cache-dir=/cache -v debug -i ubuntu:latest --cache-ttl=1s
DEBU[0000] /cache                                       
DEBU[0000] [ubuntu:latest]                              
DEBU[0000] Cached image is too old: 2019-12-19 16:46:48.276102926 +0000 UTC

Additional Information

jerkern commented 2 years ago

Hitting a side-effect of this issue as well, since the pulled images never seem to be cleaned up the folder used for the cache will eventually fill up causing the prewarmer to fail pulling new images. It would have been nice if the prewarmer removed images that are older than the TTL