Use current platform when fetching image in warmer
Cache warming fetched images without specifying platform, which resulted in always pulling default linux/amd64. Even when kaniko was built and run on arm64. This change brings warmer's behaviour in line with executor's by specifying runtime.GOOS/GOARCH. Fixes #1372
This commit is contained in:
parent
c480a06347
commit
4af795bf4a
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/config"
|
"github.com/GoogleContainerTools/kaniko/pkg/config"
|
||||||
"github.com/GoogleContainerTools/kaniko/pkg/creds"
|
"github.com/GoogleContainerTools/kaniko/pkg/creds"
|
||||||
|
|
@ -117,7 +118,10 @@ func (w *Warmer) Warm(image string, opts *config.WarmerOptions) (v1.Hash, error)
|
||||||
return v1.Hash{}, errors.Wrapf(err, "Failed to verify image name: %s", image)
|
return v1.Hash{}, errors.Wrapf(err, "Failed to verify image name: %s", image)
|
||||||
}
|
}
|
||||||
|
|
||||||
rOpts := []remote.Option{remote.WithTransport(http.DefaultTransport.(*http.Transport)), remote.WithAuthFromKeychain(creds.GetKeychain())}
|
transport := http.DefaultTransport.(*http.Transport)
|
||||||
|
platform := currentPlatform()
|
||||||
|
|
||||||
|
rOpts := []remote.Option{remote.WithTransport(transport), remote.WithAuthFromKeychain(creds.GetKeychain()), remote.WithPlatform(platform)}
|
||||||
img, err := w.Remote(cacheRef, rOpts...)
|
img, err := w.Remote(cacheRef, rOpts...)
|
||||||
if err != nil || img == nil {
|
if err != nil || img == nil {
|
||||||
return v1.Hash{}, errors.Wrapf(err, "Failed to retrieve image: %s", image)
|
return v1.Hash{}, errors.Wrapf(err, "Failed to retrieve image: %s", image)
|
||||||
|
|
@ -151,3 +155,11 @@ func (w *Warmer) Warm(image string, opts *config.WarmerOptions) (v1.Hash, error)
|
||||||
|
|
||||||
return digest, nil
|
return digest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CurrentPlatform returns the v1.Platform on which the code runs.
|
||||||
|
func currentPlatform() v1.Platform {
|
||||||
|
return v1.Platform{
|
||||||
|
OS: runtime.GOOS,
|
||||||
|
Architecture: runtime.GOARCH,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue