forked from spectrocloud/cluster-api-provider-maas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
176 lines (136 loc) · 5.45 KB
/
Makefile
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
ROOT_DIR_RELATIVE := .
include $(ROOT_DIR_RELATIVE)/common.mk
VERSION ?= $(shell cat clusterctl-settings.json | jq .config.nextVersion -r)
TOOLS_DIR := hack/tools
TOOLS_DIR_DEPS := $(TOOLS_DIR)/go.sum $(TOOLS_DIR)/go.mod $(TOOLS_DIR)/Makefile
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
MANIFEST_DIR=_build/manifests
BUILD_DIR :=_build
RELEASE_DIR := _build/release
DEV_DIR := _build/dev
REPO_ROOT := $(shell git rev-parse --show-toplevel)
# Image URL to use all building/pushing image targets
IMAGE_NAME := cluster-api-provider-maas-controller
IMG_URL ?= gcr.io/spectro-dev-public/release/cluster-api
IMG_TAG ?= spectro-v0.4.0-v1beta1-20230512.1055
IMG ?= ${IMG_URL}/${IMAGE_NAME}:${IMG_TAG}
# Set --output-base for conversion-gen if we are not within GOPATH
ifneq ($(abspath $(REPO_ROOT)),$(shell go env GOPATH)/src/github.com/spectrocloud/cluster-api-provider-maas)
GEN_OUTPUT_BASE := --output-base=$(REPO_ROOT)
else
export GOPATH := $(shell go env GOPATH)
endif
# Release images
# Release docker variables
RELEASE_REGISTRY := gcr.io/spectro-images-public/release/cluster-api-provider-maas
RELEASE_CONTROLLER_IMG := $(RELEASE_REGISTRY)/$(IMAGE_NAME)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
MOCKGEN := $(TOOLS_BIN_DIR)/mockgen
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen
CONVERSION_GEN := $(TOOLS_BIN_DIR)/conversion-gen
DEFAULTER_GEN := $(TOOLS_BIN_DIR)/defaulter-gen
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
all: manager
# Run tests
test: generate fmt vet manifests ## Run unit tests
# TODO bring back
go test ./... -coverprofile cover.out
# Build manager binary
manager: generate fmt vet ## Build manager binary
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
install: manifests ## Install CRDs into a cluster
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests ## Uninstall CRDs from a cluster
kustomize build config/crd | kubectl delete -f -
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
deploy: manifests ## Deploy controller in the configured Kubernetes cluster
cd config/manager && kustomize edit set image controller=${IMG}
kustomize build config/default | kubectl apply -f -
$(MANIFEST_DIR):
mkdir -p $(MANIFEST_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(OVERRIDES_DIR):
@mkdir -p $(OVERRIDES_DIR)
.PHONY: dev-version-check
dev-version-check:
ifndef VERSION
$(error VERSION must be set)
endif
.PHONY: release-version-check
release-version-check:
ifeq ($(VERSION), 0.0.0)
$(error VERSION must be >0.0.0 for release)
endif
.PHONY: release-manifests
release-manifests: test
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(RELEASE_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)
cp metadata.yaml $(RELEASE_DIR)/metadata.yaml
$(MAKE) templates OUTPUT_DIR=$(RELEASE_DIR)
.PHONY: release-overrides
release-overrides:
$(MAKE) manifests STAGE=release MANIFEST_DIR=$(OVERRIDES_DIR) PULL_POLICY=IfNotPresent IMAGE=$(RELEASE_CONTROLLER_IMG):$(VERSION)
.PHONY: dev-manifests
dev-manifests:
$(MAKE) manifests STAGE=dev MANIFEST_DIR=$(DEV_DIR) PULL_POLICY=Always IMAGE=$(IMG)
cp metadata.yaml $(DEV_DIR)/metadata.yaml
$(MAKE) templates OUTPUT_DIR=$(DEV_DIR)
# Generate manifests e.g. CRD, RBAC etc.
manifests: $(CONTROLLER_GEN) $(MANIFEST_DIR) $(KUSTOMIZE) $(BUILD_DIR) ## Generate manifests e.g. CRD, RBAC etc.
rm -rf $(BUILD_DIR)/config
cp -R config $(BUILD_DIR)/config
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' $(BUILD_DIR)/config/default/manager_pull_policy.yaml
sed -i'' -e 's@image: .*@image: '"$(IMAGE)"'@' $(BUILD_DIR)/config/default/manager_image_patch.yaml
"$(KUSTOMIZE)" build $(BUILD_DIR)/config/default > $(MANIFEST_DIR)/infrastructure-components.yaml
# Run go fmt against code
fmt: ## Run go fmt against code
go fmt ./...
# Run go vet against code
vet: ## Run go vet against code
go vet ./...
# Generate code
generate: $(CONTROLLER_GEN) $(CONVERSION_GEN)
$(MAKE) generate-go
$(MAKE) generate-manifests
generate-go:
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONVERSION_GEN) \
--input-dirs=./api/v1beta1 \
--extra-peer-dirs=github.com/spectrocloud/cluster-api-provider-maas/api/v1beta1 \
--build-tag=ignore_autogenerated_core_v1alpha3 \
--output-file-base=zz_generated.conversion $(GEN_OUTPUT_BASE) \
--go-header-file=./hack/boilerplate.go.txt
generate-manifests: ## Generate manifests
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Build the docker image
docker-build: #test
docker build . -t ${IMG}
# Push the docker image
docker-push: ## Push the docker image to gcr
docker push ${IMG}
docker-rmi: ## Remove the docker image locally
docker rmi ${IMG}
mock: $(MOCKGEN)
go generate ./...
clean-release:
rm -rf $(RELEASE_DIR)
release: release-manifests
$(MAKE) docker-build IMG=$(RELEASE_CONTROLLER_IMG):$(VERSION)
$(MAKE) docker-push IMG=$(RELEASE_CONTROLLER_IMG):$(VERSION)
.PHONY: templates
templates: ## Generate release templates
cp templates/cluster-template*.yaml $(OUTPUT_DIR)/
version: ## Prints version of current make
@echo $(VERSION)