-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
80 lines (68 loc) · 3.08 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
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.29
IMG ?= achilles-token-controller:latest
# go-get-tool will 'go get' any package $2 and install it to $1.
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(LOCALBIN) go install -modfile=tools/go.mod $(2) ;\
}
endef
.PHONY: lint
lint: gosimports
cd tools && go mod tidy
go mod tidy
go fmt ./...
go list ./... | xargs go vet
$(GOSIMPORTS) -local github.com/reddit/achilles-sudo-controller -l -w .
# Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
.PHONY: generate
generate: controller-gen kustomize
$(CONTROLLER_GEN) object rbac:roleName=achilles-token-controller-role crd webhook paths="./..." \
output:crd:artifacts:config=manifests/crd/bases \
output:webhook:artifacts:config=manifests/webhook/ \
output:rbac:artifacts:config=manifests/base/rbac
# generate root kustomization.yaml for crds
cd manifests/crd/bases && rm -f kustomization.yaml && $(KUSTOMIZE) create --autodetect --recursive
# add all rbac resources to kustomize
cd manifests/base/rbac && rm -f kustomization.yaml && $(KUSTOMIZE) create --autodetect
# generate complete achilles-global-config-controller manifest
cd manifests/base && $(KUSTOMIZE) build > manager.yaml
.PHONY: test
test: generate lint envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./...
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker
docker:
docker build -t ${IMG} .
##@ Build Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
GOSIMPORTS ?= $(LOCALBIN)/gosimports
## Tool Versions
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
$(KUSTOMIZE): $(LOCALBIN)
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5)
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary. If wrong version is installed, it will be overwritten.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen)
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest)
.PHONY: gosimports
gosimports: $(GOSIMPORTS)
$(GOSIMPORTS): $(LOCALBIN)
$(call go-get-tool,$(GOSIMPORTS),github.com/rinchsan/gosimports/cmd/gosimports)