diff --git a/Makefile b/Makefile index 84de39fd2..1a7bc2400 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ 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.34.9 +EMBEDDED_OPERATOR_CHART_VERSION = 0.35.2 EMBEDDED_OPERATOR_UTILS_IMAGE = busybox:1.36.1 EMBEDDED_CLUSTER_OPERATOR_IMAGE_OVERRIDE = OPENEBS_CHART_URL = https://openebs.github.io/openebs @@ -39,7 +39,6 @@ LOCAL_ARTIFACT_MIRROR_IMAGE ?= registry.replicated.com/library/embedded-cluster- LOCAL_ARTIFACT_MIRROR_IMAGE_LOCATION = ${LOCAL_ARTIFACT_MIRROR_IMAGE}:$(subst +,-,$(VERSION)) LD_FLAGS = -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sVersion=$(K0S_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.Version=$(VERSION) \ - -X github.com/replicatedhq/embedded-cluster/pkg/defaults.K0sBinaryURL=$(K0S_BINARY_SOURCE_OVERRIDE) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.TroubleshootVersion=$(TROUBLESHOOT_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.KubectlVersion=$(KUBECTL_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/defaults.LocalArtifactMirrorImage=$(LOCAL_ARTIFACT_MIRROR_IMAGE_LOCATION) \ @@ -48,6 +47,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.KotsVersion=$(KOTS_VERSION) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator.ChartURL=$(EMBEDDED_OPERATOR_CHART_URL) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator.ChartName=$(EMBEDDED_OPERATOR_CHART_NAME) \ -X github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator.Version=$(EMBEDDED_OPERATOR_CHART_VERSION) \ diff --git a/cmd/embedded-cluster/version.go b/cmd/embedded-cluster/version.go index 4096068ee..c48c8ada5 100644 --- a/cmd/embedded-cluster/version.go +++ b/cmd/embedded-cluster/version.go @@ -13,6 +13,8 @@ import ( "github.com/urfave/cli/v2" "github.com/replicatedhq/embedded-cluster/pkg/addons" + "github.com/replicatedhq/embedded-cluster/pkg/addons/adminconsole" + "github.com/replicatedhq/embedded-cluster/pkg/addons/embeddedclusteroperator" "github.com/replicatedhq/embedded-cluster/pkg/config" "github.com/replicatedhq/embedded-cluster/pkg/defaults" "github.com/replicatedhq/embedded-cluster/pkg/goods" @@ -103,10 +105,16 @@ func gatherVersionMetadata() (*types.ReleaseMetadata, error) { return nil, fmt.Errorf("unable to get k0s binary sha256: %w", err) } + artifacts := map[string]string{ + "kots": fmt.Sprintf("kots-binaries/%s", adminconsole.KotsVersion), + "operator": fmt.Sprintf("operator-binaries/%s", embeddedclusteroperator.Version), + "local-artifact-mirror-image": defaults.LocalArtifactMirrorImage, + } + meta := types.ReleaseMetadata{ - Versions: versions, - K0sSHA: sha, - K0sBinaryURL: defaults.K0sBinaryURL, + Versions: versions, + K0sSHA: sha, + Artifacts: artifacts, } chtconfig, repconfig, err := applier.GenerateHelmConfigs( @@ -145,9 +153,6 @@ func gatherVersionMetadata() (*types.ReleaseMetadata, error) { return nil, fmt.Errorf("unable to get airgap images: %w", err) } meta.K0sImages = append(meta.K0sImages, additionalImages...) - meta.Artifacts = map[string]string{ - "local-artifact-mirror-image": defaults.LocalArtifactMirrorImage, - } return &meta, nil } diff --git a/e2e/version_test.go b/e2e/version_test.go index f71bb603a..0489935d8 100644 --- a/e2e/version_test.go +++ b/e2e/version_test.go @@ -143,6 +143,23 @@ func TestVersion(t *testing.T) { } } + expectedArtifacts := []string{"kots", "operator", "local-artifact-mirror-image"} + if len(parsed.Artifacts) != len(expectedArtifacts) { + t.Log(output) + t.Fatalf("found %d artifacts in metadata, expected %d", len(parsed.Artifacts), len(expectedArtifacts)) + } + + for _, expectedName := range expectedArtifacts { + if _, ok := parsed.Artifacts[expectedName]; !ok { + t.Errorf("failed to find artifact %s in 'metadata' output", expectedName) + failed = true + } + if len(parsed.Artifacts[expectedName]) == 0 { + t.Errorf("artifact %s is empty in 'metadata' output", expectedName) + failed = true + } + } + if failed { t.Log(output) t.FailNow() diff --git a/go.mod b/go.mod index 2b9f1e995..a88dba900 100644 --- a/go.mod +++ b/go.mod @@ -57,16 +57,15 @@ require ( github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect - go.etcd.io/etcd/api/v3 v3.5.13 // indirect - go.etcd.io/etcd/client/pkg/v3 v3.5.13 // indirect - go.etcd.io/etcd/client/v3 v3.5.13 // indirect + go.etcd.io/etcd/api/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/pkg/v3 v3.5.14 // indirect + go.etcd.io/etcd/client/v3 v3.5.14 // indirect golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect golang.org/x/sync v0.7.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect - google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect - google.golang.org/grpc v1.62.1 // indirect + google.golang.org/grpc v1.64.0 // indirect helm.sh/helm/v3 v3.15.1 // indirect ) diff --git a/go.sum b/go.sum index c56037574..cace5e497 100644 --- a/go.sum +++ b/go.sum @@ -301,12 +301,12 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/zitadel/oidc/v2 v2.7.0 h1:IGX4EDk6tegTjUSsZDWeTfLseFU0BdJ/Glf1tgys2lU= github.com/zitadel/oidc/v2 v2.7.0/go.mod h1:zkUkVJS0sDVy9m0UA9RgO3f8i/C0rtjvXU36UJj7T+0= -go.etcd.io/etcd/api/v3 v3.5.13 h1:8WXU2/NBge6AUF1K1gOexB6e07NgsN1hXK0rSTtgSp4= -go.etcd.io/etcd/api/v3 v3.5.13/go.mod h1:gBqlqkcMMZMVTMm4NDZloEVJzxQOQIls8splbqBDa0c= -go.etcd.io/etcd/client/pkg/v3 v3.5.13 h1:RVZSAnWWWiI5IrYAXjQorajncORbS0zI48LQlE2kQWg= -go.etcd.io/etcd/client/pkg/v3 v3.5.13/go.mod h1:XxHT4u1qU12E2+po+UVPrEeL94Um6zL58ppuJWXSAB8= -go.etcd.io/etcd/client/v3 v3.5.13 h1:o0fHTNJLeO0MyVbc7I3fsCf6nrOqn5d+diSarKnB2js= -go.etcd.io/etcd/client/v3 v3.5.13/go.mod h1:cqiAeY8b5DEEcpxvgWKsbLIWNM/8Wy2xJSDMtioMcoI= +go.etcd.io/etcd/api/v3 v3.5.14 h1:vHObSCxyB9zlF60w7qzAdTcGaglbJOpSj1Xj9+WGxq0= +go.etcd.io/etcd/api/v3 v3.5.14/go.mod h1:BmtWcRlQvwa1h3G2jvKYwIQy4PkHlDej5t7uLMUdJUU= +go.etcd.io/etcd/client/pkg/v3 v3.5.14 h1:SaNH6Y+rVEdxfpA2Jr5wkEvN6Zykme5+YnbCkxvuWxQ= +go.etcd.io/etcd/client/pkg/v3 v3.5.14/go.mod h1:8uMgAokyG1czCtIdsq+AGyYQMvpIKnSvPjFMunkgeZI= +go.etcd.io/etcd/client/v3 v3.5.14 h1:CWfRs4FDaDoSz81giL7zPpZH2Z35tbOrAJkkjMqOupg= +go.etcd.io/etcd/client/v3 v3.5.14/go.mod h1:k3XfdV/VIHy/97rqWjoUzrj9tk7GgJGH9J8L4dNXmAk= go.mongodb.org/mongo-driver v1.11.3 h1:Ql6K6qYHEzB6xvu4+AU0BoRoqf9vFPcc4o7MUIdPW8Y= go.mongodb.org/mongo-driver v1.11.3/go.mod h1:PTSz5yu21bkT/wXpkS7WR5f0ddqw5quethTUn9WM+2g= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -415,17 +415,15 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ= -google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro= -google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU= -google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4= +google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE= google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc= google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= +google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/pkg/addons/adminconsole/adminconsole.go b/pkg/addons/adminconsole/adminconsole.go index 3b3fbc94a..33b7df327 100644 --- a/pkg/addons/adminconsole/adminconsole.go +++ b/pkg/addons/adminconsole/adminconsole.go @@ -41,6 +41,7 @@ var ( Version = "v0.0.0" ImageOverride = "" MigrationsImageOverride = "" + KotsVersion = "" CounterRegex = regexp.MustCompile(`(\d+)/(\d+)`) Password = "" ) diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index f8cac06ca..d8cab65bf 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -16,11 +16,6 @@ var ( KubectlVersion = "0.0.0" // provider holds a global reference to the default provider. provider *Provider - // K0sBinaryURL holds an alternative URL from where to download the k0s - // binary that has been embedded in this version of the binary. If this - // is empty then it means we have shipped the official k0s binary. This - // is set at compile time via ldflags. - K0sBinaryURL = "" // LocalArtifactMirrorImage holds a reference to where the lam image for // this version of embedded-cluster is stored. Set at compile time. LocalArtifactMirrorImage = "" diff --git a/scripts/cache-files.sh b/scripts/cache-files.sh index ed0de22b4..6fa06701e 100755 --- a/scripts/cache-files.sh +++ b/scripts/cache-files.sh @@ -1,6 +1,6 @@ #!/bin/bash -set -eo pipefail +set -euo pipefail function require() { if [ -z "$2" ]; then @@ -51,19 +51,78 @@ function k0sbin() { return 0 fi - # if the override is set, the binary will have been added to the bucket through another process + # if the override is set, we should download this binary and upload it to the bucket so as not to require end users hit the override url if [ -n "${k0s_override}" ] && [ "${k0s_override}" != '' ]; then echo "K0S_BINARY_SOURCE_OVERRIDE is set to '${k0s_override}', using that source" - curl -L -o "${k0s_version}" "${k0s_override}" + curl --fail-with-body -L -o "${k0s_version}" "${k0s_override}" else # download the k0s binary from official sources - curl -L -o "${k0s_version}" "https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" + echo "downloading k0s binary from https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" + curl --fail-with-body -L -o "${k0s_version}" "https://github.com/k0sproject/k0s/releases/download/${k0s_version}/k0s-${k0s_version}-amd64" fi # upload the binary to the bucket retry 3 aws s3 cp "${k0s_version}" "s3://${S3_BUCKET}/k0s-binaries/${k0s_version}" } +function operatorbin() { + # first, figure out what version of operator is in the current build + local operator_version= + operator_version=$(awk '/^EMBEDDED_OPERATOR_CHART_VERSION/{print $3}' Makefile) + + # check if the binary already exists in the bucket + local operator_binary_exists= + operator_binary_exists=$(aws s3api head-object --bucket "${S3_BUCKET}" --key "operator-binaries/${operator_version}" || true) + + # if the binary already exists, we don't need to upload it again + if [ -n "${operator_binary_exists}" ]; then + echo "operator binary ${operator_version} already exists in bucket ${S3_BUCKET}, skipping upload" + return 0 + fi + + # download the operator binary from github + echo "downloading embedded cluster operator binary from https://github.com/replicatedhq/embedded-cluster-operator/releases/download/v${operator_version}/manager" + curl --fail-with-body -L -o "${operator_version}" "https://github.com/replicatedhq/embedded-cluster-operator/releases/download/v${operator_version}/manager" + + # upload the binary to the bucket + retry 3 aws s3 cp "${operator_version}" "s3://${S3_BUCKET}/operator-binaries/${operator_version}" +} + +function kotsbin() { + # first, figure out what version of kots is in the current build + local kots_version= + kots_version=$(awk '/^ADMIN_CONSOLE_CHART_VERSION/{print $3}' Makefile) + kots_version=$(echo "${kots_version}" | sed 's/\([0-9]\+\.[0-9]\+\.[0-9]\+\).*/\1/') + + local kots_override= + kots_override=$(awk '/^KOTS_BINARY_URL_OVERRIDE/{gsub("\"", "", $3); print $3}' Makefile) + + # check if the binary already exists in the bucket + local kots_binary_exists= + kots_binary_exists=$(aws s3api head-object --bucket "${S3_BUCKET}" --key "kots-binaries/${kots_version}" || true) + + # if the binary already exists, we don't need to upload it again + if [ -n "${kots_binary_exists}" ]; then + echo "kots binary ${kots_version} already exists in bucket ${S3_BUCKET}, skipping upload" + return 0 + fi + + if [ -n "${kots_override}" ] && [ "${kots_override}" != '' ]; then + echo "KOTS_BINARY_URL_OVERRIDE is set to '${kots_override}', using that source" + curl --fail-with-body -L -o "kots_linux_amd64.tar.gz" "${kots_override}" + else + # download the kots binary from github + echo "downloading kots binary from https://github.com/replicatedhq/kots/releases/download/v${kots_version}/kots_linux_amd64.tar.gz" + curl --fail-with-body -L -o "kots_linux_amd64.tar.gz" "https://github.com/replicatedhq/kots/releases/download/v${kots_version}/kots_linux_amd64.tar.gz" + fi + + # decompress the bundle, as we only care about the binary and not the sbom/license/readme + tar -xvf kots_linux_amd64.tar.gz + + # upload the binary to the bucket + retry 3 aws s3 cp "kots" "s3://${S3_BUCKET}/kots-binaries/${kots_version}" +} + function metadata() { if [ -z "${EC_VERSION}" ]; then echo "EC_VERSION unset, not uploading metadata.json" @@ -98,6 +157,8 @@ function embeddedcluster() { # the embedded cluster release does not exist for CI builds function main() { k0sbin + operatorbin + kotsbin metadata embeddedcluster }