Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 42 additions & 22 deletions pkg/cli/admin/release/extract_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ import (

// extractTarget describes how a file in the release image can be extracted to disk.
type extractTarget struct {
OS string
Command string
OS string
Command string
Optional bool

TargetName string

Expand Down Expand Up @@ -189,6 +190,16 @@ func (o *ExtractOptions) extractCommand(command string) error {
InjectReleaseImage: true,
ArchiveFormat: "openshift-install-linux-%s.tar.gz",
},
{
OS: "linux",
Command: "openshift-baremetal-install",
Optional: true,
Mapping: extract.Mapping{Image: "baremetal-installer", From: "usr/bin/openshift-install"},

Readme: readmeInstallUnix,
InjectReleaseImage: true,
ArchiveFormat: "openshift-baremetal-install-linux-%s.tar.gz",
},
}

currentOS := runtime.GOOS
Expand All @@ -199,36 +210,45 @@ func (o *ExtractOptions) extractCommand(command string) error {
currentOS = "darwin"
}

// select the subset of targets based on command line input
// Select the subset of targets based on command line input
var willArchive bool
var targets []extractTarget

// Filter by command, or gather all non-optional targets
if len(command) > 0 {
hasCommand := false
for _, target := range availableTargets {
if target.Command != command {
continue
}
hasCommand = true
if target.OS == currentOS || currentOS == "*" {
targets = []extractTarget{target}
break
if target.Command == command {
targets = append(targets, target)
}
}
if len(targets) == 0 {
if hasCommand {
return fmt.Errorf("command %q does not support the operating system %q", o.Command, currentOS)
} else {
for _, target := range availableTargets {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ideal outcome is:

oc adm release extract —tools

Doesn’t include it, but

oc adm release extract —command openshift-baremetal-installer

Extracts the binary

oc adm release extract —command openshift-baremetal-installer —command-os=*

Creates an archive.

Hence the suggestion for optional - the explicit request overrides optional, rather than the current behavior here with always excluding from archive.

if !target.Optional {
targets = append(targets, target)
}
return fmt.Errorf("the supported commands are 'oc' and 'openshift-install'")
}
} else {
willArchive = true
targets = availableTargets
}

// If the user didn't specify a command, or the operating system is set
// to '*', we'll produce an archive
if len(command) == 0 || o.CommandOperatingSystem == "*" {
for i := range targets {
targets[i].AsArchive = true
targets[i].AsZip = targets[i].OS == "windows"
}
}

if len(targets) == 0 {
switch {
case len(command) > 0 && currentOS != "*":
return fmt.Errorf("command %q does not support the operating system %q", o.Command, currentOS)
case len(command) > 0:
return fmt.Errorf("the supported commands are 'oc' and 'openshift-install'")
default:
return fmt.Errorf("no available commands")
}
}

var hashFn = sha256.New
var signer *openpgp.Entity
if willArchive && len(o.SigningKey) > 0 {
Expand Down Expand Up @@ -305,7 +325,7 @@ func (o *ExtractOptions) extractCommand(command string) error {
target.Mapping.Name = fmt.Sprintf(target.ArchiveFormat, releaseName)
target.Mapping.To = filepath.Join(dir, target.Mapping.Name)
} else {
target.Mapping.To = filepath.Join(dir, filepath.Base(target.Mapping.From))
target.Mapping.To = filepath.Join(dir, target.Command)
target.Mapping.Name = fmt.Sprintf("%s-%s", target.OS, target.Command)
}
validTargets = append(validTargets, target)
Expand Down Expand Up @@ -398,7 +418,7 @@ func (o *ExtractOptions) extractCommand(command string) error {

zh := &zip.FileHeader{
Method: zip.Deflate,
Name: hdr.Name,
Name: target.Command + ".exe",
UncompressedSize64: uint64(hdr.Size),
Modified: hdr.ModTime,
}
Expand Down Expand Up @@ -436,7 +456,7 @@ func (o *ExtractOptions) extractCommand(command string) error {
}

if err := tw.WriteHeader(&tar.Header{
Name: hdr.Name,
Name: target.Command,
Mode: int64(os.FileMode(0755).Perm()),
Size: hdr.Size,
Typeflag: tar.TypeReg,
Expand All @@ -454,7 +474,7 @@ func (o *ExtractOptions) extractCommand(command string) error {
Size: 0,
Typeflag: tar.TypeLink,
ModTime: hdr.ModTime,
Linkname: hdr.Name,
Linkname: target.Command,
}); err != nil {
return err
}
Expand Down