github.com/metaprov/modela-operator@v0.0.0-20240118193048-f378be8b74d2/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 ?= 0.0.1
     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  # modela.ai/modela-operator-bundle:$VERSION and modela.ai/modela-operator-catalog:$VERSION.
    32  IMAGE_TAG_BASE ?= ghcr.io/metaprov/modela-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  # Image URL to use all building/pushing image targets
    50  IMG ?= $(IMAGE_TAG_BASE):v$(VERSION)
    51  # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
    52  ENVTEST_K8S_VERSION = 1.24.1
    53  
    54  # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
    55  ifeq (,$(shell go env GOBIN))
    56  GOBIN=$(shell go env GOPATH)/bin
    57  else
    58  GOBIN=$(shell go env GOBIN)
    59  endif
    60  
    61  # Setting SHELL to bash allows bash commands to be executed by recipes.
    62  # This is a requirement for 'setup-envtest.sh' in the test target.
    63  # Options are set to exit when a recipe line exits non-zero or a piped command fails.
    64  SHELL = /usr/bin/env bash -o pipefail
    65  .SHELLFLAGS = -ec
    66  
    67  .PHONY: all
    68  all: build
    69  
    70  ##@ General
    71  
    72  # The help target prints out all targets with their descriptions organized
    73  # beneath their categories. The categories are represented by '##@' and the
    74  # target descriptions by '##'. The awk commands is responsible for reading the
    75  # entire set of makefiles included in this invocation, looking for lines of the
    76  # file as xyz: ## something, and then pretty-format the target and help. Then,
    77  # if there's a line with ##@ something, that gets pretty-printed as a category.
    78  # More info on the usage of ANSI control characters for terminal formatting:
    79  # https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
    80  # More info on the awk command:
    81  # http://linuxcommand.org/lc3_adv_awk.php
    82  
    83  .PHONY: help
    84  help: ## Display this help.
    85  	@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)
    86  
    87  ##@ Development
    88  
    89  .PHONY: manifests
    90  manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
    91  	$(CONTROLLER_GEN) rbac:roleName=modela-manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
    92  
    93  .PHONY: generate
    94  generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
    95  	$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
    96  
    97  .PHONY: fmt
    98  fmt: ## Run go fmt against code.
    99  	go fmt ./...
   100  
   101  .PHONY: vet
   102  vet: ## Run go vet against code.
   103  	go vet ./...
   104  
   105  .PHONY: test
   106  test: manifests generate fmt vet envtest ## Run tests.
   107  	KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test ./... -coverprofile cover.out
   108  
   109  ##@ Build
   110  
   111  .PHONY: build
   112  build: generate fmt vet ## Build manager binary.
   113  	go build -o bin/manager main.go
   114  
   115  .PHONY: run
   116  run: manifests generate fmt vet ## Run a controller from your host.
   117  	go run ./main.go
   118  
   119  .PHONY: prepare-crds
   120  prepare-crds:
   121  	if [ ! -d "./assets/crds" ]; then \
   122  		mkdir ./assets/crds; \
   123  		cd ./assets/crds; \
   124  		git init; \
   125  		git remote add -f origin https://github.com/metaprov/modelaapi.git; \
   126  		git config core.sparseCheckout true; \
   127  		echo "manifests" >> .git/info/sparse-checkout; \
   128  		cd ../..; \
   129  	fi;
   130  	cd ./assets/crds
   131  	git pull origin main --depth 1
   132  
   133  .PHONY: docker-prepare
   134  docker-prepare:
   135  	mkdir -p ./out/config/assets/charts/
   136  	wget https://charts.jetstack.io/charts/cert-manager-v1.9.1.tgz -O ./cert-manager.tgz
   137  	wget https://charts.bitnami.com/bitnami/minio-11.7.10.tgz -O ./minio.tgz
   138  	wget https://charts.bitnami.com/bitnami/postgresql-11.6.16.tgz -O ./postgres.tgz
   139  	wget https://github.com/prometheus-community/helm-charts/releases/download/prometheus-15.10.4/prometheus-15.10.4.tgz -O ./prometheus.tgz
   140  	wget https://github.com/grafana/helm-charts/releases/download/helm-loki-3.0.7/loki-3.0.7.tgz -O ./loki.tgz
   141  	wget https://github.com/grafana/helm-charts/releases/download/grafana-6.45.1/grafana-6.45.1.tgz -O ./grafana.tgz
   142  	wget https://github.com/kubernetes/ingress-nginx/releases/download/helm-chart-4.2.5/ingress-nginx-4.2.5.tgz -O ./nginx.tgz
   143  	wget https://charts.bitnami.com/bitnami/redis-17.3.8.tgz -O ./redis.tgz
   144  	wget https://helm.releases.hashicorp.com/vault-0.23.0.tgz -O ./vault.tgz
   145  	wget https://charts.bitnami.com/bitnami/mongodb-14.0.13.tgz -O ./mongo.tgz
   146  	tar -xf ./cert-manager.tgz -C ./assets/charts/
   147  	tar -xf ./minio.tgz -C ./assets/charts/
   148  	tar -xf ./postgres.tgz -C ./assets/charts/
   149  	tar -xf ./prometheus.tgz -C ./assets/charts/
   150  	tar -xf ./loki.tgz -C ./assets/charts/
   151  	tar -xf ./grafana.tgz -C ./assets/charts/
   152  	tar -xf ./nginx.tgz -C ./assets/charts
   153  	tar -xf ./redis.tgz -C ./assets/charts
   154  	tar -xf ./vault.tgz -C ./assets/charts
   155  	tar -xf ./mongo.tgz -C ./assets/charts
   156  
   157  
   158  .PHONY: docker-build
   159  docker-build: ## Build docker image with the manager.
   160  	docker build -t ${IMG} .
   161  
   162  .PHONY: docker-push
   163  docker-push: ## Push docker image with the manager.
   164  	docker push ${IMG}
   165  
   166  ##@ Deployment
   167  
   168  ifndef ignore-not-found
   169    ignore-not-found = false
   170  endif
   171  
   172  .PHONY: install
   173  install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
   174  	$(KUSTOMIZE) build config/crd | kubectl apply -f -
   175  
   176  .PHONY: uninstall
   177  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.
   178  	$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
   179  
   180  .PHONY: deploy
   181  deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
   182  	cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
   183  	$(KUSTOMIZE) build config/default | kubectl apply -f -
   184  
   185  .PHONY: undeploy
   186  undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
   187  	$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
   188  
   189  ##@ Build Dependencies
   190  
   191  ## Location to install dependencies to
   192  LOCALBIN ?= $(shell pwd)/bin
   193  $(LOCALBIN):
   194  	mkdir -p $(LOCALBIN)
   195  
   196  ## Tool Binaries
   197  KUSTOMIZE ?= $(LOCALBIN)/kustomize
   198  CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
   199  ENVTEST ?= $(LOCALBIN)/setup-envtest
   200  
   201  ## Tool Versions
   202  KUSTOMIZE_VERSION ?= v3.8.7
   203  CONTROLLER_TOOLS_VERSION ?= v0.13.0
   204  
   205  KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
   206  .PHONY: kustomize
   207  kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
   208  $(KUSTOMIZE): $(LOCALBIN)
   209  	curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN)
   210  
   211  .PHONY: controller-gen
   212  controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
   213  $(CONTROLLER_GEN): $(LOCALBIN)
   214  	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
   215  
   216  .PHONY: envtest
   217  envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
   218  $(ENVTEST): $(LOCALBIN)
   219  	GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
   220  
   221  .PHONY: bundle
   222  bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
   223  	operator-sdk generate kustomize manifests -q
   224  	cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
   225  	$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle $(BUNDLE_GEN_FLAGS)
   226  	operator-sdk bundle validate ./bundle
   227  
   228  .PHONY: bundle-build
   229  bundle-build: ## Build the bundle image.
   230  	docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) .
   231  
   232  .PHONY: bundle-push
   233  bundle-push: ## Push the bundle image.
   234  	$(MAKE) docker-push IMG=$(BUNDLE_IMG)
   235  
   236  .PHONY: opm
   237  OPM = ./bin/opm
   238  opm: ## Download opm locally if necessary.
   239  ifeq (,$(wildcard $(OPM)))
   240  ifeq (,$(shell which opm 2>/dev/null))
   241  	@{ \
   242  	set -e ;\
   243  	mkdir -p $(dir $(OPM)) ;\
   244  	OS=$(shell go env GOOS) && ARCH=$(shell go env GOARCH) && \
   245  	curl -sSLo $(OPM) https://github.com/operator-framework/operator-registry/releases/download/v1.23.0/$${OS}-$${ARCH}-opm ;\
   246  	chmod +x $(OPM) ;\
   247  	}
   248  else
   249  OPM = $(shell which opm)
   250  endif
   251  endif
   252  
   253  # 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).
   254  # These images MUST exist in a registry and be pull-able.
   255  BUNDLE_IMGS ?= $(BUNDLE_IMG)
   256  
   257  # The image tag given to the resulting catalog image (e.g. make catalog-build CATALOG_IMG=example.com/operator-catalog:v0.2.0).
   258  CATALOG_IMG ?= $(IMAGE_TAG_BASE)-catalog:v$(VERSION)
   259  
   260  # Set CATALOG_BASE_IMG to an existing catalog image tag to add $BUNDLE_IMGS to that image.
   261  ifneq ($(origin CATALOG_BASE_IMG), undefined)
   262  FROM_INDEX_OPT := --from-index $(CATALOG_BASE_IMG)
   263  endif
   264  
   265  # Build a catalog image by adding bundle images to an empty catalog using the operator package manager tool, 'opm'.
   266  # This recipe invokes 'opm' in 'semver' bundle add mode. For more information on add modes, see:
   267  # https://github.com/operator-framework/community-operators/blob/7f1438c/docs/packaging-operator.md#updating-your-existing-operator
   268  .PHONY: catalog-build
   269  catalog-build: opm ## Build a catalog image.
   270  	$(OPM) index add --container-tool docker --mode semver --tag $(CATALOG_IMG) --bundles $(BUNDLE_IMGS) $(FROM_INDEX_OPT)
   271  
   272  # Push the catalog image.
   273  .PHONY: catalog-push
   274  catalog-push: ## Push a catalog image.
   275  	$(MAKE) docker-push IMG=$(CATALOG_IMG)