diff --git a/Makefile b/Makefile index 230fbd881..f81bc79a4 100644 --- a/Makefile +++ b/Makefile @@ -160,7 +160,7 @@ bundle-images: dev-apply $(IMAGES_PACKAGE_DIR) ## Create a tarball with all imag @BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-images-$(VERSION).tgz EXTENSIONS_BUNDLE_TARBALL=$(IMAGES_PACKAGE_DIR)/hmc-extension-images-$(VERSION).tgz IMG=$(IMG) KUBECTL=$(KUBECTL) YQ=$(YQ) HELM=$(HELM) NAMESPACE=$(NAMESPACE) TEMPLATES_DIR=$(TEMPLATES_DIR) KIND_CLUSTER_NAME=$(KIND_CLUSTER_NAME) $(SHELL) $(CURDIR)/scripts/bundle-images.sh airgap-package: bundle-images ## Create a tarball with all images and Helm charts used by HMC, useful for deploying in air-gapped environments. - @TEMPLATES_DIR=$(TEMPLATES_DIR) EXTENSION_CHARTS_PACKAGE_DIR=$(EXTENSION_CHARTS_PACKAGE_DIR) HELM=$(HELM) YQ=$(YQ) $(SHELL) $(CURDIR)/scripts/package-k0s-extensions-helm.sh + @TEMPLATES_DIR=$(TEMPLATES_DIR) EXTENSION_CHARTS_PACKAGE_DIR=$(EXTENSION_CHARTS_PACKAGE_DIR) HELM=$(HELM) JQ=$(JQ) YQ=$(YQ) $(SHELL) $(CURDIR)/scripts/package-k0s-extensions-helm.sh cd $(LOCALBIN) && mkdir -p scripts && cp ../scripts/airgap-push.sh scripts/airgap-push.sh && tar -czf hmc-airgap-$(VERSION).tgz scripts/airgap-push.sh $(shell basename $(CHARTS_PACKAGE_DIR)) $(shell basename $(IMAGES_PACKAGE_DIR)) package-%-tmpl: @@ -399,7 +399,11 @@ dev-azure-nuke: envsubst azure-nuke ## Warning: Destructive! Nuke all Azure reso @rm config/dev/azure-cloud-nuke.yaml .PHONY: cli-install -cli-install: clusterawsadm clusterctl cloud-nuke envsubst yq awscli ## Install the necessary CLI tools for deployment, development and testing. +cli-install: clusterawsadm clusterctl cloud-nuke envsubst yq awscli jq ## Install the necessary CLI tools for deployment, development and testing. + +.PHONY: check-unzip +check-unzip: + @which unzip > /dev/null 2>&1 || { echo "unzip is not installed"; exit 1; } ##@ Dependencies @@ -413,24 +417,6 @@ EXTERNAL_CRD_DIR ?= $(LOCALBIN)/crd $(EXTERNAL_CRD_DIR): $(LOCALBIN) mkdir -p $(EXTERNAL_CRD_DIR) -FLUX_SOURCE_VERSION ?= $(shell go mod edit -json | jq -r '.Require[] | select(.Path == "github.com/fluxcd/source-controller/api") | .Version') -FLUX_SOURCE_REPO_NAME ?= source-helmrepositories -FLUX_SOURCE_REPO_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_REPO_NAME)-$(FLUX_SOURCE_VERSION).yaml -FLUX_SOURCE_CHART_NAME ?= source-helmchart -FLUX_SOURCE_CHART_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_CHART_NAME)-$(FLUX_SOURCE_VERSION).yaml - -FLUX_HELM_VERSION ?= $(shell go mod edit -json | jq -r '.Require[] | select(.Path == "github.com/fluxcd/helm-controller/api") | .Version') -FLUX_HELM_NAME ?= helm -FLUX_HELM_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_HELM_NAME)-$(FLUX_HELM_VERSION).yaml - -SVELTOS_VERSION ?= v$(shell $(YQ) -r '.appVersion' $(PROVIDER_TEMPLATES_DIR)/projectsveltos/Chart.yaml) -SVELTOS_NAME ?= sveltos -SVELTOS_CRD ?= $(EXTERNAL_CRD_DIR)/$(SVELTOS_NAME)-$(SVELTOS_VERSION).yaml - -CAPI_OPERATOR_VERSION ?= v$(shell $(YQ) -r '.dependencies.[] | select(.name == "cluster-api-operator") | .version' $(PROVIDER_TEMPLATES_DIR)/hmc/Chart.yaml) -CAPI_OPERATOR_CRD_PREFIX ?= "operator.cluster.x-k8s.io_" -CAPI_OPERATOR_CRDS ?= capi-operator-crds - ## Tool Binaries KUBECTL ?= kubectl CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION) @@ -441,6 +427,7 @@ export HELM KIND ?= $(LOCALBIN)/kind-$(KIND_VERSION) YQ ?= $(LOCALBIN)/yq-$(YQ_VERSION) export YQ +JQ ?= $(LOCALBIN)/jq-$(JQ_VERSION) CLUSTERAWSADM ?= $(LOCALBIN)/clusterawsadm CLUSTERCTL ?= $(LOCALBIN)/clusterctl export CLUSTERCTL @@ -458,6 +445,7 @@ GOLANGCI_LINT_TIMEOUT ?= 1m HELM_VERSION ?= v3.15.1 KIND_VERSION ?= v0.23.0 YQ_VERSION ?= v4.44.2 +JQ_VERSION ?= 1.7.1 CLOUDNUKE_VERSION = v0.37.1 AZURENUKE_VERSION = v1.1.0 CLUSTERAWSADM_VERSION ?= v2.5.2 @@ -489,22 +477,37 @@ $(HELM): | $(LOCALBIN) curl -s --fail $(HELM_INSTALL_SCRIPT) | USE_SUDO=false HELM_INSTALL_DIR=$(LOCALBIN) DESIRED_VERSION=$(HELM_VERSION) BINARY_NAME=helm-$(HELM_VERSION) PATH="$(LOCALBIN):$(PATH)" bash $(FLUX_HELM_CRD): | $(EXTERNAL_CRD_DIR) + FLUX_HELM_VERSION ?= $(shell go mod edit -json | $(JQ) -r '.Require[] | select(.Path == "github.com/fluxcd/helm-controller/api") | .Version') + FLUX_HELM_NAME ?= helm + FLUX_HELM_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_HELM_NAME)-$(FLUX_HELM_VERSION).yaml rm -f $(EXTERNAL_CRD_DIR)/$(FLUX_HELM_NAME)* curl -s --fail https://raw.githubusercontent.com/fluxcd/helm-controller/$(FLUX_HELM_VERSION)/config/crd/bases/helm.toolkit.fluxcd.io_helmreleases.yaml > $(FLUX_HELM_CRD) $(FLUX_SOURCE_CHART_CRD): | $(EXTERNAL_CRD_DIR) + FLUX_SOURCE_VERSION ?= $(shell go mod edit -json | $(JQ) -r '.Require[] | select(.Path == "github.com/fluxcd/source-controller/api") | .Version') + FLUX_SOURCE_CHART_NAME ?= source-helmchart + FLUX_SOURCE_CHART_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_CHART_NAME)-$(FLUX_SOURCE_VERSION).yaml rm -f $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_CHART_NAME)* curl -s --fail https://raw.githubusercontent.com/fluxcd/source-controller/$(FLUX_SOURCE_VERSION)/config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml > $(FLUX_SOURCE_CHART_CRD) $(FLUX_SOURCE_REPO_CRD): | $(EXTERNAL_CRD_DIR) + FLUX_SOURCE_VERSION ?= $(shell go mod edit -json | $(JQ) -r '.Require[] | select(.Path == "github.com/fluxcd/source-controller/api") | .Version') + FLUX_SOURCE_REPO_NAME ?= source-helmrepositories + FLUX_SOURCE_REPO_CRD ?= $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_REPO_NAME)-$(FLUX_SOURCE_VERSION).yaml rm -f $(EXTERNAL_CRD_DIR)/$(FLUX_SOURCE_REPO_NAME)* curl -s --fail https://raw.githubusercontent.com/fluxcd/source-controller/$(FLUX_SOURCE_VERSION)/config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml > $(FLUX_SOURCE_REPO_CRD) $(SVELTOS_CRD): | yq $(EXTERNAL_CRD_DIR) + SVELTOS_VERSION ?= v$(shell $(YQ) -r '.appVersion' $(PROVIDER_TEMPLATES_DIR)/projectsveltos/Chart.yaml) + SVELTOS_NAME ?= sveltos + SVELTOS_CRD ?= $(EXTERNAL_CRD_DIR)/$(SVELTOS_NAME)-$(SVELTOS_VERSION).yaml rm -f $(EXTERNAL_CRD_DIR)/$(SVELTOS_NAME)* curl -s --fail https://raw.githubusercontent.com/projectsveltos/sveltos/$(SVELTOS_VERSION)/manifest/crds/sveltos_crds.yaml > $(SVELTOS_CRD) $(CAPI_OPERATOR_CRDS): | $(YQ) $(EXTERNAL_CRD_DIR) + CAPI_OPERATOR_VERSION ?= v$(shell $(YQ) -r '.dependencies.[] | select(.name == "cluster-api-operator") | .version' $(PROVIDER_TEMPLATES_DIR)/hmc/Chart.yaml) + CAPI_OPERATOR_CRD_PREFIX ?= "operator.cluster.x-k8s.io_" + CAPI_OPERATOR_CRDS ?= capi-operator-crds rm -f $(EXTERNAL_CRD_DIR)/$(CAPI_OPERATOR_CRD_PREFIX)* @$(foreach name, \ addonproviders bootstrapproviders controlplaneproviders coreproviders infrastructureproviders ipamproviders runtimeextensionproviders, \ @@ -524,6 +527,16 @@ yq: $(YQ) ## Download yq locally if necessary. $(YQ): | $(LOCALBIN) $(call go-install-tool,$(YQ),github.com/mikefarah/yq/v4,${YQ_VERSION}) +.PHONY: jq +jq: $(JQ) ## Download jq locally if necessary. +$(JQ): | $(LOCALBIN) + @if [ $(HOSTOS) == "darwin" ]; then \ + curl -sL --fail https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-macos-$(HOSTARCH) -o $(JQ); \ + else \ + curl -sL --fail https://github.com/jqlang/jq/releases/download/jq-$(JQ_VERSION)/jq-$(HOSTOS)-$(HOSTARCH) -o $(JQ); \ + fi; \ + chmod +x $(JQ) + .PHONY: cloud-nuke cloud-nuke: $(CLOUDNUKE) ## Download cloud-nuke locally if necessary. $(CLOUDNUKE): | $(LOCALBIN) @@ -560,7 +573,7 @@ $(ENVSUBST): | $(LOCALBIN) $(call go-install-tool,$(ENVSUBST),github.com/a8m/envsubst/cmd/envsubst,${ENVSUBST_VERSION}) .PHONY: awscli -awscli: $(AWSCLI) +awscli: check-unzip $(AWSCLI) $(AWSCLI): | $(LOCALBIN) @if [ $(HOSTOS) == "linux" ]; then \ curl --fail "https://awscli.amazonaws.com/awscli-exe-linux-$(shell uname -m)-$(AWSCLI_VERSION).zip" -o "/tmp/awscliv2.zip" && \ diff --git a/scripts/airgap-push.sh b/scripts/airgap-push.sh index 3e9fc5ae7..8bddf326f 100755 --- a/scripts/airgap-push.sh +++ b/scripts/airgap-push.sh @@ -114,8 +114,8 @@ else fi fi -if [ ! $(command -v jq) ]; then - echo "'jq' could not be found, install 'jq' to continue" +if [ -z ${JQ} ]; then + echo "'jq' could not be found, do a 'make cli-install'" exit 1 fi @@ -142,7 +142,7 @@ fi # Extract the repositories json file from the extensions bundle. echo "Retagging and pushing extension images to ${REPO}..." tar -C ${WORK_DIR} -xf ${WORK_DIR}/${extension_tarball_name} "repositories" -for image in $(cat ${WORK_DIR}/repositories | jq -r 'to_entries[] | .key'); do +for image in $(cat ${WORK_DIR}/repositories | ${JQ} -r 'to_entries[] | .key'); do image_name=$(echo ${image} | grep -o '[^/]*$') # docker images -a may return multiple images with the same name but