Skip to content

Commit a63351b

Browse files
release: Support extracting the 'oc' and 'openshift-install' binaries
The payload is the authoritative source of tools. To support the openshift-install binary being transformed to lock against a particular version, add support for: oc adm release extract --command=oc|openshift-install ... The command attempts to extract the binary appropriate for the current os or respects --command-os=mac|windows|linux. We do not support alternative architectures yet but those will be handled by extending the os field if necessary. We hardcode the lookup locations for now, assuming that a future release may make this more generic. The 'cli-artifacts' and 'installer-artifacts' images will descend from 'cli' and 'installer' and offer the mac/windows and mac variants of their respective commands. A more general purpose variant of this command is: oc adm release extract --tools ... --to=DIR which creates in DIR an archive for each tool+OS combination (right now, oc win/mac/linux and openshift-install mac/linux) as well as a sha256sum.txt.asc file that can be used to verify the output.
1 parent 4d64016 commit a63351b

File tree

8 files changed

+582
-19
lines changed

8 files changed

+582
-19
lines changed

contrib/completions/bash/oc

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/completions/zsh/oc

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/oc/cli/admin/release/extract.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import (
88
"time"
99

1010
"github.com/golang/glog"
11-
11+
digest "github.com/opencontainers/go-digest"
1212
"github.com/spf13/cobra"
1313

14-
digest "github.com/opencontainers/go-digest"
1514
apierrors "k8s.io/apimachinery/pkg/api/errors"
1615
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1716
"k8s.io/cli-runtime/pkg/genericclioptions"
@@ -39,17 +38,20 @@ func NewExtract(f kcmdutil.Factory, parentName string, streams genericclioptions
3938
Long: templates.LongDesc(`
4039
Extract the contents of a release image to disk
4140
42-
Extracts the contents of an OpenShift update image to disk for inspection or
41+
Extracts the contents of an OpenShift release image to disk for inspection or
4342
debugging. Update images contain manifests and metadata about the operators that
4443
must be installed on the cluster for a given version.
4544
45+
The --tools and --command flags allow you to extract the appropriate client binaries
46+
for your operating system to disk. --tools will create archive files containing the
47+
current OS tools (or, if --command-os is set to '*', all OS versions). Specifying
48+
--command for either 'oc' or 'openshift-install' will extract the binaries directly.
49+
4650
Instead of extracting the manifests, you can specify --git=DIR to perform a Git
4751
checkout of the source code that comprises the release. A warning will be printed
4852
if the component is not associated with source code. The command will not perform
4953
any destructive actions on your behalf except for executing a 'git checkout' which
5054
may change the current branch. Requires 'git' to be on your path.
51-
52-
Experimental: This command is under active development and may change without notice.
5355
`),
5456
Run: func(cmd *cobra.Command, args []string) {
5557
kcmdutil.CheckErr(o.Complete(f, cmd, args))
@@ -58,10 +60,16 @@ func NewExtract(f kcmdutil.Factory, parentName string, streams genericclioptions
5860
}
5961
flags := cmd.Flags()
6062
flags.StringVarP(&o.RegistryConfig, "registry-config", "a", o.RegistryConfig, "Path to your registry credentials (defaults to ~/.docker/config.json)")
61-
flags.StringVar(&o.GitExtractDir, "git", o.GitExtractDir, "Check out the sources that created this release into the provided dir. Repos will be created at <dir>/<host>/<path>. Requires 'git' on your path.")
63+
6264
flags.StringVar(&o.From, "from", o.From, "Image containing the release payload.")
6365
flags.StringVar(&o.File, "file", o.File, "Extract a single file from the payload to standard output.")
6466
flags.StringVar(&o.Directory, "to", o.Directory, "Directory to write release contents to, defaults to the current directory.")
67+
68+
flags.StringVar(&o.GitExtractDir, "git", o.GitExtractDir, "Check out the sources that created this release into the provided dir. Repos will be created at <dir>/<host>/<path>. Requires 'git' on your path.")
69+
flags.BoolVar(&o.Tools, "tools", o.Tools, "Extract the tools archives from the release image. Implies --command=*")
70+
71+
flags.StringVar(&o.Command, "command", o.Command, "Specify 'oc' or 'openshift-install' to extract the client for your operating system.")
72+
flags.StringVar(&o.CommandOperatingSystem, "command-os", o.CommandOperatingSystem, "Override which operating system command is extracted (mac, windows, linux). You map specify '*' to extract all tool archives.")
6573
return cmd
6674
}
6775

@@ -70,6 +78,10 @@ type ExtractOptions struct {
7078

7179
From string
7280

81+
Tools bool
82+
Command string
83+
CommandOperatingSystem string
84+
7385
// GitExtractDir is the path of a root directory to extract the source of a release to.
7486
GitExtractDir string
7587

@@ -118,19 +130,38 @@ func (o *ExtractOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args [
118130
}
119131

120132
func (o *ExtractOptions) Run() error {
121-
if len(o.From) == 0 {
122-
return fmt.Errorf("must specify an image containing a release payload with --from")
133+
sources := 0
134+
if o.Tools {
135+
sources++
123136
}
124-
if o.Directory != "." && len(o.File) > 0 {
125-
return fmt.Errorf("only one of --to and --file may be set")
137+
if len(o.File) > 0 {
138+
sources++
139+
}
140+
if len(o.Command) > 0 {
141+
sources++
126142
}
127-
128143
if len(o.GitExtractDir) > 0 {
144+
sources++
145+
}
146+
147+
switch {
148+
case sources > 1:
149+
return fmt.Errorf("only one of --tools, --command, --file, or --git may be specified")
150+
case len(o.From) == 0:
151+
return fmt.Errorf("must specify an image containing a release payload with --from")
152+
case o.Directory != "." && len(o.File) > 0:
153+
return fmt.Errorf("only one of --to and --file may be set")
154+
155+
case len(o.GitExtractDir) > 0:
129156
return o.extractGit(o.GitExtractDir)
157+
case o.Tools:
158+
return o.extractTools()
159+
case len(o.Command) > 0:
160+
return o.extractCommand(o.Command)
130161
}
131162

132163
dir := o.Directory
133-
if err := os.MkdirAll(dir, 0755); err != nil {
164+
if err := os.MkdirAll(dir, 0777); err != nil {
134165
return err
135166
}
136167

@@ -200,7 +231,7 @@ func (o *ExtractOptions) Run() error {
200231
}
201232

202233
func (o *ExtractOptions) extractGit(dir string) error {
203-
if err := os.MkdirAll(dir, 0750); err != nil {
234+
if err := os.MkdirAll(dir, 0777); err != nil {
204235
return err
205236
}
206237

0 commit comments

Comments
 (0)