From 8d9998d6f561b8197ec08791aef271607bdb7626 Mon Sep 17 00:00:00 2001 From: Andreas Fritzler Date: Wed, 25 Oct 2023 14:34:51 +0200 Subject: [PATCH] Improve Gardener hack script fetching - Use go mod to get the Gardener hack scripts - Cleanup Makefile from unused directives --- Makefile | 79 +++++++------------------------------------ hack/generate-crds.sh | 3 +- 2 files changed, 15 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index dafefb33..3f146ea7 100644 --- a/Makefile +++ b/Makefile @@ -35,24 +35,19 @@ $(LOCALBIN): KUSTOMIZE ?= $(LOCALBIN)/kustomize CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest -INSTALL ?= $(LOCALBIN)/install.sh -CLEAN ?= $(LOCALBIN)/clean.sh -FORMAT ?= $(LOCALBIN)/format.sh -TEST_COV ?= $(LOCALBIN)/test-cov.sh -TEST_CLEAN ?= $(LOCALBIN)/test-clean.sh GOIMPORTS ?= $(LOCALBIN)/goimports GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint -CHECK ?= $(LOCALBIN)/check.sh -CHECK_CHARTS ?= $(LOCALBIN)/check-charts.sh VGOPATH ?= $(LOCALBIN)/vgopath DEEPCOPY_GEN ?= $(LOCALBIN)/deepcopy-gen CONVERSION_GEN ?= $(LOCALBIN)/conversion-gen DEFAULTER_GEN ?= $(LOCALBIN)/defaulter-gen ADDLICENSE ?= $(LOCALBIN)/addlicense -GENERATE_CRDS ?= $(LOCALBIN)/generate-crds.sh GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs MOCKGEN ?= $(LOCALBIN)/mockgen +## Gardener hack scripts +GARDENER_GENERATE_CRDS ?= $(LOCALBIN)/generate-crds.sh + ## Tool Versions KUSTOMIZE_VERSION ?= v3.8.7 CONTROLLER_TOOLS_VERSION ?= v0.13.0 @@ -112,11 +107,6 @@ docker-images: # Rules for verification, formatting, linting, testing and cleaning # ##################################################################### -CLEAN_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/master/hack/clean.sh" -$(CLEAN): $(LOCALBIN) - curl -Ss $(CLEAN_SCRIPT_URL) -o $(CLEAN) - chmod +x $(CLEAN) - .PHONY: clean clean: $(CLEAN) @$(shell find ./example -type f -name "controller-registration.yaml" -exec rm '{}' \;) @@ -147,9 +137,10 @@ generate: vgopath deepcopy-gen defaulter-gen conversion-gen controller-gen docs ./hack/update-codegen.sh .PHONY: generate-crds -generate-crds: vgopath controller-gen generate-crds-sh +generate-crds: vgopath controller-gen gardener-generate-crds VGOPATH=$(VGOPATH) \ CONTROLLER_GEN=$(CONTROLLER_GEN) \ + GARDENER_GENERATE_CRDS=$(GARDENER_GENERATE_CRDS) \ go generate ./example/... .PHONY: generate-charts @@ -186,20 +177,6 @@ test: generate-mocks fmt vet envtest ## Run tests. KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out go mod tidy -.PHONY: test-clean -test-clean: $(TEST_CLEAN) - $(TEST_CLEAN) - -.PHONY: test-cov -test-cov: $(TEST_COV) - $(TEST_COV) -mod=mod ./cmd/... ./pkg/... - -.PHONY: verify -verify: check format test - -.PHONY: verify-extended -verify-extended: check-generate check format test-cov test-clean - ### ### Download tooling ### @@ -247,44 +224,14 @@ $(ADDLICENSE): $(LOCALBIN) ### ### Download Gardener hack scripts ### -GARDENER_VERSION=v1.80.3 - -GENERATE_CRDS_SCRIPT ?= https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/generate-crds.sh -.PHONY: generate-crds-sh -generate-crds-sh: $(GENERATE_CRDS) ## Download generate-crds.sh locally if necessary. -$(GENERATE_CRDS): $(LOCALBIN) - test -s $(LOCALBIN)/generate-crds.sh || curl -Ss $(GENERATE_CRDS_SCRIPT) -o $(GENERATE_CRDS) - chmod +x $(GENERATE_CRDS) - -TEST_COV_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/test-cover.sh" -$(TEST_COV): $(LOCALBIN) - curl -Ss $(TEST_COV_SCRIPT_URL) -o $(TEST_COV) - chmod +x $(TEST_COV) - -TEST_CLEAN_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/test-cover-clean.sh" -$(TEST_CLEAN): $(LOCALBIN) - curl -Ss $(TEST_CLEAN_SCRIPT_URL) -o $(TEST_CLEAN) - chmod +x $(TEST_CLEAN) - -FORMAT_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/format.sh" -$(FORMAT): $(LOCALBIN) - curl -Ss $(FORMAT_SCRIPT_URL) -o $(FORMAT) - chmod +x $(FORMAT) - -CHECK_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/check.sh" -$(CHECK): $(LOCALBIN) - curl -Ss $(CHECK_SCRIPT_URL) -o $(CHECK) - chmod +x $(CHECK) - -CHECK_CHARTS_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/check-charts.sh" -$(CHECK_CHARTS): $(LOCALBIN) - curl -Ss $(CHECK_CHARTS_SCRIPT_URL) -o $(CHECK_CHARTS) - chmod +x $(CHECK_CHARTS) - -INSTALL_SCRIPT_URL ?= "https://raw.githubusercontent.com/gardener/gardener/$(GARDENER_VERSION)/hack/install.sh" -$(INSTALL): $(LOCALBIN) - curl -Ss $(INSTALL_SCRIPT_URL) -o $(INSTALL) - chmod +x $(INSTALL) +### Gardener hack scripts location +GARDENER_BASE_DIR=$(shell go mod download -json | jq 'select(.Path == "github.com/gardener/gardener") | .Dir') + +.PHONY: gardener-generate-crds +gardener-generate-crds: $(GARDENER_GENERATE_CRDS) ## Download generate-crds.sh locally if necessary. +$(GARDENER_GENERATE_CRDS): $(LOCALBIN) + test -s $(GARDENER_GENERATE_CRDS) || cp $(GARDENER_BASE_DIR)/hack/generate-crds.sh $(GARDENER_GENERATE_CRDS) + chmod +x $(GARDENER_GENERATE_CRDS) .PHONY: goimports goimports: $(GOIMPORTS) ## Download goimports locally if necessary. diff --git a/hack/generate-crds.sh b/hack/generate-crds.sh index 04301258..e204ceea 100755 --- a/hack/generate-crds.sh +++ b/hack/generate-crds.sh @@ -48,6 +48,7 @@ function qualify-gs() { VGOPATH="$VGOPATH" CONTROLLER_GEN="$CONTROLLER_GEN" +GARDENER_GENERATE_CRDS="$GARDENER_GENERATE_CRDS" VIRTUAL_GOPATH="$(mktemp -d)" trap 'rm -rf "$GOPATH"' EXIT @@ -59,4 +60,4 @@ export GOROOT="${GOROOT:-"$(go env GOROOT)"}" export GOPATH="$VIRTUAL_GOPATH" export GO111MODULE=off -$SCRIPT_DIR/../bin/generate-crds.sh "$@" +"$GARDENER_GENERATE_CRDS" "$@"