-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
158 lines (120 loc) · 5.26 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
.PHONY: all build clean compile help integration lint push test setup
.PHONY: dev.cluster.apply dev.cluster.delete
.PHONY: operator.apply operator.delete
.PHONY: dev.policy.apply dev.policy.delete
.PHONY: dev.scale.down dev.scale.start dev.scale.totals dev.scale.up dev.scale.where
.PHONY: dev.start.iex dev.start.in-cluster
.PHONY: pools.roll.od-n1-1 pools.roll.pvm-n1-2 pools.roll.pvm-n1-2
.PHONY: pools.sourcepool.enable pools.sourcepool.disable
IMAGE=quay.io/coryodaniel/ballast
help: ## Show this help
help:
@grep -E '^[a-zA-Z0-9._%-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
guard-%: # Creates an environment variable requirement by setting a prereq of guard-YOUR_ENV_VAR
@ if [ -z '${${*}}' ]; then \
echo "Environment variable $* not set"; \
exit 1;\
fi
lazy:
lazy: ## Find places where I've been lazy
grep -R --include="*.ex" -E ":ok[^=].* = " ./lib | grep -v '\->'
all: ## Lints, tests, compiles, and pushes "latest" docker tag.
all: lint test compile build push
clean: ## Clean builds, dependencies, coverage reports, and docs
rm -rf _build
rm -rf deps
rm -rf cover
rm -rf doc
setup: ## Setup
test: ## Run unit tests with coverage
mix test --exclude external:true --cover
integration: ## Run integration tests with coverage.
mix test --cover
lint: ## run format, credo, and dialyzer
mix lint
compile: ## Compile ballast
mix deps.get
mix compile
build: ## Build docker image
build: guard-IMAGE compile
docker build -t ${IMAGE} .
push: ## Release 'latest' docker image
push: guard-IMAGE
docker push ${IMAGE}:latest
.PHONY: debug
debug: guard-IMAGE compile build
debug: ## Builds a debug image
docker tag ${IMAGE} ${IMAGE}:debug
docker push ${IMAGE}:debug
shell: guard-IMAGE
docker run -it --entrypoint "/bin/sh" quay.io/coryodaniel/ballast:latest
tag: guard-DOCKER_LABEL
tag: ## Tag a release
docker tag ${IMAGE}:latest ${IMAGE}:${DOCKER_LABEL}
docker push ${IMAGE}:${DOCKER_LABEL}
dev.cluster.apply: ## Create / Update development cluster
dev.cluster.apply:
cd terraform && terraform init && \
terraform apply -var-file=terraform.tfvars
dev.cluster.delete: ## Delete development cluster
cd terraform && terraform destroy -var-file=terraform.tfvars
operator.apply: ## Apply kustomization base in kubectl current context using the latest docker image
-@kubectl delete -k ./manifests/base/
kubectl apply -k ./manifests/base/
operator.delete: ## Delete the operator in kubectl current context
kubectl delete -k ./manifests/base/
dev.policy.apply: ## Create / Update example PoolPolicy
dev.policy.apply:
-@kubectl delete -f ./terraform/ballast-poolpolicy.yaml
kubectl apply -f ./terraform/ballast-poolpolicy.yaml
dev.policy.delete: ## Delete example PoolPolicy
dev.policy.delete:
kubectl delete -f ./terraform/ballast-poolpolicy.yaml
dev.scale.start: ## Start an nginx deployment
kubectl apply -f ./test-scale-up.yaml
dev.scale.50: ## Scale nginx to 50 replicas
REPLICAS=50 $(MAKE) dev.scale.up
dev.scale.500: ## Scale nginx to 500 replicas
REPLICAS=500 $(MAKE) dev.scale.up
dev.scale.1000: ## Scale nginx to 1000 replicas
REPLICAS=1000 $(MAKE) dev.scale.up
dev.scale.up: ## Scale nginx deployment to a lot
dev.scale.up: guard-REPLICAS
echo "Scaling to ${REPLICAS} replicas"
kubectl scale --replicas=${REPLICAS} -f ./test-scale-up.yaml
dev.scale.down: ## Destroy nginx deployment
kubectl delete -f ./test-scale-up.yaml
dev.scale.where: ## Show which nodes scaled nginx test is on
kubectl get pods -o wide --sort-by="{.spec.nodeName}" --chunk-size=0
dev.scale.totals: ## Show count of pods on node pools
$(MAKE) dev.scale.where | grep -Fo -e other -e od-n1-1 -e pvm-n1-1 -e pvm-n1-2 | uniq -c
dev.start.iex: ## Deploys CRD and RBAC to kubectl current context, but runs ballast in iex
- rm manifest.yaml
mix bonny.gen.manifest
kubectl apply -f ./manifest.yaml
iex --dot-iex .iex.exs -S mix
dev.start.in-cluster: ## Deploys "latest" docker image into kubectl current context w/ a newly generated manifest.yaml
- rm manifest.yaml
mix bonny.gen.manifest --image ${IMAGE}
kubectl apply -f ./manifest.yaml
dev.svc-metrics.forward: ## Forward the remote k8s ballast-metrics service to localhost
kubectl port-forward service/ballast-metrics 9323:9323
## Managed Pools
SOURCE_POOL=$(shell kubectl get nodes | grep od-n | awk '{print $$1}')
pools.sourcepool.disable: ## Disable the source pool
for node in ${SOURCE_POOL} ; do (kubectl drain $$node --force --ignore-daemonsets &); done
pools.sourcepool.enable: ## Enabled the source pool
for node in ${SOURCE_POOL} ; do (kubectl uncordon $$node &); done
pools.nodes.current: ## Show number of nodes in pool
kubectl get nodes | grep -Fo -e other -e od-n1-1 -e pvm-n1-1 -e pvm-n1-2 | uniq -c
pools.roll.od-n1-1: ## Rolling replace the od-n1-1 managed node pool
pools.roll.od-n1-1: _roll_pool.od-n1-1
pools.roll.pvm-n1-1: ## Rolling replace the pvm-n1-1 managed node pool
pools.roll.pvm-n1-1: _roll_pool.pvm-n1-1
pools.roll.pvm-n1-2: ## Rolling replace the pvm-n1-2 managed node pool
pools.roll.pvm-n1-2: _roll_pool.pvm-n1-2
_roll_pool.%:
gcloud compute instance-groups managed list |\
grep gke-ballast-ballast-$* |\
awk '{print $$1, $$2}' |\
xargs -n 2 bash -c 'gcloud compute instance-groups managed rolling-action replace $$0 --zone $$1 --max-unavailable 100 --max-surge 1'