forked from k8snetworkplumbingwg/whereabouts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
208 lines (161 loc) · 7.54 KB
/
Makefile
File metadata and controls
208 lines (161 loc) · 7.54 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# ---------------------------------------------------------------
# Variables
# ---------------------------------------------------------------
CURPATH=$(PWD)
BIN_DIR=$(CURPATH)/bin
IMAGE_NAME ?= whereabouts
IMAGE_REGISTRY ?= ghcr.io/telekom
IMAGE_PULL_POLICY ?= Always
IMAGE_TAG ?= latest
COMPUTE_NODES ?= 2
OCI_BIN ?= docker
GO ?= go
# Tool versions
CONTROLLER_GEN_VERSION ?= v0.20.0
STATICCHECK_VERSION ?= v0.6.0
KUSTOMIZE_VERSION ?= v5.6.0
GOLANGCI_LINT_VERSION ?= v2.1.5
# Resolved tool paths
CONTROLLER_GEN := $(BIN_DIR)/controller-gen
STATICCHECK := $(BIN_DIR)/staticcheck
KUSTOMIZE := $(BIN_DIR)/kustomize
GOLANGCI_LINT := $(BIN_DIR)/golangci-lint
# ---------------------------------------------------------------
# Version information
# ---------------------------------------------------------------
GIT_SHA := $(shell git rev-parse --short HEAD 2>/dev/null)
GIT_TREE_STATE := $(shell test -n "$$(git status --porcelain --untracked-files=no 2>/dev/null)" && echo dirty || echo clean)
GIT_TAG := $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
GIT_TAG_LAST := $(shell git describe --tags --abbrev=0 2>/dev/null)
VERSION ?= $(GIT_TAG_LAST)
RELEASE_STATUS := $(if $(strip $(VERSION)$(GIT_TAG)),released,unreleased)
VERSION_PKG := github.com/telekom/whereabouts/pkg/version
LDFLAGS := -X $(VERSION_PKG).Version=$(VERSION) \
-X $(VERSION_PKG).GitSHA=$(GIT_SHA) \
-X $(VERSION_PKG).GitTreeState=$(GIT_TREE_STATE) \
-X $(VERSION_PKG).ReleaseStatus=$(RELEASE_STATUS)
# ---------------------------------------------------------------
# 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%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: manifests
manifests: $(CONTROLLER_GEN) ## Generate CRDs, RBAC, and webhook manifests (config/).
$(CONTROLLER_GEN) rbac:roleName=whereabouts-operator \
crd:crdVersions=v1 \
webhook \
paths="./api/...;./internal/..." \
output:crd:artifacts:config=config/crd/bases \
output:rbac:artifacts:config=config/rbac \
output:webhook:artifacts:config=config/webhook
cp config/crd/bases/whereabouts.cni.cncf.io_*.yaml deployment/whereabouts-chart/crds/
.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate deepcopy and clientsets/informers/listers.
$(CONTROLLER_GEN) object paths="./api/whereabouts.cni.cncf.io/..."
hack/update-codegen.sh
rm -rf github.com
.PHONY: generate-api
generate-api: manifests generate ## Generate all API artifacts (CRDs + deepcopy + clientsets).
.PHONY: verify-codegen
verify-codegen: ## Verify generated code is up to date.
hack/verify-codegen.sh
.PHONY: fmt
fmt: ## Run go fmt against code.
$(GO) fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
$(GO) vet ./cmd/... ./pkg/... ./internal/... ./api/whereabouts.cni.cncf.io/...
##@ Testing
.PHONY: test
test: build manifests generate vet lint-staticcheck ## Run unit tests (includes build, vet, staticcheck).
$(GO) test -v -race -covermode=atomic -coverprofile=coverage.out \
$$($(GO) list ./... | grep -v e2e | tr "\n" " ")
.PHONY: test-skip-static
test-skip-static: build vet ## Run tests without staticcheck (faster iteration).
$(GO) test -v -race -covermode=atomic -coverprofile=coverage.out \
$$($(GO) list ./... | grep -v e2e | tr "\n" " ")
##@ Linting
.PHONY: lint-staticcheck
lint-staticcheck: $(STATICCHECK) ## Run staticcheck.
$(STATICCHECK) ./...
.PHONY: lint
lint: $(GOLANGCI_LINT) ## Run golangci-lint.
$(GOLANGCI_LINT) run --timeout=5m ./...
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Run golangci-lint with auto-fix.
$(GOLANGCI_LINT) run --timeout=5m --fix ./...
##@ Build
.PHONY: build
build: ## Build CNI plugin, operator, and install-cni binaries.
CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/whereabouts ./cmd/whereabouts/
CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/whereabouts-operator ./cmd/operator/
CGO_ENABLED=0 $(GO) build -trimpath -ldflags "$(LDFLAGS)" -o bin/install-cni ./cmd/install-cni/
.PHONY: run
run: ## Run the operator controller locally against the configured cluster.
$(GO) run ./cmd/operator/ controller
.PHONY: docker-build
docker-build: ## Build container image.
$(OCI_BIN) build --build-arg VERSION=$(IMAGE_TAG) --build-arg GIT_SHA=$(GIT_SHA) -t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile .
.PHONY: docker-push
docker-push: ## Push container image.
$(OCI_BIN) push $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG)
.PHONY: docker-buildx
docker-buildx: ## Build and push container image for cross-platform support.
$(OCI_BIN) buildx build --platform linux/amd64,linux/arm64 --push --build-arg VERSION=$(IMAGE_TAG) --build-arg GIT_SHA=$(GIT_SHA) -t $(IMAGE_REGISTRY)/$(IMAGE_NAME):$(IMAGE_TAG) -f Dockerfile .
##@ Deployment
.PHONY: install
install: manifests $(KUSTOMIZE) ## Install CRDs into the cluster.
$(KUSTOMIZE) build config/crd | kubectl apply -f -
.PHONY: uninstall
uninstall: manifests $(KUSTOMIZE) ## Uninstall CRDs from the cluster.
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found -f -
.PHONY: deploy
deploy: manifests $(KUSTOMIZE) ## Deploy controller to the cluster.
$(KUSTOMIZE) build config/default | kubectl apply -f -
.PHONY: undeploy
undeploy: $(KUSTOMIZE) ## Undeploy controller from the cluster.
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found -f -
.PHONY: kind
kind: ## Create a KinD cluster with whereabouts installed (kustomize).
hack/e2e-setup-kind-cluster.sh -n $(COMPUTE_NODES)
.PHONY: kind-helm
kind-helm: ## Create a KinD cluster with whereabouts installed (Helm).
hack/e2e-setup-kind-cluster-helm.sh -n $(COMPUTE_NODES)
##@ Dependencies
.PHONY: update-deps
update-deps: ## Update Go dependencies.
$(GO) mod tidy
$(GO) mod vendor
$(GO) mod verify
# ---------------------------------------------------------------
# Tool installation
# ---------------------------------------------------------------
$(BIN_DIR):
@mkdir -p $(BIN_DIR)
$(CONTROLLER_GEN): | $(BIN_DIR)
GOBIN=$(BIN_DIR) $(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
$(STATICCHECK): | $(BIN_DIR)
GOBIN=$(BIN_DIR) $(GO) install honnef.co/go/tools/cmd/staticcheck@$(STATICCHECK_VERSION)
$(KUSTOMIZE): | $(BIN_DIR)
GOBIN=$(BIN_DIR) $(GO) install sigs.k8s.io/kustomize/kustomize/v5@$(KUSTOMIZE_VERSION)
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Install kustomize binary.
$(GOLANGCI_LINT): | $(BIN_DIR)
GOBIN=$(BIN_DIR) $(GO) install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
YQ=$(BIN_DIR)/yq
YQ_VERSION=v4.44.1
$(YQ): | $(BIN_DIR); $(info installing yq)
@OS=$$(uname -s | tr '[:upper:]' '[:lower:]') && ARCH=$$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/' | sed 's/arm64/arm64/') && \
curl -fsSL -o $(YQ) https://github.com/mikefarah/yq/releases/download/$(YQ_VERSION)/yq_$${OS}_$${ARCH} && chmod +x $(YQ)
# ---------------------------------------------------------------
# Release
# ---------------------------------------------------------------
##@ Release
.PHONY: chart-prepare-release
chart-prepare-release: | $(YQ) ; ## Prepare chart for release.
@GITHUB_TAG=$(GITHUB_TAG) GITHUB_TOKEN=$(GITHUB_TOKEN) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-update.sh
.PHONY: chart-push-release
chart-push-release: ## Push release chart.
@GITHUB_TAG=$(GITHUB_TAG) GITHUB_TOKEN=$(GITHUB_TOKEN) GITHUB_REPO_OWNER=$(GITHUB_REPO_OWNER) hack/release/chart-push.sh