Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to upgrade the cluster via the new binary #684

Merged
merged 96 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
0ba8dac
Airgap updates via CLI
sgalsaleh Jun 24, 2024
25038ff
update messages
sgalsaleh Jun 24, 2024
972b6ce
alpha build
sgalsaleh Jun 26, 2024
4db5744
update url
sgalsaleh Jun 26, 2024
fbf2b6d
feat: ability to upgrade the cluster
emosbaugh Jun 10, 2024
14c5971
test
emosbaugh Jun 26, 2024
5a8277e
f
emosbaugh Jun 26, 2024
2b66075
f
emosbaugh Jun 26, 2024
c29ae26
f
emosbaugh Jun 26, 2024
2541155
f
emosbaugh Jun 26, 2024
d31b22a
f
emosbaugh Jun 26, 2024
e52617f
quiet aws s3 cp
emosbaugh Jun 26, 2024
b5b4c39
f
emosbaugh Jun 26, 2024
ec38204
f
emosbaugh Jun 26, 2024
ef08533
correct commit sha
emosbaugh Jun 26, 2024
e0805ed
correct commit sha
emosbaugh Jun 26, 2024
1499c9e
correct commit sha
emosbaugh Jun 27, 2024
46edb59
f
emosbaugh Jun 27, 2024
acfb91a
change version
emosbaugh Jun 27, 2024
aaa21c3
f
emosbaugh Jun 27, 2024
4611322
f
emosbaugh Jun 27, 2024
5605515
f
emosbaugh Jun 27, 2024
e807fdd
f
emosbaugh Jun 27, 2024
07492b2
d
emosbaugh Jun 27, 2024
db9baad
d
emosbaugh Jun 27, 2024
bffa9e0
f
emosbaugh Jun 27, 2024
63633cf
f
emosbaugh Jun 27, 2024
f36109d
f
emosbaugh Jun 27, 2024
cb9a343
f
emosbaugh Jun 27, 2024
fba9a86
f
emosbaugh Jun 27, 2024
0c77f38
f
emosbaugh Jun 28, 2024
db2c997
f
emosbaugh Jun 28, 2024
4a1d6a0
f
emosbaugh Jul 1, 2024
a200f7c
f
emosbaugh Jul 1, 2024
9b91041
f
emosbaugh Jul 1, 2024
ef1593e
f
emosbaugh Jul 1, 2024
d6b51c1
f
emosbaugh Jul 3, 2024
a599016
f
emosbaugh Jul 3, 2024
872b747
f
emosbaugh Jul 3, 2024
0ba3fed
kots ec1 nightly build
sgalsaleh Jul 8, 2024
fee2922
kots ec2 nightly build
sgalsaleh Jul 8, 2024
8407584
kots ec1 nightly build - kurl proxy fix
sgalsaleh Jul 8, 2024
c9820a4
kots ec2 nightly build
sgalsaleh Jul 8, 2024
da3bd2d
kots v2024.7.8-ec5-nightly
sgalsaleh Jul 8, 2024
db6359d
kots v2024.7.8-ec6-nightly
sgalsaleh Jul 8, 2024
a209094
kots v2024.7.8-ec7-nightly
sgalsaleh Jul 8, 2024
b7d2148
kots v2024.7.8-ec8-nightly
sgalsaleh Jul 9, 2024
7fb2a46
operator 0.39.0-build.2
sgalsaleh Jul 9, 2024
52490d3
upgrade test
emosbaugh Jul 9, 2024
1dc044e
upgrade test
emosbaugh Jul 9, 2024
1eb72d9
upgrade test
emosbaugh Jul 9, 2024
1ab5725
upgrade test
emosbaugh Jul 10, 2024
de091de
upgrade test
emosbaugh Jul 10, 2024
4ae28e7
upgrade test
emosbaugh Jul 10, 2024
4a0f4d2
upgrade test
emosbaugh Jul 10, 2024
09da2d1
upgrade test
emosbaugh Jul 10, 2024
c7c30dc
upgrade test
emosbaugh Jul 10, 2024
9954613
upgrade test
emosbaugh Jul 10, 2024
9800053
f
emosbaugh Jul 10, 2024
542b1fd
f
emosbaugh Jul 10, 2024
abf6e2a
f
emosbaugh Jul 10, 2024
02ad14c
f
emosbaugh Jul 10, 2024
69a7648
f
emosbaugh Jul 10, 2024
8805150
f
emosbaugh Jul 10, 2024
6776b1c
f
emosbaugh Jul 10, 2024
c8b6f1c
f
emosbaugh Jul 10, 2024
9486ba4
f
emosbaugh Jul 10, 2024
0ffe8e4
add k0s images dir to host support bundle collector
laverya Jul 11, 2024
db700cb
bump previous k0s version to be the latest 1.28 patch
laverya Jul 11, 2024
28e711d
second to latest 1.28 patch
laverya Jul 12, 2024
f14edac
back to 1.28.10
laverya Jul 12, 2024
22e8b9b
test reset and reinstall
laverya Jul 12, 2024
f88c16b
f
laverya Jul 12, 2024
6aa6d14
call playwright setup again after resetting instance
laverya Jul 12, 2024
c8ad5bd
reenable all tests
laverya Jul 12, 2024
bcbd7b3
add TestSingleNodeInstallationNoopUpgrade test
laverya Jul 12, 2024
61efe0e
operator image override
laverya Jul 12, 2024
94ce10b
refine playwright tests
sgalsaleh Jul 12, 2024
b6c0471
use version from env var
sgalsaleh Jul 12, 2024
9b88c55
skip cluster update modal for noop test
sgalsaleh Jul 12, 2024
53148e4
skip cluster update modal for noop test
sgalsaleh Jul 12, 2024
e1df3d5
handle unbound SKIP_CLUSTER_UPGRADE_CHECK variable
laverya Jul 12, 2024
6d581eb
fix unbound variable
sgalsaleh Jul 12, 2024
ff222cd
use ttl.sh kotsadm image
sgalsaleh Jul 12, 2024
c959f7c
override kots binary
sgalsaleh Jul 13, 2024
e9b406d
fix operator image and timeout
sgalsaleh Jul 13, 2024
6803208
use correct locator
sgalsaleh Jul 13, 2024
9e12856
use official operator/kots releases
sgalsaleh Jul 16, 2024
c3c7747
fix Makefile
sgalsaleh Jul 16, 2024
28c7a33
remove v
sgalsaleh Jul 16, 2024
d98405c
print kots version
sgalsaleh Jul 16, 2024
ae232ea
debug operator tarball
sgalsaleh Jul 16, 2024
27952b4
operator 0.40.1
sgalsaleh Jul 16, 2024
babbfaf
add EMBEDDED_OPERATOR_BINARY_URL_OVERRIDE =
sgalsaleh Jul 16, 2024
ddc35a4
operator 0.40.2
sgalsaleh Jul 16, 2024
5a8edc1
kots 1.112.1
sgalsaleh Jul 16, 2024
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
5 changes: 3 additions & 2 deletions .github/actions/e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ runs:
- name: E2E
shell: bash
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha || github.sha }}
export SHORT_SHA=dev-${SHA::7}
export LICENSE_ID=${{ inputs.license-id }}
export AIRGAP_LICENSE_ID=${{ inputs.airgap-license-id }}
export SNAPSHOT_LICENSE_ID=${{ inputs.snapshot-license-id }}
Expand All @@ -109,7 +110,7 @@ runs:
if: ${{ failure() }}
with:
name: ${{ inputs.test-name }}-support-bundle-host.tar.gz
path: ./e2e/support-bundle-host.tar.gz
path: ./e2e/support-bundle-host-*.tar.gz
- name: Upload Cluster Support Bundle
uses: actions/upload-artifact@v4
if: ${{ failure() }}
Expand Down
23 changes: 16 additions & 7 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,17 @@ jobs:

