-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
150 lines (113 loc) · 4.65 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
##@ Development
.PHONY: generate
generate: generate_manifests generate_code generate_wasm
.PHONY: generate_manifests
generate_manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=dawg-controller-role crd paths="./..." output:crd:artifacts:config=k8s/crd output:rbac:artifacts:config=k8s/dawg
.PHONY: generate_code
generate_code: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
.PHONY: generate_wasm
generate_wasm:
go generate -v ./...
.PHONY: clean_generate_wasm
clean_generate_wasm:
cd ./generator/testdata/runtime && rm -f *.wasm
cd ./internal/controller/testdata && rm -f *.wasm
.PHONY: test
test: generate_wasm fast_test
.PHONY: fast_test
fast_test:
go test -count=1 -v -timeout=5m -race -cover -run=$(T) ./...
##@ Generators
TINYGO=tinygo
GENERATOR_DIST=$(PWD)/dist/generators
generators: clean_generators $(GENERATOR_DIST) build_generators
$(GENERATOR_DIST):
mkdir -p $(GENERATOR_DIST)
.PHONY: build_generators
build_generators: example/*
for dir in $^; do \
cd $${dir} && $(TINYGO) build -o $(GENERATOR_DIST)/$$(basename "$${dir}") -scheduler=none --no-debug -target wasi ./generator.go ; \
done
.PHONY: push_generators
push_generators:
for bin in $(wildcard dist/generators/*); do \
go run ./cmd/push -generator registry://dawg-dev.localhost:5000/dashboards/$$(basename "$${bin}"):v0.0.1 $${bin} ; \
done
.PHONY: clean_generators
clean_generators:
rm -rf $(GENERATOR_DIST)
##@ Dev environment
K3S_VERSION?=v1.27.3-k3s1
DEV_CLUSTER_PORT?=3000
DEV_CLUSTER_NAME?=dawg-dev
VERSION?=unknown
.PHONY: dev
dev: preflight_dev generate create_cluster install deploy_dependencies deploy build_generators push_generators deploy_example
.PHONY: create_cluster
create_cluster: ## run a local k3d cluster
k3d cluster create \
--image="rancher/k3s:$(K3S_VERSION)" \
-p "$(DEV_CLUSTER_PORT):80@loadbalancer" \
--registry-create=$(DEV_CLUSTER_NAME).localhost:0.0.0.0:5000 \
$(DEV_CLUSTER_NAME)
.PHONY: delete_cluster
delete_cluster: ## tears down the k3d dev cluster
k3d cluster delete $(DEV_CLUSTER_NAME)
.PHONY: install
install: generate_manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
kubectl apply -f k8s/crd
.PHONY: uninstall
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config
kubectl delete -f k8s/crd
.PHONY: deploy
deploy: generate_code generate_manifests
kubectl kustomize k8s/dawg | VERSION=$(VERSION) KO_DOCKER_REPO=dawg-dev.localhost:5000 ko apply -f -
.PHONY: undeploy
undeploy: generate_manifests
kubectl kustomize k8s/dawg | kubectl delete -f -
.PHONY: restart
restart:
kubectl -n dawg rollout restart deployment dawg-controller
.PHONY: deploy_dependencies
deploy_dependencies: deploy_grafana deploy_prometheus deploy_ksb ## deploy all the dependencies
.PHONY: deploy_grafana
deploy_grafana:
kubectl apply -k k8s/grafana
.PHONY: deploy_prometheus
deploy_prometheus:
kubectl apply -k k8s/prometheus
.PHONY: deploy_ksb
deploy_ksb:
kubectl apply -k k8s/kube-state-metrics
.PHONY: deploy_example
deploy_example:
kubectl apply -k k8s/example
.PHONY: undeploy_example
undeploy_example:
kubectl kustomize k8s/example | kubectl delete -f -
.PHONY: set_grafana_token
set_grafana_token:
git update-index --assume-unchanged k8s/dawg/.grafanatoken
echo $(GRAFANA_TOKEN) > k8s/dawg/.grafanatoken
.PHONY: preflight_dev
preflight_dev: ## Checks that all the necesary binaries are present
@k3d version >/dev/null 2>&1 || (echo "ERROR: k3d is required."; exit 1)
@kubectl version --client >/dev/null 2>&1 || (echo "ERROR: kubectl is required."; exit 1)
@ko version >/dev/null 2>&1 || (echo "ERROR: ko is required."; exit 1)
@tinygo version >/dev/null 2>&1 || (echo "ERROR: tinygo is required."; exit 1)
@grep -Fq "$(DEV_CLUSTER_NAME).localhost" /etc/hosts || (echo "ERROR: please add the following line '127.0.0.1 $(DEV_CLUSTER_NAME).localhost' to your /etc/hosts file"; exit 1)
## Tool Binaries
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
KUBECTL ?= kubectl
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CONTROLLER_TOOLS_VERSION ?= v0.13.0
.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)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)