From efe2744d21e43bc383326e814f2df59d855994a2 Mon Sep 17 00:00:00 2001 From: Todd Short Date: Thu, 23 Feb 2023 15:37:16 -0500 Subject: [PATCH] Merge fixup: update from operator-framework/rukpak This copies everything from operator-framework/rukpak, which really ends up being just the `Makefile` and `Dockerfile`. Both the `Dockerfile` and the `Makefile` have been tweaked to work with upstream changes. Versions of the locally built components previously in `/bin`, now in `hack/tools/bin`, are based on the `go.mod` in the new location rather than versions in the `Makefile`. CI Fixes: * Swap test-e2e and e2e and disable e2e * Add -mod=mod to local builds of tools Signed-off-by: Todd Short --- Dockerfile | 3 ++ Makefile | 139 ++++++++++++++++++++++++++--------------------------- 2 files changed, 72 insertions(+), 70 deletions(-) diff --git a/Dockerfile b/Dockerfile index 62c5adc29..e0d044526 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,6 +14,9 @@ FROM registry.ci.openshift.org/ocp/4.13:base COPY --from=builder /build/bin/core / COPY --from=builder /build/bin/unpack / COPY --from=builder /build/bin/webhooks / +COPY --from=builder /build/bin/helm / +COPY --from=builder /build/bin/crdvalidator / +COPY --from=builder /build/bin/rukpakctl / USER 1001 LABEL io.k8s.display-name="OpenShift RukPak" \ diff --git a/Makefile b/Makefile index c81907fc3..813317d95 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ ########################### ORG := github.com/operator-framework PKG := $(ORG)/rukpak -GO_INSTALL_OPTS ?= "-mod=readonly" export IMAGE_REPO ?= quay.io/operator-framework/rukpak export IMAGE_TAG ?= latest export GO_BUILD_TAGS ?= upstream @@ -61,6 +60,9 @@ lint: golangci-lint ## Run golangci linter tidy: ## Update dependencies $(Q)go mod tidy +fmt: ## Format Go code + $(Q)go fmt ./... + clean: ## Remove binaries and test artifacts @rm -rf bin @@ -81,34 +83,42 @@ generate: controller-gen ## Generate code and manifests paths=./internal/provisioner/helm/... \ output:stdout > ./manifests/provisioners/helm/resources/cluster_role.yaml -verify: tidy generate ## Verify the current code generation and lint +verify: tidy fmt generate ## Verify the current code generation and lint git diff --exit-code ########### # Testing # ########### -.PHONY: test test-unit test-e2e image-registry local-git +.PHONY: test test-unit test-e2e run-e2e e2e image-registry local-git ##@ testing: test: test-unit test-e2e ## Run the tests -.PHONY: setup-envtest -setup-envtest: envtest - $(eval KUBEBUILDER_ASSETS := "$(shell $(ENVTEST) use $(ENVTEST_VERSION) -p path --bin-dir $(LOCALBIN))") +envtest: setup-envtest + $(eval KUBEBUILDER_ASSETS := "$(shell $(SETUP_ENVTEST) use $(ENVTEST_VERSION) -p path --bin-dir $(TOOLS_BIN_DIR))") ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/') UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/) -test-unit: setup-envtest ## Run the unit tests +test-unit: envtest ## Run the unit tests KUBEBUILDER_ASSETS=$(KUBEBUILDER_ASSETS) go test -tags $(GO_BUILD_TAGS) -count=1 -short $(UNIT_TEST_DIRS) FOCUS := $(if $(TEST),-v -focus "$(TEST)") E2E_FLAGS ?= "" -test-e2e: ginkgo ## Run the e2e tests +run-e2e: ginkgo ## Run the e2e tests $(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e -e2e: KIND_CLUSTER_NAME=rukpak-e2e -e2e: rukpakctl run image-registry local-git kind-load-bundles registry-load-bundles test-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster +# This is for local testing +test-e2e: KIND_CLUSTER_NAME=rukpak-e2e +test-e2e: rukpakctl run image-registry local-git kind-load-bundles registry-load-bundles run-e2e kind-cluster-cleanup ## Run e2e tests against an ephemeral kind cluster + +# `make e2e` is what is run by the CI: +# https://github.com/openshift/release/blob/e4afcd7896eb8db041b7290001f39b11155aa22f/ci-operator/config/openshift/operator-framework-rukpak/openshift-operator-framework-rukpak-main.yaml#L63 +e2e: ## Target for CI e2e testing + @echo '********************************************' + @echo '* CI/PROW/E2E TESTS ARE DISABLED *' + @echo '* Use "make test-e2e" to test e2e via kind *' + @echo '********************************************' kind-cluster: kind kind-cluster-cleanup ## Standup a kind cluster $(KIND) create cluster --name ${KIND_CLUSTER_NAME} @@ -133,18 +143,26 @@ local-git: ## Setup in-cluster git repository install: generate cert-mgr install-manifests wait ## Install rukpak install-manifests: - kubectl apply -k manifests + $(KUBECTL) apply -k manifests wait: - kubectl wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/core --timeout=60s - kubectl wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/rukpak-webhooks --timeout=60s + $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/core --timeout=60s + $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/rukpak-webhooks --timeout=60s + $(KUBECTL) wait --for=condition=Available --namespace=$(RUKPAK_NAMESPACE) deployment/helm-provisioner --timeout=60s + $(KUBECTL) wait --for=condition=Available --namespace=crdvalidator-system deployment/crd-validation-webhook --timeout=60s run: build-container kind-cluster kind-load install ## Build image, stop/start a local kind cluster, and run operator in that cluster +cert-mgr: ## Install the certification manager + $(KUBECTL) apply -f https://github.com/cert-manager/cert-manager/releases/download/$(CERT_MGR_VERSION)/cert-manager.yaml + $(KUBECTL) wait --for=condition=Available --namespace=cert-manager deployment/cert-manager-webhook --timeout=60s + +uninstall: ## Remove all rukpak resources from the cluster + $(KUBECTL) delete -k manifests + ################## # Build and Load # ################## -.PHONY: build plain unpack core rukpakctl build-container kind-load kind-load-bundles kind-cluster registry-load-bundles ##@ build/load: @@ -159,13 +177,13 @@ VERSION_FLAGS=-ldflags "-X $(VERSION_PATH).GitCommit=$(GIT_COMMIT)" build: $(BINARIES) $(LINUX_BINARIES): - CGO_ENABLED=0 GOOS=linux go build -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@) + CGO_ENABLED=0 GOOS=linux go build -mod=vendor -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$(notdir $@) $(BINARIES): - CGO_ENABLED=0 go build -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$@ + CGO_ENABLED=0 go build -mod=vendor -tags $(GO_BUILD_TAGS) $(VERSION_FLAGS) -o $(BIN_DIR)/$@ ./cmd/$@ build-container: $(LINUX_BINARIES) ## Builds provisioner container image locally - $(CONTAINER_RUNTIME) build -f Dockerfile -t $(IMAGE) $(BIN_DIR)/linux + $(CONTAINER_RUNTIME) build -f Dockerfile -t $(IMAGE) kind-load-bundles: kind ## Load the e2e testdata container images into a kind cluster $(CONTAINER_RUNTIME) build $(TESTDATA_DIR)/bundles/plain-v0/valid -t localhost/testdata/bundles/plain-v0:valid @@ -217,56 +235,37 @@ quickstart: generate ## Generate the installation release manifests ################ # Hack / Tools # ################ - -## Location to install dependencies to -LOCALBIN ?= $(shell pwd)/bin -$(LOCALBIN): - mkdir -p $(LOCALBIN) - -## Tool Binaries -KUSTOMIZE ?= $(LOCALBIN)/kustomize -CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen -ENVTEST ?= $(LOCALBIN)/setup-envtest -GINKGO ?= $(LOCALBIN)/ginkgo -GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint -KIND ?= $(LOCALBIN)/kind - -## Tool Versions -KUSTOMIZE_VERSION ?= v3.8.7 -CONTROLLER_TOOLS_VERSION ?= v0.9.0 -SETUP_ENVTEST_VERSION ?= latest -GINKGO_VERSION ?= v2.1.4 -GOLANGCI_LINT_VERSION ?= v1.46.0 -KIND_VERSION ?= v0.14.0 - -KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" -.PHONY: kustomize -kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. -$(KUSTOMIZE): $(LOCALBIN) - rm -f $(KUSTOMIZE) - curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN) - -.PHONY: controller-gen -controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. -$(CONTROLLER_GEN): $(LOCALBIN) - GOBIN=$(LOCALBIN) go install $(GO_INSTALL_OPTS) sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) - -.PHONY: envtest -envtest: $(ENVTEST) ## Download envtest-setup locally if necessary. -$(ENVTEST): $(LOCALBIN) - GOBIN=$(LOCALBIN) go install $(GO_INSTALL_OPTS) sigs.k8s.io/controller-runtime/tools/setup-envtest@$(SETUP_ENVTEST_VERSION) - -.PHONY: ginkgo -ginkgo: $(GINKGO) -$(GINKGO): $(LOCALBIN) ## Download ginkgo locally if necessary. - GOBIN=$(LOCALBIN) go install $(GO_INSTALL_OPTS) github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) - -.PHONY: golangci-lint -golangci-lint: $(GOLANGCI_LINT) -$(GOLANGCI_LINT): $(LOCALBIN) ## Download golangci-lint locally if necessary. - GOBIN=$(LOCALBIN) go install $(GO_INSTALL_OPTS) github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) - -.PHONY: kind -kind: $(KIND) ## Download kind locally if necessary. -$(KIND): $(LOCALBIN) - GOBIN=$(LOCALBIN) go install $(GO_INSTALL_OPTS) sigs.k8s.io/kind@$(KIND_VERSION) +TOOLS_DIR := $(shell pwd)/hack/tools +TOOLS_BIN_DIR := $(TOOLS_DIR)/bin + +##@ hack/tools: +# Versions are specified in hack/tools/go.mod + +.PHONY: golangci-lint ginkgo controller-gen goreleaser kind + +GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/golangci-lint) +GINKGO := $(abspath $(TOOLS_BIN_DIR)/ginkgo) +CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/controller-gen) +SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/setup-envtest) +GORELEASER := $(abspath $(TOOLS_BIN_DIR)/goreleaser) +KIND := $(abspath $(TOOLS_BIN_DIR)/kind) + +controller-gen: $(CONTROLLER_GEN) ## Build a local copy of controller-gen +ginkgo: $(GINKGO) ## Build a local copy of ginkgo +golangci-lint: $(GOLANGCI_LINT) ## Build a local copy of golangci-lint +setup-envtest: $(SETUP_ENVTEST) ## Build a local copy of envtest +goreleaser: $(GORELEASER) ## Builds a local copy of goreleaser +kind: $(KIND) ## Builds a local copy of kind + +$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod # Build controller-gen from tools folder. + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen +$(GINKGO): $(TOOLS_DIR)/go.mod # Build ginkgo from tools folder. + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/ginkgo github.com/onsi/ginkgo/v2/ginkgo +$(GOLANGCI_LINT): $(TOOLS_DIR)/go.mod # Build golangci-lint from tools folder. + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint +$(SETUP_ENVTEST): $(TOOLS_DIR)/go.mod # Build setup-envtest from tools folder. + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/setup-envtest sigs.k8s.io/controller-runtime/tools/setup-envtest +$(GORELEASER): $(TOOLS_DIR)/go.mod # Build goreleaser from tools folder. + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/goreleaser github.com/goreleaser/goreleaser +$(KIND): $(TOOLS_DIR)/go.mod + cd $(TOOLS_DIR); go build -mod=mod -tags=tools -o $(BIN_DIR)/kind sigs.k8s.io/kind