From 52a8b75b554bc2201299873828477dd91b87971a Mon Sep 17 00:00:00 2001 From: Jamie Phillips Date: Tue, 9 Nov 2021 21:15:21 -0500 Subject: [PATCH] Adding OS version to Crane for better Windows support. Windows images present some unique challenges and one of those challenges is being able to pull a specific OS version. This especially comes into play when working with a manifest like the k8s.gcr.io/pause:3.6 which doesn't offer tags specific to Windows OS version. Here is an example use case: crane pull --platform windows/amd64 --osversion 10.0.17763.2114 k8s.gcr.io/pause:3.6 windows-1809.tar Without the version specified Windows Server 2022 would have been pulled. Signed-off-by: Jamie Phillips --- cmd/crane/cmd/root.go | 6 ++++++ pkg/v1/remote/index.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/crane/cmd/root.go b/cmd/crane/cmd/root.go index d0bc6429a..b692e91e2 100644 --- a/cmd/crane/cmd/root.go +++ b/cmd/crane/cmd/root.go @@ -38,6 +38,7 @@ func New(use, short string, options []crane.Option) *cobra.Command { verbose := false insecure := false platform := &platformValue{} + var osVersion string root := &cobra.Command{ Use: use, @@ -62,6 +63,10 @@ func New(use, short string, options []crane.Option) *cobra.Command { options = append(options, crane.WithUserAgent(fmt.Sprintf("%s/%s", binary, Version))) } + if osVersion != "" { + platform.platform.OSVersion = osVersion + } + options = append(options, crane.WithPlatform(platform.platform)) transport := http.DefaultTransport.(*http.Transport).Clone() @@ -111,6 +116,7 @@ func New(use, short string, options []crane.Option) *cobra.Command { root.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable debug logs") root.PersistentFlags().BoolVar(&insecure, "insecure", false, "Allow image references to be fetched without TLS") root.PersistentFlags().Var(platform, "platform", "Specifies the platform in the form os/arch[/variant] (e.g. linux/amd64).") + root.PersistentFlags().StringVar(&osVersion, "osversion", "", "Specifies the OS version.") return root } diff --git a/pkg/v1/remote/index.go b/pkg/v1/remote/index.go index 49c5404e1..989857918 100644 --- a/pkg/v1/remote/index.go +++ b/pkg/v1/remote/index.go @@ -214,7 +214,7 @@ func (r *remoteIndex) childByPlatform(platform v1.Platform) (*Descriptor, error) return r.childDescriptor(childDesc, platform) } } - return nil, fmt.Errorf("no child with platform %s/%s in index %s", platform.OS, platform.Architecture, r.Ref) + return nil, fmt.Errorf("no child with platform %+v in index %s", platform, r.Ref) } func (r *remoteIndex) childByHash(h v1.Hash) (*Descriptor, error) {