From e17fb41eef6638be9bf0f76271885e9a603d0ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Thu, 4 Jan 2024 09:42:12 +0300 Subject: [PATCH 1/5] Skip release-arch and arch type collision per command --- pkg/cli/admin/release/extract_tools.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index 869db525d1..c9f73be445 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -499,6 +499,7 @@ func (o *ExtractOptions) extractCommand(command string) error { } exactReleaseImage := refExact.String() + targetArchCommands := make(map[string]struct{}) // resolve target image references to their pull specs missing := sets.NewString() var validTargets []extractTarget @@ -513,9 +514,23 @@ func (o *ExtractOptions) extractCommand(command string) error { continue } } + + if target.Arch == targetReleaseArch { + targetArchCommands[target.Command] = struct{}{} + } + if target.OS == "linux" && target.Arch == releaseArch { - klog.V(2).Infof("Skipping duplicate %s", target.ArchiveFormat) - continue + if _, ok := targetArchCommands[target.Command]; ok { + // Some target commands have release-arch types that defines extracting + // the command in whatever release architecture type is set(e.g. linux/amd64) + // But there is also another target type for these commands specifically set to + // each architecture type(linux/amd64, linux/arm64) and it is expected that + // one of these arch types collide with release-arch type. Thus, + // to prevent duplicate extraction, we have to skip the one colliding with release-arch type. + // However, we need to skip per command name because some command may not have release-arch type. + klog.V(2).Infof("Skipping duplicate %s", target.ArchiveFormat) + continue + } } spec, err := findImageSpec(release.References, target.Mapping.Image, o.From) if err != nil && !target.NewArch { From 129da4848700fb8ca6541739cfe3484684ed5cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Thu, 4 Jan 2024 10:14:50 +0300 Subject: [PATCH 2/5] Add RHEL9 oc as linux command in target list --- pkg/cli/admin/release/extract_tools.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index c9f73be445..76fa183a02 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -265,6 +265,17 @@ func (o *ExtractOptions) extractCommand(command string) error { InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-amd64-%s.tar.gz", }, + { + OS: "linux", + Arch: "amd64", + Command: "oc.rhel9", + Mapping: extract.Mapping{Image: "cli-artifacts", From: "usr/share/openshift/linux_amd64/oc.rhel9"}, + + LinkTo: []string{"kubectl"}, + Readme: readmeCLIUnix, + InjectReleaseVersion: true, + ArchiveFormat: "openshift-client-linux-amd64-rhel9-%s.tar.gz", + }, { OS: "linux", Arch: "arm64", @@ -277,6 +288,18 @@ func (o *ExtractOptions) extractCommand(command string) error { InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-arm64-%s.tar.gz", }, + { + OS: "linux", + Arch: "arm64", + Command: "oc.rhel9", + NewArch: true, + Mapping: extract.Mapping{Image: "cli-artifacts", From: "usr/share/openshift/linux_arm64/oc.rhel9"}, + + LinkTo: []string{"kubectl"}, + Readme: readmeCLIUnix, + InjectReleaseVersion: true, + ArchiveFormat: "openshift-client-linux-arm64-rhel9-%s.tar.gz", + }, { OS: "windows", Arch: "amd64", From 701015934c4ee2a49567dd7f385ce16fdad2ebaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Thu, 4 Jan 2024 10:21:21 +0300 Subject: [PATCH 3/5] Generate RHEL8 based oc and add as target to extract --- images/cli-artifacts/Dockerfile.rhel | 4 ++++ pkg/cli/admin/release/extract_tools.go | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/images/cli-artifacts/Dockerfile.rhel b/images/cli-artifacts/Dockerfile.rhel index 903256fb02..65353d7f99 100644 --- a/images/cli-artifacts/Dockerfile.rhel +++ b/images/cli-artifacts/Dockerfile.rhel @@ -18,6 +18,10 @@ RUN cd /usr/share/openshift && \ ln -sf /usr/share/openshift/linux_$(uname -m | sed 's/aarch64/arm64/;s/x86_64/amd64/')/oc /usr/bin/oc && \ mv windows_amd64 windows && mv darwin_amd64 mac && mv darwin_arm64 mac_arm64 +RUN ln -sf /usr/share/openshift/linux_amd64/oc /usr/share/openshift/linux_amd64/oc.rhel8 +RUN ln -sf /usr/share/openshift/linux_arm64/oc /usr/share/openshift/linux_arm64/oc.rhel8 +RUN ln -sf /usr/share/openshift/linux_ppc64le/oc /usr/share/openshift/linux_ppc64le/oc.rhel8 + COPY --from=builder-rhel-9 /go/src/github.com/openshift/oc/_output/bin/linux_amd64/oc /usr/share/openshift/linux_amd64/oc.rhel9 COPY --from=builder-rhel-9 /go/src/github.com/openshift/oc/_output/bin/linux_arm64/oc /usr/share/openshift/linux_arm64/oc.rhel9 COPY --from=builder-rhel-9 /go/src/github.com/openshift/oc/_output/bin/linux_ppc64le/oc /usr/share/openshift/linux_ppc64le/oc.rhel9 diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index 76fa183a02..86f8bf0f8d 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -276,6 +276,17 @@ func (o *ExtractOptions) extractCommand(command string) error { InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-amd64-rhel9-%s.tar.gz", }, + { + OS: "linux", + Arch: "amd64", + Command: "oc.rhel8", + Mapping: extract.Mapping{Image: "cli-artifacts", From: "usr/share/openshift/linux_amd64/oc.rhel8"}, + + LinkTo: []string{"kubectl"}, + Readme: readmeCLIUnix, + InjectReleaseVersion: true, + ArchiveFormat: "openshift-client-linux-amd64-rhel8-%s.tar.gz", + }, { OS: "linux", Arch: "arm64", @@ -300,6 +311,18 @@ func (o *ExtractOptions) extractCommand(command string) error { InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-arm64-rhel9-%s.tar.gz", }, + { + OS: "linux", + Arch: "arm64", + Command: "oc.rhel8", + NewArch: true, + Mapping: extract.Mapping{Image: "cli-artifacts", From: "usr/share/openshift/linux_arm64/oc.rhel8"}, + + LinkTo: []string{"kubectl"}, + Readme: readmeCLIUnix, + InjectReleaseVersion: true, + ArchiveFormat: "openshift-client-linux-arm64-rhel8-%s.tar.gz", + }, { OS: "windows", Arch: "amd64", From 10b06af48a34072b8d47ae90fb3100d06fba3105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Fri, 5 Jan 2024 09:41:25 +0300 Subject: [PATCH 4/5] Allow extracted binary name can be set to different --- pkg/cli/admin/release/extract_tools.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index 86f8bf0f8d..dd48359ab5 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -58,11 +58,12 @@ type extractTarget struct { InjectReleaseVersion bool SignMachOBinary bool - ArchiveFormat string - AsArchive bool - AsZip bool - Readme string - LinkTo []string + ArchiveFormat string + AsArchive bool + AsZip bool + Readme string + LinkTo []string + TargetCommandName string Mapping extract.Mapping } @@ -275,6 +276,7 @@ func (o *ExtractOptions) extractCommand(command string) error { Readme: readmeCLIUnix, InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-amd64-rhel9-%s.tar.gz", + TargetCommandName: "oc", }, { OS: "linux", @@ -286,6 +288,7 @@ func (o *ExtractOptions) extractCommand(command string) error { Readme: readmeCLIUnix, InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-amd64-rhel8-%s.tar.gz", + TargetCommandName: "oc", }, { OS: "linux", @@ -310,6 +313,7 @@ func (o *ExtractOptions) extractCommand(command string) error { Readme: readmeCLIUnix, InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-arm64-rhel9-%s.tar.gz", + TargetCommandName: "oc", }, { OS: "linux", @@ -322,6 +326,7 @@ func (o *ExtractOptions) extractCommand(command string) error { Readme: readmeCLIUnix, InjectReleaseVersion: true, ArchiveFormat: "openshift-client-linux-arm64-rhel8-%s.tar.gz", + TargetCommandName: "oc", }, { OS: "windows", @@ -590,6 +595,11 @@ func (o *ExtractOptions) extractCommand(command string) error { } target.Mapping.Image = spec target.Mapping.ImageRef = imagesource.TypedImageReference{Ref: ref, Type: imagesource.DestinationRegistry} + // if the name of the extracted binary is set to different from the + // actual command name, we set it to new target command name. + if target.TargetCommandName != "" { + target.Command = target.TargetCommandName + } if target.AsArchive { willArchive = true target.Mapping.Name = fmt.Sprintf(target.ArchiveFormat, releaseName) From 06d13215888e0ba3ed6ee37a44e9df8f7a0df06b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Mon, 8 Jan 2024 10:56:35 +0300 Subject: [PATCH 5/5] Skip rhel9 binary not found error for older releases --- pkg/cli/admin/release/extract_tools.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/cli/admin/release/extract_tools.go b/pkg/cli/admin/release/extract_tools.go index dd48359ab5..2dc66acdf4 100644 --- a/pkg/cli/admin/release/extract_tools.go +++ b/pkg/cli/admin/release/extract_tools.go @@ -901,6 +901,13 @@ func (o *ExtractOptions) extractCommand(command string) error { if target.NewArch { continue } + if command == "" && (strings.Contains(target.Mapping.From, "rhel9") || strings.Contains(target.Mapping.From, "rhel8")) { + // if user explicitly wants to extract oc.rhel9(or installer.rhel9) via --command=oc.rhel9 and + // if release does not have this binary, we can safely return error. + // On the other hand, if user wants to extract all the tooling in older versions via --tools flag, + // we shouldn't print any error indicating that oc.rhel9 does not exist in this release payload. + continue + } missing = append(missing, target.Mapping.From) } sort.Strings(missing)