github.com/verrazzano/verrazzano@v1.7.0/cluster-operator/Makefile (about) 1 # Copyright (C) 2022, 2023, Oracle and/or its affiliates. 2 # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 include ../make/quality.mk 5 include ../make/generate.mk 6 include ../make/retry.mk 7 8 SCRIPT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../build 9 TOOLS_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/../tools 10 11 NAME:=verrazzano-cluster-operator 12 REPO_NAME:=verrazzano-cluster-operator 13 14 CONTROLLER_GEN_VERSION ?= $(shell go list -m -f '{{.Version}}' sigs.k8s.io/controller-tools) 15 CREATE_LATEST_TAG=0 16 17 CRD_OPTIONS ?= "crd:crdVersions=v1" 18 ifdef KUBECONFIG 19 KUBECONFIG ?= ${KUBECONFIG} 20 else 21 KUBECONFIG ?= ${HOME}/.kube/config 22 endif 23 24 ifndef DOCKER_IMAGE_FULLNAME 25 DOCKER_IMAGE_NAME ?= ${NAME}-dev 26 DOCKER_IMAGE_FULLNAME=${DOCKER_IMAGE_NAME} 27 ifeq ($(MAKECMDGOALS),$(filter $(MAKECMDGOALS),docker-push push-tag)) 28 ifndef DOCKER_REPO 29 $(error DOCKER_REPO must be defined as the name of the Docker repository where image will be pushed) 30 endif 31 ifndef DOCKER_NAMESPACE 32 $(error DOCKER_NAMESPACE must be defined as the name of the Docker namespace where image will be pushed) 33 endif 34 endif 35 ifdef DOCKER_NAMESPACE 36 DOCKER_IMAGE_FULLNAME := ${DOCKER_NAMESPACE}/${DOCKER_IMAGE_FULLNAME} 37 endif 38 ifdef DOCKER_REPO 39 DOCKER_IMAGE_FULLNAME := ${DOCKER_REPO}/${DOCKER_IMAGE_FULLNAME} 40 endif 41 endif 42 43 DOCKER_IMAGE_TAG ?= local-$(shell git rev-parse --short HEAD) 44 45 OPERATOR_VERSION = ${DOCKER_IMAGE_TAG} 46 ifdef RELEASE_VERSION 47 OPERATOR_VERSION = ${RELEASE_VERSION} 48 endif 49 ifndef RELEASE_BRANCH 50 RELEASE_BRANCH=$(shell git rev-parse --abbrev-ref HEAD) 51 endif 52 53 VZ_BASE_IMAGE ?= ghcr.io/verrazzano/verrazzano-base:v1.0.0-20230327155846-4653b27 54 55 DIST_DIR:=dist 56 GO ?= CGO_ENABLED=0 GO111MODULE=on GOPRIVATE=github.com/verrazzano go 57 GO_LDFLAGS ?= -extldflags -static -X main.buildVersion=${BUILDVERSION} -X main.buildDate=${BUILDDATE} 58 CRD_PATH=../platform-operator/helm_config/charts/verrazzano-cluster-operator/crds 59 60 .PHONY: build 61 build: go-fmt go-vet 62 go build -o bin/manager main.go 63 64 # Disable the cluster operator in the local Kubernetes cluster 65 # Scales the in-cluster cluster operator deployment to replicas 0 66 .PHONY: disable-operator 67 disable-operator: 68 kubectl scale deployment verrazzano-cluster-operator --replicas=0 -n verrazzano-system 69 70 # Run against the configured Kubernetes cluster in ~/.kube/config 71 .PHONY: run 72 run: 73 # To enable webhooks: $(GO) run main.go --kubeconfig=${KUBECONFIG} --enable-webhooks=true --metrics-addr=localhost:0 --cert-dir=build/webhook-certs 74 $(GO) run main.go --kubeconfig=${KUBECONFIG} --enable-webhooks=false --metrics-addr=localhost:0 75 76 # Install CRDs into a cluster 77 .PHONY: install-crds 78 install-crds: manifests 79 kubectl apply -f ${CRD_PATH} 80 81 # Uninstall CRDs from a cluster 82 .PHONY: uninstall-crds 83 uninstall-crds: manifests 84 kubectl delete -f ${CRD_PATH} 85 86 # Generate mocks 87 .PHONY: mock-gen 88 mock-gen: 89 mockgen --build_flags=--mod=mod -destination=mocks/controller_client_mock.go -package=mocks -copyright_file=hack/boilerplate.go.txt sigs.k8s.io/controller-runtime/pkg/client Client,StatusWriter 90 mockgen --build_flags=--mod=mod -destination=mocks/controller_manager_mock.go -package=mocks -copyright_file=hack/boilerplate.go.txt sigs.k8s.io/controller-runtime Manager 91 92 .PHONY: manifests 93 manifests: cluster-manifests 94 # 95 # Go build related tasks 96 # 97 .PHONY: go-build 98 go-build: 99 $(GO) build \ 100 -ldflags "${GO_LDFLAGS}" \ 101 -o out/$(shell uname)_$(shell uname -m)/verrazzano-cluster-operator \ 102 main.go 103 104 .PHONY: go-build-linux 105 go-build-linux: 106 GOOS=linux GOARCH=amd64 $(GO) build \ 107 -ldflags "-s -w ${GO_LDFLAGS}" \ 108 -o out/linux_amd64/verrazzano-cluster-operator \ 109 main.go 110 111 .PHONY: go-build-linux-debug 112 go-build-linux-debug: 113 GOOS=linux GOARCH=amd64 $(GO) build \ 114 -ldflags "${GO_LDFLAGS}" \ 115 -o out/linux_amd64/verrazzano-cluster-operator \ 116 main.go 117 118 .PHONY: go-install 119 go-install: 120 $(GO) install 121 122 # 123 # Docker-related tasks 124 # 125 .PHONY: docker-clean 126 docker-clean: 127 rm -rf ${DIST_DIR} 128 129 .PHONY: docker-build 130 docker-build: go-build-linux docker-build-common 131 132 .PHONY: docker-build-debug 133 docker-build-debug: go-build-linux-debug docker-build-common 134 135 .PHONY: docker-build-common 136 docker-build-common: 137 # the TPL file needs to be copied into this dir so it is in the docker build context 138 cp ../THIRD_PARTY_LICENSES.txt . 139 docker build --pull \ 140 --build-arg BASE_IMAGE="${VZ_BASE_IMAGE}" \ 141 -t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} . 142 143 .PHONY: docker-push 144 docker-push: docker-build docker-push-common 145 146 .PHONY: docker-push-debug 147 docker-push-debug: docker-build-debug docker-push-common 148 149 .PHONY: docker-push-common 150 docker-push-common: 151 docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG} 152 $(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}) 153 154 ifeq ($(CREATE_LATEST_TAG), "1") 155 docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:latest; 156 $(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:latest); 157 endif 158 159 # 160 # Test-related tasks 161 # 162 .PHONY: unit-test 163 unit-test: go-install 164 $(GO) test -v ./apis/... ./controllers/... ./internal/... 165 166 # 167 # Kubernetes-related tasks 168 # 169 .PHONY: push-tag 170 push-tag: 171 PUBLISH_TAG="${DOCKER_IMAGE_TAG}"; \ 172 echo "Tagging and pushing image ${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \ 173 docker pull "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}"; \ 174 docker tag "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}" "${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \ 175 $(call retry_docker_push,"${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG")