From 6122998583065fb0ca03a549bc1cba4794e35df3 Mon Sep 17 00:00:00 2001 From: Suleyman Akbas Date: Mon, 24 Apr 2023 19:49:10 +0200 Subject: [PATCH] chore: reduce number of Dockerfiles Signed-off-by: Suleyman Akbas --- Dockerfile | 23 +- Dockerfile.combined | 44 --- Dockerfile.vgmanager | 34 --- Makefile | 314 +++++++++++----------- api/v1alpha1/groupversion_info.go | 4 +- controllers/defaults.go | 3 - controllers/lvmcluster_controller_test.go | 2 - controllers/vgmanager_daemonset.go | 11 +- controllers/vgmanager_test.go | 2 - doc/usage/install.md | 2 +- 10 files changed, 176 insertions(+), 263 deletions(-) delete mode 100644 Dockerfile.combined delete mode 100644 Dockerfile.vgmanager diff --git a/Dockerfile b/Dockerfile index ff0a0c85d..885ebec96 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,15 +13,32 @@ RUN go mod download COPY main.go main.go COPY api/ api/ COPY controllers/ controllers/ +COPY cmd/ cmd/ +COPY pkg/ pkg/ # Build RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o manager main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o vgmanager cmd/vgmanager/main.go +RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o metricsexporter cmd/metricsexporter/exporter.go + +# vgmanager needs 'nsenter' and other basic linux utils to correctly function +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 + +# Update the image to get the latest CVE updates +RUN microdnf update -y && \ + microdnf install -y openssl && \ + microdnf install -y util-linux && \ + microdnf clean all -# Use distroless as minimal base image to package the manager binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM gcr.io/distroless/static:nonroot WORKDIR / COPY --from=builder /workspace/manager . +COPY --from=builder /workspace/vgmanager . +COPY --from=builder /workspace/metricsexporter . +EXPOSE 23532 USER 65532:65532 +# '/manager' is lvm-operator entrypoint ENTRYPOINT ["/manager"] + +# '/vgmanager' is vgmanager entrypoint which is used in daemonset image +# ENTRYPOINT ["/vgmanager"] diff --git a/Dockerfile.combined b/Dockerfile.combined deleted file mode 100644 index 885ebec96..000000000 --- a/Dockerfile.combined +++ /dev/null @@ -1,44 +0,0 @@ -# Build the manager binary -FROM golang:1.18 as builder - -WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -# Copy the go source -COPY main.go main.go -COPY api/ api/ -COPY controllers/ controllers/ -COPY cmd/ cmd/ -COPY pkg/ pkg/ - -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o manager main.go -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o vgmanager cmd/vgmanager/main.go -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o metricsexporter cmd/metricsexporter/exporter.go - -# vgmanager needs 'nsenter' and other basic linux utils to correctly function -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 - -# Update the image to get the latest CVE updates -RUN microdnf update -y && \ - microdnf install -y openssl && \ - microdnf install -y util-linux && \ - microdnf clean all - -WORKDIR / -COPY --from=builder /workspace/manager . -COPY --from=builder /workspace/vgmanager . -COPY --from=builder /workspace/metricsexporter . -EXPOSE 23532 -USER 65532:65532 - -# '/manager' is lvm-operator entrypoint -ENTRYPOINT ["/manager"] - -# '/vgmanager' is vgmanager entrypoint which is used in daemonset image -# ENTRYPOINT ["/vgmanager"] diff --git a/Dockerfile.vgmanager b/Dockerfile.vgmanager deleted file mode 100644 index c0fc184f1..000000000 --- a/Dockerfile.vgmanager +++ /dev/null @@ -1,34 +0,0 @@ -# Build the manager binary -FROM golang:1.18 as builder - -WORKDIR /workspace -# Copy the Go Modules manifests -COPY go.mod go.mod -COPY go.sum go.sum -# cache deps before building and copying source so that we don't need to re-download as much -# and so that source changes don't invalidate our downloaded layer -RUN go mod download - -# Copy the go source -COPY cmd/ cmd/ -COPY api/ api/ -COPY pkg/ pkg/ -COPY controllers/ controllers/ - -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build --ldflags "-s -w" -a -o vgmanager cmd/vgmanager/main.go - -# vgmanager needs 'nsenter' and other basic linux utils to correctly function -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.7 - -# Update the image to get the latest CVE updates -RUN microdnf update -y && \ - microdnf install -y openssl && \ - microdnf install -y util-linux && \ - microdnf clean all - -WORKDIR / -COPY --from=builder /workspace/vgmanager . -USER 65532:65532 - -ENTRYPOINT ["/vgmanager"] diff --git a/Makefile b/Makefile index 937ad4b58..633438513 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,33 @@ +##@ General + +# The help target prints out all targets with their descriptions organized +# beneath their categories. The categories are represented by '##@' and the +# target descriptions by '##'. The awk commands is responsible for reading the +# entire set of makefiles included in this invocation, looking for lines of the +# file as xyz: ## something, and then pretty-format the target and help. Then, +# if there's a line with ##@ something, that gets pretty-printed as a category. +# More info on the usage of ANSI control characters for terminal formatting: +# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters +# More info on the awk command: +# http://linuxcommand.org/lc3_adv_awk.php +help: ## Display this help. + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN=$(shell go env GOPATH)/bin +else +GOBIN=$(shell go env GOBIN) +endif + +# Setting SHELL to bash allows bash commands to be executed by recipes. +# This is a requirement for 'setup-envtest.sh' in the test target. +# Options are set to exit when a recipe line exits non-zero or a piped command fails. +SHELL = /usr/bin/env bash -o pipefail +.SHELLFLAGS = -ec + +## Versions + # VERSION defines the project version for the bundle. # Update this value when you upgrade the version of your project. # To re-generate a bundle for another specific version without changing the standard setup, you can: @@ -5,7 +35,57 @@ # - use environment variables to overwrite this value (e.g export VERSION=0.0.2) VERSION ?= 0.0.1 +# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. +ENVTEST_K8S_VERSION = 1.22 + OPERATOR_SDK_VERSION ?= 1.23.0 +RBAC_PROXY_IMG ?= gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 + +MANAGER_NAME_PREFIX ?= lvms- +OPERATOR_NAMESPACE ?= openshift-storage +TOPOLVM_CSI_IMAGE ?= quay.io/lvms_dev/topolvm:latest +CSI_REGISTRAR_IMAGE ?= k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.6.2 +CSI_PROVISIONER_IMAGE ?= k8s.gcr.io/sig-storage/csi-provisioner:v3.3.0 +CSI_LIVENESSPROBE_IMAGE ?= k8s.gcr.io/sig-storage/livenessprobe:v2.8.0 +CSI_RESIZER_IMAGE ?= k8s.gcr.io/sig-storage/csi-resizer:v1.6.0 +CSI_SNAPSHOTTER_IMAGE ?= k8s.gcr.io/sig-storage/csi-snapshotter:v6.1.0 + +define MANAGER_ENV_VARS +OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) +TOPOLVM_CSI_IMAGE=$(TOPOLVM_CSI_IMAGE) +CSI_REGISTRAR_IMAGE=$(CSI_REGISTRAR_IMAGE) +CSI_PROVISIONER_IMAGE=$(CSI_PROVISIONER_IMAGE) +CSI_LIVENESSPROBE_IMAGE=$(CSI_LIVENESSPROBE_IMAGE) +CSI_RESIZER_IMAGE=$(CSI_RESIZER_IMAGE) +CSI_SNAPSHOTTER_IMAGE=$(CSI_SNAPSHOTTER_IMAGE) +endef +export MANAGER_ENV_VARS + +update-mgr-env: ## Feed environment variables to the manager ConfigMap. + @echo "$$MANAGER_ENV_VARS" > config/manager/manager.env + cp config/default/manager_custom_env.yaml.in config/default/manager_custom_env.yaml + sed 's|TOPOLVM_CSI_IMAGE_VAL|$(TOPOLVM_CSI_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + sed 's|CSI_LIVENESSPROBE_IMAGE_VAL|$(CSI_LIVENESSPROBE_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + sed 's|CSI_PROVISIONER_IMAGE_VAL|$(CSI_PROVISIONER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + sed 's|CSI_RESIZER_IMAGE_VAL|$(CSI_RESIZER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + sed 's|CSI_REGISTRAR_IMAGE_VAL|$(CSI_REGISTRAR_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + sed 's|CSI_SNAPSHOTTER_IMAGE_VAL|$(CSI_SNAPSHOTTER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml + +## Variables for the images + +# Image URL to use all building/pushing image targets +IMAGE_REGISTRY ?= quay.io +REGISTRY_NAMESPACE ?= lvms_dev +IMAGE_TAG ?= latest +IMAGE_NAME ?= lvms-operator +# IMG defines the image used for the operator. +IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) + +# MUST_GATHER_IMG defines the image used for the must-gather. +MUST_GATHER_IMAGE_NAME ?= lvms-must-gather +MUST_GATHER_IMG=$(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(MUST_GATHER_IMAGE_NAME):$(IMAGE_TAG) + +## Variables for the bundle # CHANNELS define the bundle channels used in the bundle. # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable") @@ -27,30 +107,10 @@ endif BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) BUNDLE_PACKAGE ?= lvms-operator -# Image URL to use all building/pushing image targets -IMAGE_REGISTRY ?= quay.io -REGISTRY_NAMESPACE ?= lvms_dev -IMAGE_TAG ?= latest -IMAGE_NAME ?= lvms-operator -VGMANAGER_IMAGE_NAME ?= vgmanager -MUST_GATHER_IMAGE_NAME ?= lvms-must-gather -MUST_GATHER_FULL_IMAGE_NAME=$(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(MUST_GATHER_IMAGE_NAME):$(IMAGE_TAG) - -# IMG defines the image used for the operator. -IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_TAG) -# VGMANAGER_IMG is the image for the vgmanager daemonset -VGMANAGER_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(VGMANAGER_IMAGE_NAME):$(IMAGE_TAG) -RBAC_PROXY_IMG ?= gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0 - - # BUNDLE_IMG defines the image used for the bundle. BUNDLE_IMAGE_NAME ?= $(IMAGE_NAME)-bundle BUNDLE_IMG ?= $(IMAGE_REGISTRY)/$(REGISTRY_NAMESPACE)/$(BUNDLE_IMAGE_NAME):$(IMAGE_TAG) - -# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.22 - # Each CSV has a replaces parameter that indicates which Operator it replaces. # This builds a graph of CSVs that can be queried by OLM, and updates can be # shared between channels. Channels can be thought of as entry points into @@ -61,43 +121,6 @@ REPLACES ?= # but can skip several. This can be accomplished using the skipRange annotation: SKIP_RANGE ?= -# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) -ifeq (,$(shell go env GOBIN)) -GOBIN=$(shell go env GOPATH)/bin -else -GOBIN=$(shell go env GOBIN) -endif - -# Setting SHELL to bash allows bash commands to be executed by recipes. -# This is a requirement for 'setup-envtest.sh' in the test target. -# Options are set to exit when a recipe line exits non-zero or a piped command fails. -SHELL = /usr/bin/env bash -o pipefail -.SHELLFLAGS = -ec - - -IMAGE_BUILD_CMD ?= $(shell command -v docker 2>&1 >/dev/null && echo docker || echo podman) - - -MANAGER_NAME_PREFIX ?= lvms- - -all: build - -##@ General - -# The help target prints out all targets with their descriptions organized -# beneath their categories. The categories are represented by '##@' and the -# target descriptions by '##'. The awk commands is responsible for reading the -# entire set of makefiles included in this invocation, looking for lines of the -# file as xyz: ## something, and then pretty-format the target and help. Then, -# if there's a line with ##@ something, that gets pretty-printed as a category. -# More info on the usage of ANSI control characters for terminal formatting: -# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters -# More info on the awk command: -# http://linuxcommand.org/lc3_adv_awk.php - -help: ## Display this help. - @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) - ##@ Development manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects. @@ -115,43 +138,17 @@ vet: ## Run go vet against code. godeps-update: ## Run go mod tidy and go mod vendor. go mod tidy && go mod vendor -test: manifests generate fmt vet envtest godeps-update ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -cover `go list ./... | grep -v "e2e"` - - -OPERATOR_NAMESPACE ?= openshift-storage -TOPOLVM_CSI_IMAGE ?= quay.io/lvms_dev/topolvm:latest -CSI_REGISTRAR_IMAGE ?= k8s.gcr.io/sig-storage/csi-node-driver-registrar:v2.6.2 -CSI_PROVISIONER_IMAGE ?= k8s.gcr.io/sig-storage/csi-provisioner:v3.3.0 -CSI_LIVENESSPROBE_IMAGE ?= k8s.gcr.io/sig-storage/livenessprobe:v2.8.0 -CSI_RESIZER_IMAGE ?= k8s.gcr.io/sig-storage/csi-resizer:v1.6.0 -CSI_SNAPSHOTTER_IMAGE ?= k8s.gcr.io/sig-storage/csi-snapshotter:v6.1.0 -VGMANAGER_IMAGE ?= quay.io/lvms_dev/vgmanager:latest - +run: manifests generate ## Run a controller from your host. + go run ./main.go -define MANAGER_ENV_VARS -OPERATOR_NAMESPACE=$(OPERATOR_NAMESPACE) -TOPOLVM_CSI_IMAGE=$(TOPOLVM_CSI_IMAGE) -CSI_REGISTRAR_IMAGE=$(CSI_REGISTRAR_IMAGE) -CSI_PROVISIONER_IMAGE=$(CSI_PROVISIONER_IMAGE) -CSI_LIVENESSPROBE_IMAGE=$(CSI_LIVENESSPROBE_IMAGE) -CSI_RESIZER_IMAGE=$(CSI_RESIZER_IMAGE) -CSI_SNAPSHOTTER_IMAGE=$(CSI_SNAPSHOTTER_IMAGE) -endef -export MANAGER_ENV_VARS +test: manifests generate envtest godeps-update ## Run tests. + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test -v -cover `go list ./... | grep -v "e2e"` -update-mgr-env: ## Feed env variables to the manager configmap - @echo "$$MANAGER_ENV_VARS" > config/manager/manager.env - cp config/default/manager_custom_env.yaml.in config/default/manager_custom_env.yaml - sed 's|TOPOLVM_CSI_IMAGE_VAL|$(TOPOLVM_CSI_IMAGE)|g' --in-place config/default/manager_custom_env.yaml - sed 's|CSI_LIVENESSPROBE_IMAGE_VAL|$(CSI_LIVENESSPROBE_IMAGE)|g' --in-place config/default/manager_custom_env.yaml - sed 's|CSI_PROVISIONER_IMAGE_VAL|$(CSI_PROVISIONER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml - sed 's|CSI_RESIZER_IMAGE_VAL|$(CSI_RESIZER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml - sed 's|CSI_REGISTRAR_IMAGE_VAL|$(CSI_REGISTRAR_IMAGE)|g' --in-place config/default/manager_custom_env.yaml - sed 's|CSI_SNAPSHOTTER_IMAGE_VAL|$(CSI_SNAPSHOTTER_IMAGE)|g' --in-place config/default/manager_custom_env.yaml +##@ Build +IMAGE_BUILD_CMD ?= $(shell command -v docker 2>&1 >/dev/null && echo docker || echo podman) -##@ Build +all: build build: generate fmt vet ## Build manager binary. go build -o bin/manager main.go @@ -162,25 +159,15 @@ build-vgmanager: generate fmt vet ## Build vg manager binary. build-prometheus-alert-rules: jsonnet monitoring/mixin.libsonnet monitoring/alerts/alerts.jsonnet monitoring/alerts/*.libsonnet $(JSONNET) -S monitoring/alerts/alerts.jsonnet > config/prometheus/prometheus_rules.yaml -run: manifests generate fmt vet ## Run a controller from your host. - go run ./main.go - -docker-build: test ## Build docker image with the manager. +docker-build: ## Build docker image with the manager. $(IMAGE_BUILD_CMD) build -t ${IMG} . -docker-build-vgmanager: ## Build docker image with vgmanager. - $(IMAGE_BUILD_CMD) build -f Dockerfile.vgmanager -t ${VGMANAGER_IMG} . - -docker-build-combined: test ## Build docker image with manager and vgmanager - $(IMAGE_BUILD_CMD) build -f Dockerfile.combined -t ${IMG} . - docker-push: ## Push docker image with the manager. $(IMAGE_BUILD_CMD) push ${IMG} -docker-push-vgmanager: ## Push docker image with the vgmanager. - $(IMAGE_BUILD_CMD) push ${VGMANAGER_IMG} - -docker-push-combined: docker-push ## Push docker image containing both manager and vgmanager binaries +lvms-must-gather: + @echo "Building the lvms-must-gather image" + $(IMAGE_BUILD_CMD) build -f must-gather/Dockerfile -t "${MUST_GATHER_IMG}" must-gather/ ##@ Deployment @@ -199,39 +186,14 @@ deploy: update-mgr-env manifests kustomize ## Deploy controller to the K8s clust undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. $(KUSTOMIZE) build config/default | kubectl delete -f - -deploy-with-olm: kustomize ## Deploy controller to the K8s cluster via OLM +deploy-with-olm: kustomize ## Deploy controller to the K8s cluster via OLM. cd olm-deploy/ && $(KUSTOMIZE) edit set image catalog-img=${CATALOG_IMG} $(KUSTOMIZE) build olm-deploy/ | sed "s/lvms-operator.v.*/lvms-operator.v${VERSION}/g" | kubectl create -f - -undeploy-with-olm: ## Undeploy controller from the K8s cluster +undeploy-with-olm: ## Undeploy controller from the K8s cluster. $(KUSTOMIZE) build olm-deploy/ | kubectl delete -f - - -CONTROLLER_GEN = $(shell pwd)/bin/controller-gen -controller-gen: ## Download controller-gen locally if necessary. - $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0) - -KUSTOMIZE = $(shell pwd)/bin/kustomize -kustomize: ## Download kustomize locally if necessary. - $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.3) - -ENVTEST = $(shell pwd)/bin/setup-envtest -envtest: ## Download envtest-setup locally if necessary. - $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) - -JSONNET = $(shell pwd)/bin/jsonnet -jsonnet: ## Download jsonnet locally if necessary. - $(call go-get-tool,$(JSONNET),github.com/google/go-jsonnet/cmd/jsonnet@latest) - -GINKGO = $(shell pwd)/bin/ginkgo -ginkgo: ## Download ginkgo and gomega locally if necessary. - $(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2) - -# go-get-tool will 'go get' any package $2 and install it to $1. -PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) -define go-get-tool -@[ -f $(1) ] || echo "Downloading $(2)"; GOBIN=$(PROJECT_DIR)/bin go install -mod=readonly $(2) -endef +##@ Bundle image .PHONY: rename-csv rename-csv: @@ -264,31 +226,7 @@ bundle-build: ## Build the bundle image. bundle-push: ## Push the bundle image. $(MAKE) docker-push IMG=$(BUNDLE_IMG) -.PHONY: opm -OPM = ./bin/opm -opm: ## Download opm locally if necessary. -ifeq (,$(wildcard $(OPM))) -ifeq (,$(shell which opm 2>/dev/null)) - @{ \ - set -e ;\ - mkdir -p $(dir $(OPM)) ;\ - OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ - curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.26.2/$${OS}-$${ARCH}-opm ;\ - chmod +x $(OPM) ;\ - } -else -OPM = $(shell which opm) -endif -endif - -.PHONY: operator-sdk -OPERATOR_SDK = ./bin/operator-sdk -operator-sdk: ## Download operator-sdk locally - set -e ;\ - mkdir -p $(dir $(OPERATOR_SDK)) ;\ - OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ - curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_$${OS}_$${ARCH};\ - chmod +x $(OPERATOR_SDK) ;\ +##@ Catalog image # A comma-separated list of bundle images (e.g. make catalog-build BUNDLE_IMGS=example.com/operator-bundle:v0.1.0,example.com/operator-bundle:v0.2.0). # These images MUST exist in a registry and be pull-able. @@ -315,9 +253,7 @@ catalog-build: opm ## Build a catalog image. catalog-push: ## Push a catalog image. $(MAKE) docker-push IMG=$(CATALOG_IMG) -lvms-must-gather: - @echo "Building the lvms-must-gather image" - $(IMAGE_BUILD_CMD) build -f must-gather/Dockerfile -t "${MUST_GATHER_FULL_IMAGE_NAME}" must-gather/ +##@ E2E tests # Variables required to run and build LVM end to end tests. LVM_OPERATOR_INSTALL ?= true @@ -327,8 +263,62 @@ SUBSCRIPTION_CHANNEL ?= alpha # Handles only AWS as of now. DISK_INSTALL ?= false -# Build and run lvm tests. -e2e-test: ginkgo +# Build and run e2e tests. +e2e-test: ginkgo ## Build and run e2e tests. @echo "build and run e2e tests" cd e2e && $(GINKGO) build cd e2e && ./e2e.test --lvm-catalog-image=$(CATALOG_IMG) --lvm-subscription-channel=$(SUBSCRIPTION_CHANNEL) --lvm-operator-install=$(LVM_OPERATOR_INSTALL) --lvm-operator-uninstall=$(LVM_OPERATOR_UNINSTALL) --disk-install=$(DISK_INSTALL) -ginkgo.v + +##@ Tools + +CONTROLLER_GEN = $(shell pwd)/bin/controller-gen +controller-gen: ## Download controller-gen locally if necessary. + $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.7.0) + +KUSTOMIZE = $(shell pwd)/bin/kustomize +kustomize: ## Download kustomize locally if necessary. + $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.3) + +ENVTEST = $(shell pwd)/bin/setup-envtest +envtest: ## Download envtest-setup locally if necessary. + $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest) + +JSONNET = $(shell pwd)/bin/jsonnet +jsonnet: ## Download jsonnet locally if necessary. + $(call go-get-tool,$(JSONNET),github.com/google/go-jsonnet/cmd/jsonnet@latest) + +GINKGO = $(shell pwd)/bin/ginkgo +ginkgo: ## Download ginkgo and gomega locally if necessary. + $(call go-get-tool,$(GINKGO),github.com/onsi/ginkgo/v2/ginkgo@v2) + +# go-get-tool will 'go get' any package $2 and install it to $1. +PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) +define go-get-tool +@[ -f $(1) ] || echo "Downloading $(2)"; GOBIN=$(PROJECT_DIR)/bin go install -mod=readonly $(2) +endef + +.PHONY: opm +OPM = ./bin/opm +opm: ## Download opm locally if necessary. +ifeq (,$(wildcard $(OPM))) +ifeq (,$(shell which opm 2>/dev/null)) + @{ \ + set -e ;\ + mkdir -p $(dir $(OPM)) ;\ + OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ + curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.26.2/$${OS}-$${ARCH}-opm ;\ + chmod +x $(OPM) ;\ + } +else +OPM = $(shell which opm) +endif +endif + +.PHONY: operator-sdk +OPERATOR_SDK = ./bin/operator-sdk +operator-sdk: ## Download operator-sdk locally. + set -e ;\ + mkdir -p $(dir $(OPERATOR_SDK)) ;\ + OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \ + curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_$${OS}_$${ARCH};\ + chmod +x $(OPERATOR_SDK) ;\ diff --git a/api/v1alpha1/groupversion_info.go b/api/v1alpha1/groupversion_info.go index 87b035888..944093509 100644 --- a/api/v1alpha1/groupversion_info.go +++ b/api/v1alpha1/groupversion_info.go @@ -15,8 +15,8 @@ limitations under the License. */ // Package v1alpha1 contains API Schema definitions for the lvm v1alpha1 API group -//+kubebuilder:object:generate=true -//+groupName=lvm.topolvm.io +// +kubebuilder:object:generate=true +// +groupName=lvm.topolvm.io package v1alpha1 import ( diff --git a/controllers/defaults.go b/controllers/defaults.go index 975ef53f0..77ce5f188 100644 --- a/controllers/defaults.go +++ b/controllers/defaults.go @@ -29,9 +29,6 @@ var ( "CSI_LIVENESSPROBE_IMAGE": "k8s.gcr.io/sig-storage/livenessprobe:v2.8.0", "CSI_RESIZER_IMAGE": "k8s.gcr.io/sig-storage/csi-resizer:v1.6.0", "CSI_SNAPSHOTTER_IMAGE": "k8s.gcr.io/sig-storage/csi-snapshotter:v6.1.0", - - // not being used, only for reference - "VGMANAGER_IMAGE": "quay.io/lvms_dev/vgmanager:latest", } OperatorNamespace = GetEnvOrDefault("OPERATOR_NAMESPACE") diff --git a/controllers/lvmcluster_controller_test.go b/controllers/lvmcluster_controller_test.go index f48c1915a..cac094a1b 100644 --- a/controllers/lvmcluster_controller_test.go +++ b/controllers/lvmcluster_controller_test.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "os" "time" . "github.com/onsi/ginkgo" @@ -114,7 +113,6 @@ var _ = Describe("LVMCluster controller", func() { } scOut := &storagev1.StorageClass{} - os.Setenv("VGMANAGER_IMAGE", "test") Context("Reconciliation on creating an LVMCluster CR", func() { It("should reconcile LVMCluster CR creation, ", func() { By("verifying CR status on reconciliation") diff --git a/controllers/vgmanager_daemonset.go b/controllers/vgmanager_daemonset.go index d087ed018..6bfa21d09 100644 --- a/controllers/vgmanager_daemonset.go +++ b/controllers/vgmanager_daemonset.go @@ -17,8 +17,6 @@ limitations under the License. package controllers import ( - "os" - lvmv1alpha1 "github.com/openshift/lvm-operator/api/v1alpha1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -123,13 +121,6 @@ func newVGManagerDaemonset(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, privileged := true var zero int64 = 0 - // try to get vgmanager image from env and on absence get from running pod - // TODO: investigate why storing this env in a variable is failing tests - image := os.Getenv("VGMANAGER_IMAGE") - if image == "" { - image = vgImage - } - command := []string{ "/vgmanager", } @@ -143,7 +134,7 @@ func newVGManagerDaemonset(lvmCluster *lvmv1alpha1.LVMCluster, namespace string, containers := []corev1.Container{ { Name: VGManagerUnit, - Image: image, + Image: vgImage, Command: command, SecurityContext: &corev1.SecurityContext{ Privileged: &privileged, diff --git a/controllers/vgmanager_test.go b/controllers/vgmanager_test.go index 2ba6bd97f..2ecdc9a66 100644 --- a/controllers/vgmanager_test.go +++ b/controllers/vgmanager_test.go @@ -18,7 +18,6 @@ package controllers import ( "context" - "os" "testing" snapapi "github.com/kubernetes-csi/external-snapshotter/client/v4/apis/volumesnapshot/v1" @@ -95,7 +94,6 @@ func TestVGManagerEnsureCreated(t *testing.T) { }, Spec: testCase.lvmclusterSpec, } - os.Setenv("VGMANAGER_IMAGE", "test") r := newFakeLVMClusterReconciler(t, lvmcluster) var unit resourceManager = vgManager{} err := unit.ensureCreated(r, context.Background(), lvmcluster) diff --git a/doc/usage/install.md b/doc/usage/install.md index 39c702760..483ff3e51 100644 --- a/doc/usage/install.md +++ b/doc/usage/install.md @@ -17,7 +17,7 @@ export IMG=quay.io/USER/lvms-operator Then start the build process like this: ``` -make docker-build-combined docker-push +make docker-build docker-push ``` Ensure that the new repository in your registry is either set to public or that your target OpenShift cluster has read access to that repository.