github.com/verrazzano/verrazzano@v1.7.0/application-operator/Makefile (about)

     1  # Copyright (C) 2020, 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-application-operator
    12  REPO_NAME:=verrazzano-application-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-application-operator/crds
    59  MC_CRD_PATH=../platform-operator/helm_config/charts/verrazzano-cluster-agent/crds
    60  OAM_PATH=../platform-operator/thirdparty/charts/oam-kubernetes-runtime/crds
    61  
    62  .PHONY: build
    63  build: go-fmt go-vet
    64  	go build -o bin/manager main.go
    65  
    66  # Disable the application operator in the local Kubernetes cluster
    67  # Deletes all of the webhook configuration for the application operator
    68  # Scales the in-cluster application operator deployment to replicas 0
    69  .PHONY: disable-operator
    70  disable-operator:
    71  	kubectl delete validatingwebhookconfigurations verrazzano-application-ingresstrait-validator || true
    72  	kubectl delete mutatingwebhookconfigurations verrazzano-application-istio-defaulter || true
    73  	kubectl delete mutatingwebhookconfigurations verrazzano-application-appconfig-defaulter || true
    74  	kubectl delete validatingwebhookconfigurations verrazzano-application-verrazzanoproject || true
    75  	kubectl delete mutatingwebhookconfigurations verrazzano-application-scrape-generator || true
    76  	kubectl scale deployment verrazzano-application-operator --replicas=0 -n verrazzano-system
    77  
    78  # Run against the configured Kubernetes cluster in ~/.kube/config
    79  .PHONY: run
    80  run:
    81  	# To enable webhooks: $(GO) run main.go --kubeconfig=${KUBECONFIG} --enable-webhooks=true --metrics-addr=localhost:0 --cert-dir=build/webhook-certs
    82  	$(GO) run main.go --kubeconfig=${KUBECONFIG} --enable-webhooks=false --metrics-addr=localhost:0
    83  
    84  .PHONY: install-oam-crds
    85  install-oam-crds:
    86  	kubectl apply -f ${OAM_PATH}
    87  
    88  .PHONY: install-verrazzano-crds
    89  install-verrazzano-crds:
    90  	kubectl apply -f ${CRD_PATH}
    91  	kubectl apply -f ${MC_CRD_PATH}
    92  
    93  # Install CRDs into a cluster
    94  .PHONY: install-crds
    95  install-crds: manifests install-oam-crds install-verrazzano-crds
    96  
    97  # Uninstall CRDs from a cluster
    98  .PHONY: uninstall-crds
    99  uninstall-crds: manifests
   100  	kubectl delete -f ${CRD_PATH}
   101  
   102  # Generate mocks
   103  .PHONY: mock-gen
   104  mock-gen:
   105  	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
   106  	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
   107  
   108  .PHONY: manifests
   109  manifests: application-manifests
   110  #
   111  # Go build related tasks
   112  #
   113  .PHONY: go-build
   114  go-build:
   115  	$(GO) build \
   116  		-ldflags "${GO_LDFLAGS}" \
   117  		-o out/$(shell uname)_$(shell uname -m)/verrazzano-application-operator \
   118  		main.go
   119  
   120  .PHONY: go-build-linux
   121  go-build-linux:
   122  	GOOS=linux GOARCH=amd64 $(GO) build \
   123  		-ldflags "-s -w ${GO_LDFLAGS}" \
   124  		-o out/linux_amd64/verrazzano-application-operator \
   125  		main.go
   126  
   127  .PHONY: go-build-linux-debug
   128  go-build-linux-debug:
   129  	GOOS=linux GOARCH=amd64 $(GO) build \
   130  		-ldflags "${GO_LDFLAGS}" \
   131  		-o out/linux_amd64/verrazzano-application-operator \
   132  		main.go
   133  
   134  .PHONY: go-install
   135  go-install:
   136  	$(GO) install
   137  
   138  #
   139  # Docker-related tasks
   140  #
   141  .PHONY: docker-clean
   142  docker-clean:
   143  	rm -rf ${DIST_DIR}
   144  
   145  .PHONY: docker-build
   146  docker-build: go-build-linux docker-build-common
   147  
   148  .PHONY: docker-build-debug
   149  docker-build-debug: go-build-linux-debug docker-build-common
   150  
   151  .PHONY: docker-build-common
   152  docker-build-common:
   153  	# the TPL file needs to be copied into this dir so it is in the docker build context
   154  	cp ../THIRD_PARTY_LICENSES.txt .
   155  	docker build --pull \
   156  		--build-arg BASE_IMAGE="${VZ_BASE_IMAGE}" \
   157  		-t ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} .
   158  
   159  .PHONY: docker-push
   160  docker-push: docker-build docker-push-common
   161  
   162  .PHONY: docker-push-debug
   163  docker-push-debug: docker-build-debug docker-push-common
   164  
   165  .PHONY: docker-push-common
   166  docker-push-common:
   167  	docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}
   168  	$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG})
   169  
   170  ifeq ($(CREATE_LATEST_TAG), "1")
   171  	docker tag ${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_TAG} ${DOCKER_IMAGE_FULLNAME}:latest;
   172  	$(call retry_docker_push,${DOCKER_IMAGE_FULLNAME}:latest);
   173  endif
   174  
   175  #
   176  # Test-related tasks
   177  #
   178  .PHONY: unit-test
   179  unit-test: go-install
   180  	$(GO) test -v ./apis/... ./controllers/... ./internal/... ./mcagent/...
   181  
   182  #
   183  # Kubernetes-related tasks
   184  #
   185  .PHONY: push-tag
   186  push-tag:
   187  	PUBLISH_TAG="${DOCKER_IMAGE_TAG}"; \
   188  	echo "Tagging and pushing image ${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
   189  	docker pull "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}"; \
   190  	docker tag "${DOCKER_IMAGE_FULLNAME}:${DOCKER_IMAGE_TAG}" "${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG"; \
   191  	$(call retry_docker_push,"${DOCKER_IMAGE_FULLNAME}:$$PUBLISH_TAG")