-
Notifications
You must be signed in to change notification settings - Fork 32
/
Makefile
executable file
·245 lines (204 loc) · 10.8 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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# Copyright 2018 The Kubernetes Authors.
# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
export REGISTRY ?= jiaxun
export STAGINGVERSION ?= $(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
export OVERLAY ?= stable
export BUILD_GCSFUSE_FROM_SOURCE ?= false
export BUILD_ARM ?= false
BINDIR ?= $(shell pwd)/bin
GCSFUSE_PATH ?= $(shell cat cmd/sidecar_mounter/gcsfuse_binary)
LDFLAGS ?= -s -w -X main.version=${STAGINGVERSION} -extldflags '-static'
# assume that a GKE cluster identifier follows the format gke_{project-name}_{location}_{cluster-name}
PROJECT ?= $(shell kubectl config current-context | cut -d '_' -f 2)
CA_BUNDLE ?= $(shell kubectl config view --raw -o json | jq '.clusters[]' | jq "select(.name == \"$(shell kubectl config current-context)\")" | jq '.cluster."certificate-authority-data"' | head -n 1)
IDENTITY_PROVIDER ?= $(shell kubectl get --raw /.well-known/openid-configuration | jq -r .issuer)
DRIVER_BINARY = gcs-fuse-csi-driver
SIDECAR_BINARY = gcs-fuse-csi-driver-sidecar-mounter
WEBHOOK_BINARY = gcs-fuse-csi-driver-webhook
PREFETCH_BINARY = gcs-fuse-csi-driver-metadata-prefetch
DRIVER_IMAGE = ${REGISTRY}/${DRIVER_BINARY}
SIDECAR_IMAGE = ${REGISTRY}/${SIDECAR_BINARY}
WEBHOOK_IMAGE = ${REGISTRY}/${WEBHOOK_BINARY}
PREFETCH_IMAGE = ${REGISTRY}/${PREFETCH_BINARY}
DOCKER_BUILDX_ARGS ?= --push --builder multiarch-multiplatform-builder --build-arg STAGINGVERSION=${STAGINGVERSION}
ifneq ("$(shell docker buildx build --help | grep 'provenance')", "")
DOCKER_BUILDX_ARGS += --provenance=false
endif
$(info PROJECT is ${PROJECT})
$(info OVERLAY is ${OVERLAY})
$(info STAGINGVERSION is ${STAGINGVERSION})
$(info DRIVER_IMAGE is ${DRIVER_IMAGE})
$(info SIDECAR_IMAGE is ${SIDECAR_IMAGE})
$(info WEBHOOK_IMAGE is ${WEBHOOK_IMAGE})
all: driver sidecar-mounter webhook metadata-prefetch
driver:
mkdir -p ${BINDIR}
CGO_ENABLED=0 GOOS=linux go build -mod vendor -ldflags "${LDFLAGS}" -o ${BINDIR}/${DRIVER_BINARY} cmd/csi_driver/main.go
sidecar-mounter:
mkdir -p ${BINDIR}
CGO_ENABLED=0 GOOS=linux go build -mod vendor -ldflags "${LDFLAGS}" -o ${BINDIR}/${SIDECAR_BINARY} cmd/sidecar_mounter/main.go
metadata-prefetch:
mkdir -p ${BINDIR}
CGO_ENABLED=0 GOOS=linux go build -mod vendor -ldflags "${LDFLAGS}" -o ${BINDIR}/${PREFETCH_BINARY} cmd/metadata_prefetch/main.go
webhook:
mkdir -p ${BINDIR}
CGO_ENABLED=0 GOOS=linux go build -mod vendor -ldflags "${LDFLAGS}" -o ${BINDIR}/${WEBHOOK_BINARY} cmd/webhook/main.go
download-gcsfuse:
mkdir -p ${BINDIR}/linux/amd64 ${BINDIR}/linux/arm64
ifeq (${BUILD_GCSFUSE_FROM_SOURCE}, true)
rm -f ${BINDIR}/Dockerfile.gcsfuse
curl https://raw.githubusercontent.com/GoogleCloudPlatform/gcsfuse/master/tools/package_gcsfuse_docker/Dockerfile -o ${BINDIR}/Dockerfile.gcsfuse
$(eval GCSFUSE_VERSION=999.$(shell git ls-remote https://github.com/GoogleCloudPlatform/gcsfuse.git HEAD | cut -c 1-40))
docker buildx build \
--load \
--file ${BINDIR}/Dockerfile.gcsfuse \
--tag gcsfuse-release:${GCSFUSE_VERSION}-amd \
--build-arg GCSFUSE_VERSION=${GCSFUSE_VERSION} \
--build-arg BRANCH_NAME=master \
--build-arg ARCHITECTURE=amd64 \
--platform=linux/amd64 .
docker run \
-v ${BINDIR}/linux/amd64:/release \
gcsfuse-release:${GCSFUSE_VERSION}-amd \
cp /gcsfuse_${GCSFUSE_VERSION}_amd64/usr/bin/gcsfuse /release
ifeq (${BUILD_ARM}, true)
docker buildx build \
--load \
--file ${BINDIR}/Dockerfile.gcsfuse \
--tag gcsfuse-release:${GCSFUSE_VERSION}-arm \
--build-arg GCSFUSE_VERSION=${GCSFUSE_VERSION} \
--build-arg BRANCH_NAME=master \
--build-arg ARCHITECTURE=arm64 \
--platform=linux/arm64 .
docker run \
-v ${BINDIR}/linux/arm64:/release \
gcsfuse-release:${GCSFUSE_VERSION}-arm \
cp /gcsfuse_${GCSFUSE_VERSION}_arm64/usr/bin/gcsfuse /release
endif
else
gsutil cp ${GCSFUSE_PATH}/linux/amd64/gcsfuse ${BINDIR}/linux/amd64/gcsfuse
ifeq (${BUILD_ARM}, true)
gsutil cp ${GCSFUSE_PATH}/linux/arm64/gcsfuse ${BINDIR}/linux/arm64/gcsfuse
endif
endif
chmod +x ${BINDIR}/linux/amd64/gcsfuse
chmod 0555 ${BINDIR}/linux/amd64/gcsfuse
ifeq (${BUILD_ARM}, true)
chmod +x ${BINDIR}/linux/arm64/gcsfuse
chmod 0555 ${BINDIR}/linux/arm64/gcsfuse
endif
${BINDIR}/linux/$(shell dpkg --print-architecture)/gcsfuse --version
init-buildx:
# Ensure we use a builder that can leverage it (the default on linux will not)
-docker buildx rm multiarch-multiplatform-builder
docker buildx create --use --name=multiarch-multiplatform-builder
docker run --rm --privileged multiarch/qemu-user-static --reset --credential yes --persistent yes
# Register gcloud as a Docker credential helper.
# Required for "docker buildx build --push".
gcloud auth configure-docker --quiet
build-image-and-push-multi-arch: init-buildx download-gcsfuse build-image-linux-amd64
ifeq (${BUILD_ARM}, true)
make build-image-linux-arm64
docker manifest create ${DRIVER_IMAGE}:${STAGINGVERSION} ${DRIVER_IMAGE}:${STAGINGVERSION}_linux_amd64 ${DRIVER_IMAGE}:${STAGINGVERSION}_linux_arm64
docker manifest create ${SIDECAR_IMAGE}:${STAGINGVERSION} ${SIDECAR_IMAGE}:${STAGINGVERSION}_linux_amd64 ${SIDECAR_IMAGE}:${STAGINGVERSION}_linux_arm64
docker manifest create ${PREFETCH_IMAGE}:${STAGINGVERSION} ${PREFETCH_IMAGE}:${STAGINGVERSION}_linux_amd64 ${PREFETCH_IMAGE}:${STAGINGVERSION}_linux_arm64
else
docker manifest create ${DRIVER_IMAGE}:${STAGINGVERSION} ${DRIVER_IMAGE}:${STAGINGVERSION}_linux_amd64
docker manifest create ${SIDECAR_IMAGE}:${STAGINGVERSION} ${SIDECAR_IMAGE}:${STAGINGVERSION}_linux_amd64
docker manifest create ${PREFETCH_IMAGE}:${STAGINGVERSION} ${PREFETCH_IMAGE}:${STAGINGVERSION}_linux_amd64
endif
docker manifest create ${WEBHOOK_IMAGE}:${STAGINGVERSION} ${WEBHOOK_IMAGE}:${STAGINGVERSION}_linux_amd64
docker manifest push --purge ${DRIVER_IMAGE}:${STAGINGVERSION}
docker manifest push --purge ${SIDECAR_IMAGE}:${STAGINGVERSION}
docker manifest push --purge ${PREFETCH_IMAGE}:${STAGINGVERSION}
docker manifest push --purge ${WEBHOOK_IMAGE}:${STAGINGVERSION}
build-image-linux-amd64:
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/metadata_prefetch/Dockerfile \
--tag ${PREFETCH_IMAGE}:${STAGINGVERSION}_linux_amd64 \
--platform linux/amd64 \
--build-arg TARGETPLATFORM=linux/amd64 .
docker buildx build \
--file ./cmd/csi_driver/Dockerfile \
--tag validation_linux_amd64 \
--platform=linux/amd64 \
--target validation-image .
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/csi_driver/Dockerfile \
--tag ${DRIVER_IMAGE}:${STAGINGVERSION}_linux_amd64 \
--platform linux/amd64 .
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/sidecar_mounter/Dockerfile \
--tag ${SIDECAR_IMAGE}:${STAGINGVERSION}_linux_amd64 \
--platform linux/amd64 \
--build-arg TARGETPLATFORM=linux/amd64 .
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/webhook/Dockerfile \
--tag ${WEBHOOK_IMAGE}:${STAGINGVERSION}_linux_amd64 \
--platform linux/amd64 .
build-image-linux-arm64:
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/metadata_prefetch/Dockerfile \
--tag ${PREFETCH_IMAGE}:${STAGINGVERSION}_linux_arm64 \
--platform linux/arm64 \
--build-arg TARGETPLATFORM=linux/arm64 .
docker buildx build \
--file ./cmd/csi_driver/Dockerfile \
--tag validation_linux_arm64 \
--platform=linux/arm64 \
--target validation-image .
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/csi_driver/Dockerfile \
--tag ${DRIVER_IMAGE}:${STAGINGVERSION}_linux_arm64 \
--platform linux/arm64 .
docker buildx build ${DOCKER_BUILDX_ARGS} \
--file ./cmd/sidecar_mounter/Dockerfile \
--tag ${SIDECAR_IMAGE}:${STAGINGVERSION}_linux_arm64 \
--platform linux/arm64 \
--build-arg TARGETPLATFORM=linux/arm64 .
install:
make generate-spec-yaml OVERLAY=${OVERLAY} REGISTRY=${REGISTRY} STAGINGVERSION=${STAGINGVERSION}
kubectl apply -f ${BINDIR}/gcs-fuse-csi-driver-specs-generated.yaml
./deploy/base/webhook/create-cert.sh --namespace gcs-fuse-csi-driver --service gcs-fuse-csi-driver-webhook --secret gcs-fuse-csi-driver-webhook-secret
./deploy/base/webhook/manage-validating_admission_policy.sh --install
uninstall:
make generate-spec-yaml OVERLAY=${OVERLAY} REGISTRY=${REGISTRY} STAGINGVERSION=${STAGINGVERSION}
kubectl delete -f ${BINDIR}/gcs-fuse-csi-driver-specs-generated.yaml --wait
./deploy/base/webhook/manage-validating_admission_policy.sh --uninstall
generate-spec-yaml:
mkdir -p ${BINDIR}
./deploy/install-kustomize.sh
cd ./deploy/overlays/${OVERLAY}; ${BINDIR}/kustomize edit set image gke.gcr.io/gcs-fuse-csi-driver=${DRIVER_IMAGE}:${STAGINGVERSION};
cd ./deploy/overlays/${OVERLAY}; ${BINDIR}/kustomize edit set image gke.gcr.io/gcs-fuse-csi-driver-webhook=${WEBHOOK_IMAGE}:${STAGINGVERSION};
cd ./deploy/overlays/${OVERLAY}; ${BINDIR}/kustomize edit add configmap gcsfusecsi-image-config --behavior=merge --disableNameSuffixHash --from-literal=sidecar-image=${SIDECAR_IMAGE}:${STAGINGVERSION};
cd ./deploy/overlays/${OVERLAY}; ${BINDIR}/kustomize edit add configmap gcsfusecsi-image-config --behavior=merge --disableNameSuffixHash --from-literal=metadata-sidecar-image=${PREFETCH_IMAGE}:${STAGINGVERSION};
echo "[{\"op\": \"replace\",\"path\": \"/spec/tokenRequests/0/audience\",\"value\": \"${PROJECT}.svc.id.goog\"}]" > ./deploy/overlays/${OVERLAY}/project_patch_csi_driver.json
echo "[{\"op\": \"replace\",\"path\": \"/webhooks/0/clientConfig/caBundle\",\"value\": \"${CA_BUNDLE}\"}]" > ./deploy/overlays/${OVERLAY}/caBundle_patch_MutatingWebhookConfiguration.json
echo "[{\"op\": \"replace\",\"path\": \"/spec/template/spec/containers/0/env/1/value\",\"value\": \"${IDENTITY_PROVIDER}\"}]" > ./deploy/overlays/${OVERLAY}/identity_provider_patch_csi_node.json
kubectl kustomize deploy/overlays/${OVERLAY} | tee ${BINDIR}/gcs-fuse-csi-driver-specs-generated.yaml > /dev/null
git restore ./deploy/overlays/${OVERLAY}/kustomization.yaml
git restore ./deploy/overlays/${OVERLAY}/project_patch_csi_driver.json
git restore ./deploy/overlays/${OVERLAY}/caBundle_patch_MutatingWebhookConfiguration.json
git restore ./deploy/overlays/${OVERLAY}/identity_provider_patch_csi_node.json
verify:
hack/verify-all.sh
unit-test:
go test -v -mod=vendor -timeout 30s "./pkg/..." -cover
sanity-test:
go test -v -mod=vendor -timeout 30s "./test/sanity/" -run TestSanity
e2e-test:
./test/e2e/run-e2e-local.sh
perf-test:
make e2e-test E2E_TEST_USE_MANAGED_DRIVER=true E2E_TEST_GINKGO_TIMEOUT=3h E2E_TEST_SKIP= E2E_TEST_FOCUS=should.succeed.in.performance.test E2E_TEST_GINKGO_FLAKE_ATTEMPTS=1