- name: Build and push local-artifact-mirror image
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}"
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}-previous-k0s"
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}-upgrade"

- name: Build Linux AMD64 and Output Metadata
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
make -B embedded-cluster-linux-amd64 K0S_VERSION=$(make print-PREVIOUS_K0S_VERSION) K0S_BINARY_SOURCE_OVERRIDE=$(make print-PREVIOUS_K0S_BINARY_SOURCE_OVERRIDE) VERSION="${SHORT_SHA}-previous-k0s"
tar -C output/bin -czvf embedded-cluster-linux-amd64-previous-k0s.tgz embedded-cluster
Expand All @@ -98,7 +100,8 @@ jobs:
REPLICATED_API_TOKEN: ${{ secrets.STAGING_REPLICATED_API_TOKEN }}
REPLICATED_API_ORIGIN: "https://api.staging.replicated.com/vendor"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
echo "${SHORT_SHA}"
sed -i "s/__version_string__/${SHORT_SHA}/g" e2e/kots-release-install/cluster-config.yaml
sed -i "s/__version_string__/${SHORT_SHA}-upgrade/g" e2e/kots-release-upgrade/cluster-config.yaml
Expand All @@ -107,10 +110,12 @@ jobs:
replicated release promote 807 2cHXb1RCttzpR0xvnNWyaZCgDBP --version "appver-${SHORT_SHA}-pre-minio-removal"

