From b7b5ed1c06d1718c1bfc73b2a78bd46c39c11779 Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Thu, 15 Aug 2019 08:59:30 -0400 Subject: [PATCH 1/3] pkg/cli/admin/release: extract to target command not source When extracting commands from a release, the command is typically the same as the source executable in the image, however if that is not the case - for example, in the case of the baremetal installer, oc does the wrong thing. If the command is `openshift-baremetal-installer` but it is extracted from `usr/bin/openshift-installer`, oc extracts the file as openshift-installer. --- pkg/cli/admin/release/extract_tools.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index aebb4d6c2f..588ac29a0c 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -305,7 +305,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) @@ -398,7 +398,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, } @@ -436,7 +436,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, @@ -454,7 +454,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 } From 60a4fc10a14da0cbd92c04325a456867bc3b8eae Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Tue, 13 Aug 2019 21:03:48 -0400 Subject: [PATCH 2/3] pkg/cli/admin/release: use archive with --command-os='*' When specifying --command-os='*' and --command, we should use an archive as there can be more than one result. This previously didn't work. --- pkg/cli/admin/release/extract_tools.go | 41 +++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index 588ac29a0c..5734828e24 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -199,36 +199,43 @@ 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) - } - return fmt.Errorf("the supported commands are 'oc' and 'openshift-install'") - } } else { - willArchive = true - targets = availableTargets + for _, target := range availableTargets { + 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 { From 2449822067c4127f1065e5b4df30e1add750586b Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Tue, 13 Aug 2019 21:03:48 -0400 Subject: [PATCH 3/3] pkg/cli/admin/release: support extracting baremetal installer The installer for baremetal is in a separate image as part of the release, we need to provide awareness to the `oc` command so we can actually extract the installer. This also introduces the concept of an 'optional' command that is not extracted when using --tools. --- pkg/cli/admin/release/extract_tools.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index 5734828e24..dbf5b92c7a 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -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 @@ -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 @@ -212,7 +223,9 @@ func (o *ExtractOptions) extractCommand(command string) error { } } else { for _, target := range availableTargets { - targets = availableTargets + if !target.Optional { + targets = append(targets, target) + } } }