-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
179 lines (154 loc) · 6.38 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
177
178
179
# MIT License
#
# Copyright (c) 2023 Matheus Pimenta
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
SHELL := /bin/bash
TEST_IMAGE := ghcr.io/matheuscscp/gke-metadata-server/test
.PHONY: dev
dev: tidy gen-ebpf dev-cluster build dev-test
.PHONY: clean
clean:
rm -rf *.json *.txt *.logs *.tgz
.PHONY: tidy
tidy:
go mod tidy
go fmt ./...
make gen
terraform fmt -recursive ./
terraform fmt -recursive ./.*/**/*.tf
./scripts/license.sh
git status
.PHONY: gen
gen: gen-timoni
.PHONY: gen-timoni
gen-timoni:
cd timoni/gke-metadata-server; cue get go k8s.io/api/core/v1
cd timoni/gke-metadata-server; cue get go k8s.io/api/apps/v1
cd timoni/gke-metadata-server; cue get go k8s.io/api/rbac/v1
.PHONY: gen-ebpf
gen-ebpf:
go generate ./internal/redirect
.PHONY: dev-cluster
dev-cluster:
kind delete cluster --name gke-metadata-server || true
make cluster TEST_ID=test PROVIDER_COMMAND=update
kubens kube-system
.PHONY: ci-cluster
ci-cluster:
echo "test-$$(openssl rand -hex 12)" | tee ci-test-id.txt
make cluster TEST_ID=$$(cat ci-test-id.txt) PROVIDER_COMMAND=create
.PHONY: dev-test
dev-test:
make test-unit
make test TEST_ID=test
.PHONY: ci-test
ci-test:
make test-unit
make test TEST_ID=$$(cat ci-test-id.txt)
.PHONY: cluster
cluster:
@if [ "${TEST_ID}" == "" ]; then echo "TEST_ID variable is required."; exit -1; fi
@if [ "${PROVIDER_COMMAND}" == "" ]; then echo "PROVIDER_COMMAND variable is required."; exit -1; fi
kind create cluster --name gke-metadata-server --config testdata/kind.yaml
make create-or-update-provider TEST_ID=${TEST_ID} PROVIDER_COMMAND=${PROVIDER_COMMAND}
make install-cilium
.PHONY: create-or-update-provider
create-or-update-provider:
@if [ "${TEST_ID}" == "" ]; then echo "TEST_ID variable is required."; exit -1; fi
@if [ "${PROVIDER_COMMAND}" == "" ]; then echo "PROVIDER_COMMAND variable is required."; exit -1; fi
kubectl --context kind-gke-metadata-server get --raw /openid/v1/jwks > jwks.json
gcloud iam workload-identity-pools providers ${PROVIDER_COMMAND}-oidc ${TEST_ID} \
--project=gke-metadata-server \
--location=global \
--workload-identity-pool=test-kind-cluster \
--issuer-uri=$$(kubectl --context kind-gke-metadata-server get --raw /.well-known/openid-configuration | jq -r .issuer) \
--attribute-mapping=google.subject=assertion.sub \
--jwk-json-path=jwks.json
.PHONY: install-cilium
install-cilium:
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs.inotify.max_user_instances=512
helm repo add cilium https://helm.cilium.io/
docker pull quay.io/cilium/cilium:v1.17.1
kind load docker-image --name gke-metadata-server quay.io/cilium/cilium:v1.17.1
helm install cilium cilium/cilium --version 1.17.1 \
--namespace kube-system \
--set image.pullPolicy=IfNotPresent \
--set ipam.mode=kubernetes
.PHONY: build
build:
docker build . -t ${TEST_IMAGE}:container
docker push ${TEST_IMAGE}:container | tee docker-push.logs
cat docker-push.logs | grep digest: | awk '{print $$3}' > container-digest.txt
mv .dockerignore .dockerignore.bkp
mv .dockerignore.test .dockerignore
docker build . -t ${TEST_IMAGE}:go-test -f Dockerfile.test
mv .dockerignore .dockerignore.test
mv .dockerignore.bkp .dockerignore
docker push ${TEST_IMAGE}:go-test | tee docker-push.logs
cat docker-push.logs | grep digest: | awk '{print $$3}' > go-test-digest.txt
sed "s|<HELM_VERSION>|$$(yq .helm versions.yaml)|g" helm/gke-metadata-server/Chart.tpl.yaml | \
sed "s|<CONTAINER_VERSION>|$$(yq .container versions.yaml)|g" > helm/gke-metadata-server/Chart.yaml
helm lint helm/gke-metadata-server
helm package helm/gke-metadata-server
helm push gke-metadata-server-helm-$$(yq .helm versions.yaml).tgz oci://${TEST_IMAGE} 2>&1 | tee helm-push.logs
cat helm-push.logs | grep Digest: | awk '{print $$NF}' > helm-digest.txt
sed "s|<CONTAINER_VERSION>|$$(yq .container versions.yaml)|g" \
timoni/gke-metadata-server/templates/config.tpl.cue > timoni/gke-metadata-server/templates/config.cue
timoni mod vet timoni/gke-metadata-server/ \
--name gke-metadata-server \
--namespace kube-system \
--values timoni/gke-metadata-server/debug_values.cue
timoni mod push timoni/gke-metadata-server/ oci://${TEST_IMAGE}/timoni \
--version $$(yq .timoni versions.yaml) \
--output yaml | yq .digest > timoni-digest.txt
.PHONY: test-unit
test-unit:
go test -v ${TEST_ARGS} $$(go list ./... | grep -v github.com/matheuscscp/gke-metadata-server/internal/server | \
grep -vE github.com/matheuscscp/gke-metadata-server$$)
.PHONY: test
test:
@if [ "${TEST_ID}" == "" ]; then echo "TEST_ID variable is required."; exit -1; fi
TEST_ID=${TEST_ID} TEST_IMAGE=${TEST_IMAGE} HELM_VERSION=$$(yq .helm versions.yaml) go test -v ${TEST_ARGS}
.PHONY: update-branch
update-branch:
git add .
git stash
git fetch --prune --all --force --tags
git update-ref refs/heads/main origin/main
git rebase main
git stash pop || true
.PHONY: drop-branch
drop-branch:
if [ $$(git status --porcelain=v1 2>/dev/null | wc -l) -ne 0 ]; then \
git status; \
echo ""; \
echo "Are you sure? You have uncommitted changes, consider using scripts/update-branch.sh."; \
exit 1; \
fi
git fetch --prune --all --force --tags
git update-ref refs/heads/main origin/main
BRANCH=$$(git branch --show-current); git checkout main; git branch -D $$BRANCH
.PHONY: bootstrap
bootstrap:
cd .github/workflows/ && terraform init && terraform apply && terraform plan -detailed-exitcode
.PHONY: plan
plan:
cd terraform/ && terraform init && terraform plan