replicated release create --yaml-dir e2e/kots-release-install --promote CI --version "appver-${SHORT_SHA}"
replicated release create --yaml-dir e2e/kots-release-install --promote CI --version "appver-${SHORT_SHA}-noop"
replicated release create --yaml-dir e2e/kots-release-upgrade --promote CI --version "appver-${SHORT_SHA}-upgrade"
- name: Build CI binary
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
echo "# channel release object" > e2e/kots-release-install/release.yaml
echo 'channelID: "2cHXb1RCttzpR0xvnNWyaZCgDBP"' >> e2e/kots-release-install/release.yaml
Expand All @@ -129,7 +134,8 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_EMBEDDED_CLUSTER_UPLOAD_IAM_SECRET }}
AWS_REGION: "us-east-1"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
export EC_VERSION="v${SHORT_SHA}"
./scripts/cache-files.sh
./scripts/create-upgrade-release.sh
Expand All @@ -141,7 +147,8 @@ jobs:
REPLICATED_API_TOKEN: ${{ secrets.STAGING_REPLICATED_API_TOKEN }}
REPLICATED_API_ORIGIN: "https://api.staging.replicated.com/vendor"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}
echo "${SHORT_SHA}"
rm e2e/kots-release-install/release.yaml
replicated release create --yaml-dir e2e/kots-release-install --promote CI-airgap --version "appver-${SHORT_SHA}"
Expand All @@ -154,7 +161,8 @@ jobs:

- name: Create download link message text
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
SHA=${{ github.event.pull_request.head.sha }}
export SHORT_SHA=dev-${SHA::7}

echo "This PR has been released (on staging) and is available for download with a embedded-cluster-smoke-test-staging-app [license ID](https://vendor.staging.replicated.com/apps/embedded-cluster-smoke-test-staging-app/customers?sort=name-asc)." > download-link.txt
echo "" >> download-link.txt
Expand Down Expand Up @@ -227,6 +235,7 @@ jobs:
- TestMultiNodeAirgapHADisasterRecovery
- TestCustomCIDR
- TestProxiedCustomCIDR
- TestSingleNodeInstallationNoopUpgrade
include:
- test: TestMultiNodeAirgapUpgrade
runner: embedded-cluster
Expand Down
14 changes: 8 additions & 6 deletions .github/workflows/release-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ jobs:

- name: Build and push local-artifact-mirror image
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
Copy link
Member

Choose a reason for hiding this comment

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

this should match what's in the pull-request.yaml version of things

Copy link
Member

Choose a reason for hiding this comment

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

can't use the same thing here though as github.event.pull_request.head.sha doesn't apply here, no?

Copy link
Member

Choose a reason for hiding this comment

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

i guess we could use GITHUB_SHA in pull-request.yaml?

export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}"
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}-previous-k0s"
make build-and-push-local-artifact-mirror-image VERSION="${SHORT_SHA}-upgrade"

- name: Build Linux AMD64 and Output Metadata
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
make -B embedded-cluster-linux-amd64 K0S_VERSION=$(make print-PREVIOUS_K0S_VERSION) K0S_BINARY_SOURCE_OVERRIDE=$(make print-PREVIOUS_K0S_BINARY_SOURCE_OVERRIDE) VERSION="${SHORT_SHA}-previous-k0s"
tar -C output/bin -czvf embedded-cluster-linux-amd64-previous-k0s.tgz embedded-cluster
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
REPLICATED_API_TOKEN: ${{ secrets.STAGING_REPLICATED_API_TOKEN }}
REPLICATED_API_ORIGIN: "https://api.staging.replicated.com/vendor"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
echo "${SHORT_SHA}"
sed -i "s/__version_string__/${SHORT_SHA}/g" e2e/kots-release-install/cluster-config.yaml
sed -i "s/__version_string__/${SHORT_SHA}-upgrade/g" e2e/kots-release-upgrade/cluster-config.yaml
Expand All @@ -83,10 +83,11 @@ jobs:
replicated release promote 807 2cHXb1RCttzpR0xvnNWyaZCgDBP --version "appver-${SHORT_SHA}-pre-minio-removal"

