github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/Makefile (about) 1 # Setting SHELL to bash allows bash commands to be executed by recipes. 2 # This is a requirement for 'setup-envtest.sh' in the test target. 3 # Options are set to exit when a recipe line exits non-zero or a piped command fails. 4 SHELL = /usr/bin/env bash -o pipefail 5 .SHELLFLAGS = -ec 6 CURPATH=$(PWD) 7 TARGET_DIR=$(CURPATH)/build/_output 8 BIN_DIR=$(CURPATH)/bin 9 KUBECONFIG?=$(HOME)/.kube/config 10 export OPERATOR_EXEC?=oc 11 12 BUILD_GOPATH=$(TARGET_DIR):$(TARGET_DIR)/vendor:$(CURPATH)/cmd 13 IMAGE_BUILDER?=docker 14 IMAGE_BUILD_OPTS?= 15 DOCKERFILE?=Dockerfile 16 DOCKERFILE_CONFIG_DAEMON?=Dockerfile.sriov-network-config-daemon 17 DOCKERFILE_WEBHOOK?=Dockerfile.webhook 18 19 CRD_BASES=./config/crd/bases 20 21 export APP_NAME?=sriov-network-operator 22 TARGET=$(TARGET_DIR)/bin/$(APP_NAME) 23 IMAGE_REPO?=ghcr.io/k8snetworkplumbingwg 24 IMAGE_TAG?=$(IMAGE_REPO)/$(APP_NAME):latest 25 CONFIG_DAEMON_IMAGE_TAG?=$(IMAGE_REPO)/$(APP_NAME)-config-daemon:latest 26 WEBHOOK_IMAGE_TAG?=$(IMAGE_REPO)/$(APP_NAME)-webhook:latest 27 MAIN_PKG=cmd/manager/main.go 28 export NAMESPACE?=openshift-sriov-network-operator 29 export WATCH_NAMESPACE?=openshift-sriov-network-operator 30 export GOFLAGS+=-mod=vendor 31 export GO111MODULE=on 32 PKGS=$(shell go list ./... | grep -v -E '/vendor/|/test|/examples') 33 TESTPKGS?=./... 34 35 # go source files, ignore vendor directory 36 SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*") 37 38 ifneq ($(origin CHANNELS), undefined) 39 BUNDLE_CHANNELS := --channels=$(CHANNELS) 40 endif 41 ifneq ($(origin DEFAULT_CHANNEL), undefined) 42 BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) 43 endif 44 BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) 45 46 # Image URL to use all building/pushing image targets 47 IMG ?= controller:latest 48 # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) 49 CRD_OPTIONS ?= "crd:crdVersions={v1}" 50 51 GOLANGCI_LINT = $(BIN_DIR)/golangci-lint 52 # golangci-lint version should be updated periodically 53 # we keep it fixed to avoid it from unexpectedly failing on the project 54 # in case of a version bump 55 GOLANGCI_LINT_VER = v1.55.2 56 57 58 .PHONY: all build clean gendeepcopy test test-e2e test-e2e-k8s run image fmt sync-manifests test-e2e-conformance manifests update-codegen 59 60 all: generate lint build 61 62 build: manager _build-sriov-network-config-daemon _build-webhook 63 64 _build-%: 65 WHAT=$* hack/build-go.sh 66 67 clean: 68 @rm -rf $(TARGET_DIR) 69 @rm -rf $(BIN_DIR) 70 71 update-codegen: 72 hack/update-codegen.sh 73 74 image: ; $(info Building images...) 75 $(IMAGE_BUILDER) build -f $(DOCKERFILE) -t $(IMAGE_TAG) $(CURPATH) $(IMAGE_BUILD_OPTS) 76 $(IMAGE_BUILDER) build -f $(DOCKERFILE_CONFIG_DAEMON) -t $(CONFIG_DAEMON_IMAGE_TAG) $(CURPATH) $(IMAGE_BUILD_OPTS) 77 $(IMAGE_BUILDER) build -f $(DOCKERFILE_WEBHOOK) -t $(WEBHOOK_IMAGE_TAG) $(CURPATH) $(IMAGE_BUILD_OPTS) 78 79 # Run tests 80 test: generate lint manifests envtest 81 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)" HOME="$(shell pwd)" go test -coverprofile cover.out -v ${TESTPKGS} 82 83 # Build manager binary 84 manager: generate _build-manager 85 86 # Run against the configured Kubernetes cluster in ~/.kube/config 87 run: skopeo install 88 hack/run-locally.sh 89 90 # Install CRDs into a cluster 91 install: manifests kustomize 92 $(KUSTOMIZE) build config/crd | kubectl apply -f - 93 94 # Uninstall CRDs from a cluster 95 uninstall: manifests kustomize 96 $(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found -f - 97 98 # Deploy controller in the configured Kubernetes cluster in ~/.kube/config 99 # deploy: manifests kustomize 100 # cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 101 # $(KUSTOMIZE) build config/default | kubectl apply -f - 102 103 # UnDeploy controller from the configured Kubernetes cluster in ~/.kube/config 104 # undeploy: 105 # $(KUSTOMIZE) build config/default | kubectl delete -f - 106 107 # Generate manifests e.g. CRD, RBAC etc. 108 manifests: controller-gen 109 $(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=$(CRD_BASES) 110 cp ./config/crd/bases/* ./deployment/sriov-network-operator/crds/ 111 112 113 sync-manifests-%: manifests 114 @mkdir -p manifests/$* 115 sed '2{/---/d}' $(CRD_BASES)/sriovnetwork.openshift.io_sriovibnetworks.yaml | awk 'NF' > manifests/$*/sriov-network-operator-sriovibnetworks_crd.yaml 116 sed '2{/---/d}' $(CRD_BASES)/sriovnetwork.openshift.io_sriovnetworknodepolicies.yaml | awk 'NF' > manifests/$*/sriov-network-operator-sriovnetworknodepolicy.crd.yaml 117 sed '2{/---/d}' $(CRD_BASES)/sriovnetwork.openshift.io_sriovnetworknodestates.yaml | awk 'NF' > manifests/$*/sriov-network-operator-sriovnetworknodestate.crd.yaml 118 sed '2{/---/d}' $(CRD_BASES)/sriovnetwork.openshift.io_sriovoperatorconfigs.yaml | awk 'NF' > manifests/$*/sriov-network-operator-sriovoperatorconfig.crd.yaml 119 sed '2{/---/d}' $(CRD_BASES)/sriovnetwork.openshift.io_sriovnetworks.yaml | awk 'NF' > manifests/$*/sriov-network-operator-sriovnetwork.crd.yaml 120 @echo "" 121 @echo "*************************************************************************************************************************************************" 122 @echo "* Please manually update the sriov-network-operator.v4.7.0.clusterserviceversion.yaml and image-references files in the manifests/$* directory *" 123 @echo "*************************************************************************************************************************************************" 124 @echo "" 125 126 127 # Run go fmt against code 128 129 fmt: ## Go fmt your code 130 CONTAINER_CMD=$(IMAGE_BUILDER) hack/go-fmt.sh . 131 132 # Run go fmt against code 133 fmt-code: 134 go fmt ./... 135 136 # Generate code 137 generate: controller-gen 138 $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." 139 140 mock-generate: gomock 141 go generate ./... 142 143 CONTROLLER_GEN = $(BIN_DIR)/controller-gen 144 controller-gen: ## Download controller-gen locally if necessary. 145 $(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0) 146 147 KUSTOMIZE = $(BIN_DIR)/kustomize 148 kustomize: ## Download kustomize locally if necessary. 149 $(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v4@v4.5.5) 150 151 ENVTEST = $(BIN_DIR)/setup-envtest 152 envtest: ## Download envtest-setup locally if necessary. 153 $(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16) 154 155 GOMOCK = $(shell pwd)/bin/mockgen 156 gomock: 157 $(call go-install-tool,$(GOMOCK),github.com/golang/mock/mockgen@v1.6.0) 158 159 # go-install-tool will 'go install' any package $2 and install it to $1. 160 define go-install-tool 161 @[ -f $(1) ] || { \ 162 set -e ;\ 163 echo "Downloading $(2)" ;\ 164 GOBIN=$(BIN_DIR) go install -mod=mod $(2) ;\ 165 } 166 endef 167 168 skopeo: 169 if ! which skopeo; then if [ -z ${SKIP_VAR_SET} ]; then if [ -f /etc/redhat-release ]; then dnf -y install skopeo; elif [ -f /etc/lsb-release ]; then sudo apt-get -y update; sudo apt-get -y install skopeo; fi; fi; fi 170 171 fakechroot: 172 if ! which fakechroot; then if [ -f /etc/redhat-release ]; then dnf -y install fakechroot; elif [ -f /etc/lsb-release ]; then sudo apt-get -y update; sudo apt-get -y install fakechroot; fi; fi 173 174 deploy-setup: export ADMISSION_CONTROLLERS_ENABLED?=false 175 deploy-setup: skopeo install 176 hack/deploy-setup.sh $(NAMESPACE) 177 178 deploy-setup-k8s: export NAMESPACE=sriov-network-operator 179 deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin 180 deploy-setup-k8s: export OPERATOR_EXEC=kubectl 181 deploy-setup-k8s: export CLUSTER_TYPE=kubernetes 182 deploy-setup-k8s: deploy-setup 183 184 test-e2e-conformance: 185 SUITE=./test/conformance ./hack/run-e2e-conformance.sh 186 187 test-e2e-conformance-virtual-k8s-cluster-ci: 188 ./hack/run-e2e-conformance-virtual-cluster.sh 189 190 test-e2e-conformance-virtual-k8s-cluster: 191 SKIP_DELETE=TRUE ./hack/run-e2e-conformance-virtual-cluster.sh 192 193 test-e2e-conformance-virtual-ocp-cluster-ci: 194 ./hack/run-e2e-conformance-virtual-ocp.sh 195 196 test-e2e-conformance-virtual-ocp-cluster: 197 SKIP_DELETE=TRUE ./hack/run-e2e-conformance-virtual-ocp.sh 198 199 redeploy-operator-virtual-cluster: 200 ./hack/virtual-cluster-redeploy.sh 201 202 test-e2e-validation-only: 203 SUITE=./test/validation ./hack/run-e2e-conformance.sh 204 205 test-e2e: generate manifests skopeo envtest 206 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)"; source hack/env.sh; HOME="$(shell pwd)" go test ./test/e2e/... -timeout 60m -coverprofile cover.out -v 207 208 test-e2e-k8s: export NAMESPACE=sriov-network-operator 209 test-e2e-k8s: test-e2e 210 211 test-bindata-scripts: fakechroot 212 fakechroot ./test/scripts/enable-kargs_test.sh 213 214 test-%: generate manifests envtest 215 KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)" HOME="$(shell pwd)" go test ./$*/... -coverprofile cover-$*.out -coverpkg ./... -v 216 217 GOCOVMERGE = $(BIN_DIR)/gocovmerge 218 gocovmerge: ## Download gocovmerge locally if necessary. 219 $(call go-install-tool,$(GOCOVMERGE),github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest) 220 221 GCOV2LCOV = $(BIN_DIR)/gcov2lcov 222 gcov2lcov: 223 $(call go-install-tool,$(GCOV2LCOV),github.com/jandelgado/gcov2lcov@v1.0.5) 224 225 merge-test-coverage: gocovmerge gcov2lcov 226 $(GOCOVMERGE) cover-*.out > cover.out 227 $(GCOV2LCOV) -infile cover.out -outfile lcov.out 228 229 deploy-wait: 230 hack/deploy-wait.sh 231 232 undeploy: uninstall 233 @hack/undeploy.sh $(NAMESPACE) 234 235 undeploy-k8s: export NAMESPACE=sriov-network-operator 236 undeploy-k8s: export OPERATOR_EXEC=kubectl 237 undeploy-k8s: undeploy 238 239 deps-update: 240 go mod tidy && \ 241 go mod vendor 242 243 check-deps: deps-update 244 @set +e; git diff --quiet HEAD go.sum go.mod vendor; \ 245 if [ $$? -eq 1 ]; \ 246 then echo -e "\ngo modules are out of date. Please commit after running 'make deps-update' command\n"; \ 247 exit 1; fi 248 249 $(GOLANGCI_LINT): ; $(info installing golangci-lint...) 250 $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VER)) 251 252 .PHONY: lint 253 lint: | $(GOLANGCI_LINT) ; $(info running golangci-lint...) @ ## Run golangci-lint 254 $(GOLANGCI_LINT) run --timeout=10m