Skip to content

Commit

Permalink
Adding OS version to Crane for better Windows support.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
phillipsj committed Nov 10, 2021
1 parent 5c9c442 commit 52a8b75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/crane/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/v1/remote/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 52a8b75

Please sign in to comment.