replicated release create --yaml-dir e2e/kots-release-install --promote CI --version "appver-${SHORT_SHA}"
replicated release create --yaml-dir e2e/kots-release-install --promote CI --version "appver-${SHORT_SHA}-noop"
replicated release create --yaml-dir e2e/kots-release-upgrade --promote CI --version "appver-${SHORT_SHA}-upgrade"
- name: Build CI binary
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
export LOCAL_ARTIFACT_MIRROR_IMAGE=registry.staging.replicated.com/library/embedded-cluster-local-artifact-mirror
echo "# channel release object" > e2e/kots-release-install/release.yaml
echo 'channelID: "2cHXb1RCttzpR0xvnNWyaZCgDBP"' >> e2e/kots-release-install/release.yaml
Expand All @@ -105,7 +106,7 @@ jobs:
AWS_SECRET_ACCESS_KEY: ${{ secrets.STAGING_EMBEDDED_CLUSTER_UPLOAD_IAM_SECRET }}
AWS_REGION: "us-east-1"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
export EC_VERSION="v${SHORT_SHA}"
./scripts/cache-files.sh
./scripts/create-upgrade-release.sh
Expand All @@ -116,7 +117,7 @@ jobs:
REPLICATED_API_TOKEN: ${{ secrets.STAGING_REPLICATED_API_TOKEN }}
REPLICATED_API_ORIGIN: "https://api.staging.replicated.com/vendor"
run: |
export SHORT_SHA=dev-$(git rev-parse --short=7 HEAD)
export SHORT_SHA=dev-${GITHUB_SHA::7}
echo "${SHORT_SHA}"
rm e2e/kots-release-install/release.yaml
replicated release create --yaml-dir e2e/kots-release-install --promote CI-airgap --version "appver-${SHORT_SHA}"
Expand Down Expand Up @@ -179,6 +180,7 @@ jobs:
- TestMultiNodeAirgapHADisasterRecovery
- TestCustomCIDR
- TestProxiedCustomCIDR
- TestSingleNodeInstallationNoopUpgrade
include:
- test: TestMultiNodeAirgapUpgrade
runner: embedded-cluster
Expand Down
18 changes: 12 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ UNAME := $(shell uname)
ARCH := $(shell uname -m)
APP_NAME = embedded-cluster
ADMIN_CONSOLE_CHART_REPO_OVERRIDE =
ADMIN_CONSOLE_CHART_VERSION = 1.111.0
ADMIN_CONSOLE_CHART_VERSION = 1.112.1
ADMIN_CONSOLE_IMAGE_OVERRIDE =
ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE =
EMBEDDED_OPERATOR_CHART_URL = oci://registry.replicated.com/library
EMBEDDED_OPERATOR_CHART_NAME = embedded-cluster-operator
EMBEDDED_OPERATOR_CHART_VERSION = 0.36.5
ADMIN_CONSOLE_KURL_PROXY_IMAGE_OVERRIDE =
EMBEDDED_OPERATOR_CHART_VERSION = 0.40.2
EMBEDDED_OPERATOR_BINARY_URL_OVERRIDE =
EMBEDDED_OPERATOR_UTILS_IMAGE = busybox:1.36.1
EMBEDDED_CLUSTER_OPERATOR_IMAGE_OVERRIDE =
OPENEBS_CHART_VERSION = 4.1.0
Expand All @@ -22,7 +22,7 @@ VELERO_AWS_PLUGIN_IMAGE_VERSION = v1.9.2
KUBECTL_VERSION = v1.30.1
K0S_VERSION = v1.29.5+k0s.0-ec.0
K0S_GO_VERSION = v1.29.5+k0s.0
PREVIOUS_K0S_VERSION ?= v1.28.8+k0s.0
PREVIOUS_K0S_VERSION ?= v1.28.10+k0s.0
K0S_BINARY_SOURCE_OVERRIDE = https://ec-k0s-binaries.s3.amazonaws.com/k0s-v1.29.5%2Bk0s.0-ec.0
PREVIOUS_K0S_BINARY_SOURCE_OVERRIDE =
TROUBLESHOOT_VERSION = v0.93.1
Expand All @@ -39,6 +39,7 @@ LD_FLAGS = -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sVersion=$
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.Version=$(ADMIN_CONSOLE_CHART_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.ImageOverride=$(ADMIN_CONSOLE_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.MigrationsImageOverride=$(ADMIN_CONSOLE_MIGRATIONS_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.KurlProxyImageOverride=$(ADMIN_CONSOLE_KURL_PROXY_IMAGE_OVERRIDE) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole.KotsVersion=$(KOTS_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator.Version=$(EMBEDDED_OPERATOR_CHART_VERSION) \
-X github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator.UtilsImage=$(EMBEDDED_OPERATOR_UTILS_IMAGE) \
Expand Down Expand Up @@ -181,7 +182,7 @@ print-%:

.PHONY: build-local-artifact-mirror-image
build-local-artifact-mirror-image:
docker build -t $(LOCAL_ARTIFACT_MIRROR_IMAGE_LOCATION) -f Dockerfile .
docker build --platform linux/amd64 -t $(LOCAL_ARTIFACT_MIRROR_IMAGE_LOCATION) -f deploy/local-artifact-mirror/Dockerfile .

.PHONY: push-local-artifact-mirror-image
push-local-artifact-mirror-image:
Expand All @@ -193,3 +194,8 @@ build-and-push-local-artifact-mirror-image: build-local-artifact-mirror-image pu
.PHONY: buildtools
buildtools:
go build -o ./output/bin/buildtools ./cmd/buildtools

.PHONY: cache-files
cache-files: export EMBEDDED_OPERATOR_BINARY_URL_OVERRIDE
cache-files:
./scripts/cache-files.sh
2 changes: 1 addition & 1 deletion cmd/embedded-cluster/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var updateCommand = &cli.Command{
return fmt.Errorf("no channel release found")
}

if err := kotscli.UpstreamUpgrade(kotscli.UpstreamUpgradeOptions{
if err := kotscli.AirgapUpdate(kotscli.AirgapUpdateOptions{
AppSlug: rel.AppSlug,
Namespace: defaults.KotsadmNamespace,
AirgapBundle: c.String("airgap-bundle"),
Expand Down
60 changes: 53 additions & 7 deletions cmd/local-artifact-mirror/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package main
import (
"bytes"
"context"
"encoding/base64"
"fmt"
"os"
"os/exec"
"path/filepath"

"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -197,14 +200,15 @@ var binariesCommand = &cli.Command{
},
}

// fetchAndValidateInstallation fetches an Installation object from its name and
// checks if it is valid for an airgap cluster deployment.
// fetchAndValidateInstallation fetches an Installation object from its name or directly decodes it
// and checks if it is valid for an airgap cluster deployment.
func fetchAndValidateInstallation(ctx context.Context, iname string) (*v1beta1.Installation, error) {
logrus.Infof("reading installation %q", iname)
nsn := types.NamespacedName{Name: iname}
var in v1beta1.Installation
if err := kubecli.Get(ctx, nsn, &in); err != nil {
return nil, fmt.Errorf("unable to get installation: %w", err)
in, err := decodeInstallation(ctx, iname)
if err != nil {
in, err = fetchInstallationFromCluster(ctx, iname)
if err != nil {
return nil, err
}
}

if !in.Spec.AirGap {
Expand All @@ -213,5 +217,47 @@ func fetchAndValidateInstallation(ctx context.Context, iname string) (*v1beta1.I
return nil, fmt.Errorf("installation has no artifacts")
}

return in, nil
}

// fetchInstallationFromCluster fetches an Installation object from the cluster.
func fetchInstallationFromCluster(ctx context.Context, iname string) (*v1beta1.Installation, error) {
logrus.Infof("reading installation from cluster %q", iname)

nsn := types.NamespacedName{Name: iname}
var in v1beta1.Installation
if err := kubecli.Get(ctx, nsn, &in); err != nil {
return nil, fmt.Errorf("unable to get installation: %w", err)
}

return &in, nil
}

// decodeInstallation decodes an Installation object from a string.
func decodeInstallation(ctx context.Context, data string) (*v1beta1.Installation, error) {
logrus.Info("decoding installation")

decoded, err := base64.StdEncoding.DecodeString(data)
if err != nil {
return nil, fmt.Errorf("base64 decode: %w", err)
}

scheme := runtime.NewScheme()
err = v1beta1.AddToScheme(scheme)
if err != nil {
return nil, fmt.Errorf("add to scheme: %w", err)
}

decode := serializer.NewCodecFactory(scheme).UniversalDeserializer().Decode
obj, _, err := decode(decoded, nil, nil)
if err != nil {
return nil, fmt.Errorf("decode: %w", err)
}

in, ok := obj.(*v1beta1.Installation)
if !ok {
return nil, fmt.Errorf("unexpected object type: %T", obj)
}

return in, nil
}
File renamed without changes.
Loading