This repository was archived by the owner on Aug 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
158 lines (124 loc) · 5.68 KB
/
Makefile
File metadata and controls
158 lines (124 loc) · 5.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
include func.mk
PROJECT_NAME:=odh-project-controller
PACKAGE_NAME:=github.com/maistra/$(PROJECT_NAME)
# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.PHONY: all
all: tools lint test build
##@ General
.PHONY: help
help: ## Display this help.
@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)
##@ Development
EXTERNAL_CRDS=./config/crd/external
.PHONY: generate
generate: tools ## Generates required resources for the controller to work properly (see config/ folder)
$(LOCALBIN)/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
rm -rf $(EXTERNAL_CRDS)
$(call fetch-external-crds,github.com/openshift/api,route/v1,$(EXTERNAL_CRDS))
SRC_DIRS:=./controllers ./test
SRCS:=$(shell find ${SRC_DIRS} -name "*.go")
.PHONY: lint
lint: tools ## Concurrently runs a whole bunch of static analysis tools
$(call header,"Running a whole bunch of static analysis tools")
$(LOCALBIN)/golangci-lint run --fix --sort-results
.PHONY: test
test: generate
test: test-unit+kube-envtest ## Run all tests. You can also select a category by running e.g. make test-unit or make test-kube-envtest
ENVTEST_K8S_VERSION = 1.26 # refers to the version of kubebuilder assets to be downloaded by envtest binary.
test-%:
$(eval test-type:=$(subst +,||,$(subst test-,,$@)))
KUBEBUILDER_ASSETS="$(shell $(LOCALBIN)/setup-envtest use $(ENVTEST_K8S_VERSION) -p path)" \
$(LOCALBIN)/ginkgo -r --label-filter="$(test-type)" -vet=off \
-coverprofile cover.out --junit-report=ginkgo-test-results.xml ${args}
##@ Build
GOOS?=$(shell uname -s | tr '[:upper:]' '[:lower:]')
GOARCH?=$(shell uname -m | tr '[:upper:]' '[:lower:]' | sed 's/x86_64/amd64/')
GOBUILD:=GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0
# Version values
BUILD_TIME=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GITUNTRACKEDCHANGES:=$(shell git status --porcelain --untracked-files=no)
COMMIT:=$(shell git rev-parse --short HEAD)
ifneq ($(GITUNTRACKEDCHANGES),)
COMMIT:=$(COMMIT)-dirty
endif
VERSION?=$(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
GIT_TAG?=$(shell git describe --tags --abbrev=0 --exact-match > /dev/null 2>&1; echo $$?)
ifneq ($(GIT_TAG),0)
ifeq ($(origin VERSION),file)
VERSION:=$(VERSION)-next
endif
endif
LDFLAGS?=-w -X ${PACKAGE_NAME}/version.Version=${VERSION} -X ${PACKAGE_NAME}/version.Commit=${COMMIT} -X ${PACKAGE_NAME}/version.BuildTime=${BUILD_TIME}
.PHONY: deps
deps:
go mod download && go mod tidy
.PHONY: build
build: lint test go-build ## Build manager binary.
.PHONY: go-build
go-build:
${GOBUILD} go build -ldflags "${LDFLAGS}" -o bin/manager main.go
##@ Container images
# Prefer to use podman if not explicitly set
CONTAINER_ENGINE ?= docker
ifneq (, $(shell which podman))
CONTAINER_ENGINE = podman
endif
IMG ?= quay.io/maistra-dev/$(PROJECT_NAME)
# If the commit is not tagged, use "latest", otherwise use the tag name
ifeq ($(GIT_TAG), 0)
TAG ?= $(VERSION)
else
TAG ?= latest
endif
.PHONY: image-build
image-build: ## Build container image
${CONTAINER_ENGINE} build --build-arg LDFLAGS="$(LDFLAGS)" . -t ${IMG}:${TAG} ${DOCKER_ARGS}
.PHONY: image-push
image-push: ## Push container image
${CONTAINER_ENGINE} push ${IMG}:${TAG}
.PHONY: image
image: image-build image-push ## Build and push docker image with the manager.
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: deploy
deploy: generate ## Deploy controller to the K8s cluster specified in ~/.kube/config.
cd config/manager && kustomize edit set image controller=${IMG}:${TAG}
kubectl apply -k config/base
.PHONY: undeploy
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.
kubectl delete --ignore-not-found=$(ignore-not-found) -k config/base
##@ Build Dependencies
LOCALBIN ?= $(shell pwd)/bin
$(shell mkdir -p $(LOCALBIN))
.PHONY: tools
tools: $(LOCALBIN)/controller-gen $(LOCALBIN)/kustomize ## Installs required tools in local ./bin folder
tools: $(LOCALBIN)/setup-envtest $(LOCALBIN)/ginkgo
tools: $(LOCALBIN)/goimports $(LOCALBIN)/golangci-lint
KUSTOMIZE_VERSION ?= v5.0.1
$(LOCALBIN)/kustomize:
$(call header,"Installing $(notdir $@)")
wget -q -c https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(GOOS)_$(GOARCH).tar.gz -O /tmp/kustomize.tar.gz
tar xzvf /tmp/kustomize.tar.gz -C $(LOCALBIN)
chmod +x $(LOCALBIN)/kustomize
CONTROLLER_TOOLS_VERSION?=$(call go-mod-version,'controller-tools')
$(LOCALBIN)/controller-gen:
$(call header,"Installing $(notdir $@)")
$(call go-get-tool,controller-gen,sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION))
$(LOCALBIN)/setup-envtest:
$(call header,"Installing $(notdir $@)")
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
$(LOCALBIN)/ginkgo:
$(call header,"Installing $(notdir $@)")
GOBIN=$(LOCALBIN) go install -mod=readonly github.com/onsi/ginkgo/v2/ginkgo
$(LOCALBIN)/goimports:
$(call header,"Installing $(notdir $@)")
GOBIN=$(LOCALBIN) go install -mod=readonly golang.org/x/tools/cmd/goimports
LINT_VERSION=v1.55.2
$(LOCALBIN)/golangci-lint:
$(call header,"Installing $(notdir $@)")
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(LOCALBIN) $(LINT_VERSION)