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

improve Makefile #843

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 34 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Comment on lines 479 to +482
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think it's justified here, since:

  1. Syntax looks incorrect
  2. You introduced duplication
  3. You didn't add jq to the target requirements (I assume that was the idea)

I suggest you just change jq -> $(JQ) in the global definitions and leave it as it were.

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, \
Expand All @@ -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)
Expand Down Expand Up @@ -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" && \
Expand Down
6 changes: 3 additions & 3 deletions scripts/airgap-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Loading