github.com/openshift/dpu-operator@v0.0.0-20240502153209-3af840d137c2/Makefile (about)

     1  # VERSION defines the project version for the bundle.
     2  # Update this value when you upgrade the version of your project.
     3  # To re-generate a bundle for another specific version without changing the standard setup, you can:
     4  # - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
     5  # - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
     6  VERSION ?= 4.16.0
     7  
     8  # CHANNELS define the bundle channels used in the bundle.
     9  # Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
    10  # To re-generate a bundle for other specific channels without changing the standard setup, you can:
    11  # - use the CHANNELS as arg of the bundle target (e.g make bundle CHANNELS=candidate,fast,stable)
    12  # - use environment variables to overwrite this value (e.g export CHANNELS="candidate,fast,stable")
    13  ifneq ($(origin CHANNELS), undefined)
    14  BUNDLE_CHANNELS := --channels=$(CHANNELS)
    15  endif
    16  
    17  # DEFAULT_CHANNEL defines the default channel used in the bundle.
    18  # Add a new line here if you would like to change its default config. (E.g DEFAULT_CHANNEL = "stable")
    19  # To re-generate a bundle for any other default channel without changing the default setup, you can:
    20  # - use the DEFAULT_CHANNEL as arg of the bundle target (e.g make bundle DEFAULT_CHANNEL=stable)
    21  # - use environment variables to overwrite this value (e.g export DEFAULT_CHANNEL="stable")
    22  ifneq ($(origin DEFAULT_CHANNEL), undefined)
    23  BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL)
    24  endif
    25  BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL)
    26  
    27  # IMAGE_TAG_BASE defines the docker.io namespace and part of the image name for remote images.
    28  # This variable is used to construct full image tags for bundle and catalog images.
    29  #
    30  # For example, running 'make bundle-build bundle-push catalog-build catalog-push' will build and push both
    31  # openshift.io/dpu-operator-bundle:$VERSION and openshift.io/dpu-operator-catalog:$VERSION.
    32  IMAGE_TAG_BASE ?= openshift.io/dpu-operator
    33  
    34  # BUNDLE_IMG defines the image:tag used for the bundle.
    35  # You can use it as an arg. (E.g make bundle-build BUNDLE_IMG=<some-registry>/<project-name-bundle>:<tag>)
    36  BUNDLE_IMG ?= $(IMAGE_TAG_BASE)-bundle:v$(VERSION)
    37  
    38  # BUNDLE_GEN_FLAGS are the flags passed to the operator-sdk generate bundle command
    39  BUNDLE_GEN_FLAGS ?= -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
    40  
    41  # USE_IMAGE_DIGESTS defines if images are resolved via tags or digests
    42  # You can enable this value if you would like to use SHA Based Digests
    43  # To enable set flag to true
    44  USE_IMAGE_DIGESTS ?= false
    45  ifeq ($(USE_IMAGE_DIGESTS), true)
    46  	BUNDLE_GEN_FLAGS += --use-image-digests
    47  endif
    48  
    49  # Set the Operator SDK version to use. By default, what is installed on the system is used.
    50  # This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
    51  OPERATOR_SDK_VERSION ?= v1.33.0
    52  
    53  # Image URL to use all building/pushing image targets
    54  IMG ?= controller:latest
    55  # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
    56  ENVTEST_K8S_VERSION = 1.27.1
    57  
    58  # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
    59  ifeq (,$(shell go env GOBIN))
    60  GOBIN=$(shell go env GOPATH)/bin
    61  else
    62  GOBIN=$(shell go env GOBIN)
    63  endif
    64  
    65  # CONTAINER_TOOL defines the container tool to be used for building images.
    66  # Be aware that the target commands are only tested with Docker which is
    67  # scaffolded by default. However, you might want to replace it to use other
    68  # tools. (i.e. podman)
    69  CONTAINER_TOOL ?= podman
    70  
    71  
    72  # Use the image urls from the yaml that is used with Kustomize for local
    73  # development.
    74  DPU_OPERATOR_IMAGE := $(shell yq -r .spec.template.spec.containers[0].image config/dev/local-images.yaml)
    75  DPU_DAEMON_IMAGE := $(shell yq -r .spec.template.spec.containers[0].env[0].value config/dev/local-images.yaml)
    76  
    77  # Setting SHELL to bash allows bash commands to be executed by recipes.
    78  # Options are set to exit when a recipe line exits non-zero or a piped command fails.
    79  SHELL = /usr/bin/env bash -o pipefail
    80  .SHELLFLAGS = -ec
    81  
    82  .PHONY: all
    83  all: build
    84  
    85  ##@ General
    86  
    87  # The help target prints out all targets with their descriptions organized
    88  # beneath their categories. The categories are represented by '##@' and the
    89  # target descriptions by '##'. The awk commands is responsible for reading the
    90  # entire set of makefiles included in this invocation, looking for lines of the
    91  # file as xyz: ## something, and then pretty-format the target and help. Then,
    92  # if there's a line with ##@ something, that gets pretty-printed as a category.
    93  # More info on the usage of ANSI control characters for terminal formatting:
    94  # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
    95  # More info on the awk command:
    96  # http://linuxcommand.org/lc3_adv_awk.php
    97  
    98  .PHONY: help
    99  help: ## Display this help.
   100  	@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n  make \033[36m<target>\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)
   101  
   102  ##@ Development
   103  
   104  .PHONY: manifests
   105  manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
   106  	GOFLAGS='' $(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
   107  
   108  .PHONY: generate
   109  generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
   110  	GOFLAGS='' $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
   111  
   112  .PHONY: fmt
   113  fmt: ## Run go fmt against code.
   114  	go fmt ./...
   115  
   116  .PHONY: vet
   117  vet: ## Run go vet against code.
   118  	go vet ./...
   119  
   120  .PHONY: test
   121  test: manifests generate fmt vet envtest ## Run tests.
   122  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
   123  
   124  ##@ Build
   125  
   126  .PHONY: build
   127  build: manifests generate fmt vet ## Build manager binary.
   128  	go build -o bin/manager cmd/main.go
   129  
   130  .PHONY: run
   131  run: manifests generate fmt vet ## Run a controller from your host.
   132  	go run ./cmd/main.go
   133  
   134  # If you wish built the manager image targeting other platforms you can use the --platform flag.
   135  # (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
   136  # More info: https://docs.docker.com/develop/develop-images/build_enhancements/
   137  .PHONY: docker-build
   138  docker-build: test ## Build docker image with the manager.
   139  	$(CONTAINER_TOOL) build -t ${IMG} .
   140  
   141  .PHONY: docker-push
   142  docker-push: ## Push docker image with the manager.
   143  	$(CONTAINER_TOOL) push ${IMG}
   144  
   145  GO_CONTAINER_CACHE = /tmp/dpu-operator-cache
   146  
   147  .PHONY: images-build
   148  images-build: ## Build all container images necessary to run the whole operator
   149  	mkdir -p $(GO_CONTAINER_CACHE)
   150  	$(CONTAINER_TOOL) build -v $(GO_CONTAINER_CACHE):/go:z -f Dockerfile.rhel -t $(DPU_OPERATOR_IMAGE)
   151  	$(CONTAINER_TOOL) build -v $(GO_CONTAINER_CACHE):/go:z -f Dockerfile.daemon.rhel -t $(DPU_DAEMON_IMAGE)
   152  
   153  .PHONY: images-buildx
   154  images-buildx: ## Build all container images necessary to run the whole operator
   155  	mkdir -p $(GO_CONTAINER_CACHE)
   156  	buildah manifest rm $(DPU_OPERATOR_IMAGE)-manifest || true
   157  	buildah manifest create $(DPU_OPERATOR_IMAGE)-manifest
   158  	buildah build --authfile /root/config.json --manifest $(DPU_OPERATOR_IMAGE)-manifest --platform linux/amd64,linux/arm64 -v $(GO_CONTAINER_CACHE):/go:z -f Dockerfile.rhel -t $(DPU_OPERATOR_IMAGE)
   159  	buildah manifest push --all $(DPU_OPERATOR_IMAGE)-manifest docker://$(DPU_OPERATOR_IMAGE)
   160  	buildah manifest rm $(DPU_DAEMON_IMAGE)-manifest || true
   161  	buildah manifest create $(DPU_DAEMON_IMAGE)-manifest
   162  	buildah build --authfile /root/config.json --manifest $(DPU_DAEMON_IMAGE)-manifest --platform linux/amd64,linux/arm64 -v $(GO_CONTAINER_CACHE):/go:z -f Dockerfile.daemon.rhel -t $(DPU_DAEMON_IMAGE)
   163  	buildah manifest push --all $(DPU_DAEMON_IMAGE)-manifest docker://$(DPU_DAEMON_IMAGE)
   164  
   165  .PHONY: images-push
   166  images-push: test ## Push all container images necessary to run the whole operator
   167  	$(CONTAINER_TOOL) push $(DPU_OPERATOR_IMAGE)
   168  	$(CONTAINER_TOOL) push $(DPU_DAEMON_IMAGE)
   169  # PLATFORMS defines the target platforms for  the manager image be build to provide support to multiple
   170  # architectures. (i.e. make docker-buildx IMG=myregistry/mypoperator:0.0.1). To use this option you need to:
   171  # - able to use docker buildx . More info: https://docs.docker.com/build/buildx/
   172  # - have enable BuildKit, More info: https://docs.docker.com/develop/develop-images/build_enhancements/
   173  # - be able to push the image for your registry (i.e. if you do not inform a valid value via IMG=<myregistry/image:<tag>> then the export will fail)
   174  # To properly provided solutions that supports more than one platform you should use this option.
   175  PLATFORMS ?= linux/arm64,linux/amd64,linux/s390x,linux/ppc64le
   176  .PHONY: docker-buildx
   177  docker-buildx: test ## Build and push docker image for the manager for cross-platform support
   178  	# copy existing Dockerfile and insert --platform=${BUILDPLATFORM} into Dockerfile.cross, and preserve the original Dockerfile
   179  	sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross
   180  	- $(CONTAINER_TOOL) buildx create --name project-v3-builder
   181  	$(CONTAINER_TOOL) buildx use project-v3-builder
   182  	- $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross .
   183  	- $(CONTAINER_TOOL) buildx rm project-v3-builder
   184  	rm Dockerfile.cross
   185  
   186  ##@ Deployment
   187  
   188  ifndef ignore-not-found
   189    ignore-not-found = false
   190  endif
   191  
   192  .PHONY: install
   193  install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
   194  	$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
   195  
   196  .PHONY: uninstall
   197  uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
   198  	$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
   199  
   200  .PHONY: deploy
   201  deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
   202  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
   203  	$(KUSTOMIZE) build config/default | $(KUBECTL) apply -f -
   204  
   205  .PHONY: local-deploy
   206  local-deploy: manifests kustomize ## Deploy controller with images hosted on local registry
   207  	$(KUSTOMIZE) build config/dev | $(KUBECTL) apply -f -
   208  
   209  .PHONY: undeploy
   210  undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
   211  	$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
   212  
   213  ##@ Build Dependencies
   214  
   215  ## Location to install dependencies to
   216  LOCALBIN ?= $(shell pwd)/bin
   217  $(LOCALBIN):
   218  	mkdir -p $(LOCALBIN)
   219  
   220  ## Tool Binaries
   221  KUBECTL ?= kubectl
   222  KUSTOMIZE ?= $(LOCALBIN)/kustomize
   223  CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
   224  ENVTEST ?= $(LOCALBIN)/setup-envtest
   225  
   226  ## Tool Versions
   227  KUSTOMIZE_VERSION ?= v5.0.1
   228  CONTROLLER_TOOLS_VERSION ?= v0.12.0
   229  
   230  .PHONY: kustomize
   231  kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
   232  $(KUSTOMIZE): $(LOCALBIN)
   233  	@if test -x $(LOCALBIN)/kustomize && ! $(LOCALBIN)/kustomize version | grep -q $(KUSTOMIZE_VERSION); then \
   234  		echo "$(LOCALBIN)/kustomize version is not expected $(KUSTOMIZE_VERSION). Removing it before installing."; \
   235  		rm -rf $(LOCALBIN)/kustomize; \
   236  	fi
   237  	test -s $(LOCALBIN)/kustomize || GOBIN=$(LOCALBIN) GOFLAGS='' GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
   238  
   239  .PHONY: controller-gen
   240  controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
   241  $(CONTROLLER_GEN): $(LOCALBIN)
   242  	test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
   243  	GOBIN=$(LOCALBIN) GOFLAGS='' go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
   244  
   245  .PHONY: envtest
   246  envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
   247  $(ENVTEST): $(LOCALBIN)
   248  	test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) GOFLAGS='' go install sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.16
   249  
   250  .PHONY: operator-sdk
   251  OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
   252  operator-sdk: ## Download operator-sdk locally if necessary.
   253  ifeq (,$(wildcard $(OPERATOR_SDK)))
   254  ifeq (, $(shell which operator-sdk 2>/dev/null))
   255  	@{ \
   256  	set -e ;\
   257  	mkdir -p $(dir $(OPERATOR_SDK)) ;\
   258  	OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
   259  	curl -sSLo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/$(OPERATOR_SDK_VERSION)/operator-sdk_$${OS}_$${ARCH} ;\
   260  	chmod +x $(OPERATOR_SDK) ;\
   261  	}
   262  else
   263  OPERATOR_SDK = $(shell which operator-sdk)
   264  endif
   265  endif
   266  
   267  .PHONY: bundle
   268  bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
   269  	$(OPERATOR_SDK) generate kustomize manifests -q
   270  	cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
   271  	$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
   272  	$(OPERATOR_SDK) bundle validate ./bundle
   273  	cp bundle/manifests/* manifests/stable
   274  
   275  .PHONY: bundle-build
   276  bundle-build: ## Build the bundle image.
   277  	docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
   278  
   279  .PHONY: bundle-push
   280  bundle-push: ## Push the bundle image.
   281  	$(MAKE) docker-push IMG=$(BUNDLE_IMG)
   282  
   283  .PHONY: opm
   284  OPM = $(LOCALBIN)/opm
   285  opm: ## Download opm locally if necessary.
   286  ifeq (,$(wildcard $(OPM)))
   287  ifeq (,$(shell which opm 2>/dev/null))
   288  	@{ \
   289  	set -e ;\
   290  	mkdir -p $(dir $(OPM)) ;\
   291  	OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
   292  	curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
   293  	chmod +x $(OPM) ;\
   294  	}
   295  else
   296  OPM = $(shell which opm)
   297  endif
   298  endif
   299  
   300  # 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).
   301  # These images MUST exist in a registry and be pull-able.
   302  BUNDLE_IMGS ?= $(BUNDLE_IMG)
   303  
   304  # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
   305  CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
   306  
   307  # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
   308  ifneq ($(origin CATALOG_BASE_IMG), undefined)
   309  FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
   310  endif
   311  
   312  # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
   313  # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
   314  # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
   315  .PHONY: catalog-build
   316  catalog-build: opm ## Build a catalog image.
   317  	$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
   318  
   319  # Push the catalog image.
   320  .PHONY: catalog-push
   321  catalog-push: ## Push a catalog image.
   322  	$(MAKE) docker-push IMG=$(CATALOG_IMG)
   323  
   324  proto:
   325  	rm -rf dpu-api/gen
   326  	mkdir -p dpu-api/gen
   327  	cd dpu-api && protoc --go_out=gen --go_opt=paths=source_relative \
   328  		--go-grpc_out=gen --go-grpc_opt=paths=source_relative \
   329  		api.proto