-
Notifications
You must be signed in to change notification settings - Fork 179
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
232 lines (205 loc) · 8.23 KB
/
Taskfile.yaml
File metadata and controls
232 lines (205 loc) · 8.23 KB
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
# SPDX-FileCopyrightText: the secureCodeBox authors
#
# SPDX-License-Identifier: Apache-2.0
version: "3.48.0"
env:
IMG_NS: securecodebox
IMG_TAG:
sh: 'echo "sha-$(git rev-parse --short HEAD)"'
vars:
OPERATOR_IMG: operator
LURKER_IMG: lurker
CONTROLLER_TOOLS_VERSION: v0.18.0
ENVTEST_K8S_VERSION:
sh: cd {{ .TASKFILE_DIR }} && go list -m -f '{{"{{"}}.Version{{"}}"}}' k8s.io/api 2>/dev/null | sed -E 's/^v?[0-9]+\.([0-9]+).*/1.\1/'
ENVTEST_VERSION:
sh: cd {{ .TASKFILE_DIR }} && go list -m -f '{{"{{"}}.Version{{"}}"}}' sigs.k8s.io/controller-runtime 2>/dev/null | sed -E 's/^v?([0-9]+)\.([0-9]+).*/release-\1.\2/'
LOCALBIN: '{{ .TASKFILE_DIR }}/bin'
tasks:
controller-gen:
desc: "Download controller-gen locally if necessary"
run: once
dir: '{{ .TASKFILE_DIR }}'
generates:
- '{{ .LOCALBIN }}/controller-gen'
- '{{ .LOCALBIN }}/.controller-gen.version'
cmds:
- mkdir -p {{ .LOCALBIN }}
- rm -f {{ .LOCALBIN }}/controller-gen
- GOBIN={{ .LOCALBIN }} go install sigs.k8s.io/controller-tools/cmd/controller-gen@{{ .CONTROLLER_TOOLS_VERSION }}
- echo "{{ .CONTROLLER_TOOLS_VERSION }}" > {{ .LOCALBIN }}/.controller-gen.version
status:
- test -f {{ .LOCALBIN }}/controller-gen
- grep -qxF "{{ .CONTROLLER_TOOLS_VERSION }}" {{ .LOCALBIN }}/.controller-gen.version 2>/dev/null
envtest:
desc: "Download setup-envtest locally if necessary"
run: once
dir: '{{ .TASKFILE_DIR }}'
generates:
- '{{ .LOCALBIN }}/setup-envtest'
- '{{ .LOCALBIN }}/.setup-envtest.version'
cmds:
- mkdir -p {{ .LOCALBIN }}
- rm -f {{ .LOCALBIN }}/setup-envtest
- GOBIN={{ .LOCALBIN }} go install sigs.k8s.io/controller-runtime/tools/setup-envtest@{{ .ENVTEST_VERSION }}
- echo "{{ .ENVTEST_VERSION }}" > {{ .LOCALBIN }}/.setup-envtest.version
status:
- test -f {{ .LOCALBIN }}/setup-envtest
- grep -qxF "{{ .ENVTEST_VERSION }}" {{ .LOCALBIN }}/.setup-envtest.version 2>/dev/null
manifests:
desc: "Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects"
deps: [controller-gen]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- |
{{ .LOCALBIN }}/controller-gen rbac:roleName="securecodebox-manager-role",headerFile="hack/boilerplate.yaml.txt" \
crd:maxDescLen=256,headerFile="hack/boilerplate.yaml.txt" \
webhook paths="./..." \
output:crd:artifacts:config=crds \
output:rbac:artifacts:config=templates/rbac
generate:
desc: "Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations"
deps: [controller-gen]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- '{{ .LOCALBIN }}/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."'
fmt:
desc: "Run go fmt against code"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- go fmt ./...
vet:
desc: "Run go vet against code"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- go vet ./...
test:
desc: "Run all tests (fast and slow)"
deps: [manifests, generate, fmt, vet, envtest]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- |
KUBEBUILDER_ASSETS="$({{ .LOCALBIN }}/setup-envtest use {{ .ENVTEST_K8S_VERSION }} --bin-dir {{ .LOCALBIN }} -p path)" \
go test -tags="fast slow" ./... -coverprofile cover.out
test-fast:
desc: "Run fast tests only"
deps: [manifests, generate, fmt, vet, envtest]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- |
KUBEBUILDER_ASSETS="$({{ .LOCALBIN }}/setup-envtest use {{ .ENVTEST_K8S_VERSION }} -p path)" \
go test -tags="fast" ./... -coverprofile cover.out
view-coverage:
desc: "View test coverage in browser"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- go tool cover -html=cover.out
helm-unit-tests:
desc: "Run helm unit tests for operator"
dir: '{{ .TASKFILE_DIR }}'
preconditions:
- msg: "Helm unittest plugin is not installed. Install it from https://github.com/helm-unittest/helm-unittest/"
sh: "helm plugin list | grep -q 'unittest' || false"
cmds:
- 'echo "Running helm unit tests for operator"'
- helm unittest .
build:
desc: "Build manager binary"
deps: [generate, fmt, vet]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- go build -o bin/manager main.go
run:
desc: "Run the controller from your host"
deps: [manifests, generate, fmt, vet]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- go run ./main.go
docker-build:
desc: "Build Docker images for operator and lurker"
dir: '{{ .TASKFILE_DIR }}'
preconditions:
- msg: "Docker is not running, please start Docker first"
sh: "docker info >/dev/null 2>&1 || false"
cmds:
- 'echo "Building Container Images"'
- docker build -t ${IMG_NS}/{{ .OPERATOR_IMG }}:${IMG_TAG} {{ .TASKFILE_DIR }}
- docker build -t ${IMG_NS}/{{ .LURKER_IMG }}:${IMG_TAG} {{ .TASKFILE_DIR }}/../lurker
status:
- docker images | grep -q "${IMG_NS}/{{ .OPERATOR_IMG }}:${IMG_TAG}" || false
- docker images | grep -q "${IMG_NS}/{{ .LURKER_IMG }}:${IMG_TAG}" || false
docker-push:
desc: "Push Docker images for operator and lurker"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- docker push ${IMG_NS}/{{ .OPERATOR_IMG }}:${IMG_TAG}
- docker push ${IMG_NS}/{{ .LURKER_IMG }}:${IMG_TAG}
docker-export:
desc: "Export Docker images to tar files"
deps: [docker-build]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- task: docker-export-operator
- task: docker-export-lurker
docker-export-operator:
desc: "Export operator Docker image to tar file"
deps: [docker-build]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- 'echo "Exporting Operator Image"'
- docker save ${IMG_NS}/{{ .OPERATOR_IMG }}:${IMG_TAG} > {{ .OPERATOR_IMG }}.tar
docker-export-lurker:
desc: "Export lurker Docker image to tar file"
deps: [docker-build]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- 'echo "Exporting Lurker Image"'
- docker save ${IMG_NS}/{{ .LURKER_IMG }}:${IMG_TAG} > {{ .LURKER_IMG }}.tar
kind-import:
desc: "Import Docker images into kind cluster"
deps: [docker-export]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- 'echo "Importing image archives to local kind cluster"'
- kind load image-archive ./{{ .OPERATOR_IMG }}.tar
- kind load image-archive ./{{ .LURKER_IMG }}.tar
helm-deploy:
desc: "Deploy operator to kind cluster using Helm"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- 'echo "Deploying Operator with image tag ${IMG_TAG} into kind"'
- kubectl create namespace integration-tests --dry-run=client -o yaml | kubectl apply -f -
- kubectl create namespace securecodebox-system --dry-run=client -o yaml | kubectl apply -f -
- |
MINIO_ROOT_USER=$(kubectl get secret securecodebox-operator-minio -n securecodebox-system -o=jsonpath='{.data.root-user}' 2>/dev/null | base64 --decode || echo "")
MINIO_ROOT_PASSWORD=$(kubectl get secret securecodebox-operator-minio -n securecodebox-system -o=jsonpath='{.data.root-password}' 2>/dev/null | base64 --decode || echo "")
MINIO_ARGS=""
if [ -n "$MINIO_ROOT_USER" ] && [ -n "$MINIO_ROOT_PASSWORD" ]; then
MINIO_ARGS="--set=minio.auth.rootUser=$MINIO_ROOT_USER --set=minio.auth.rootPassword=$MINIO_ROOT_PASSWORD"
fi
helm -n securecodebox-system upgrade --install securecodebox-operator ./ --wait \
--set="image.repository=docker.io/${IMG_NS}/{{ .OPERATOR_IMG }}" \
--set="image.tag=${IMG_TAG}" \
--set="image.pullPolicy=IfNotPresent" \
--set="lurker.image.repository=docker.io/${IMG_NS}/{{ .LURKER_IMG }}" \
--set="lurker.image.tag=${IMG_TAG}" \
--set="lurker.image.pullPolicy=IfNotPresent" \
$MINIO_ARGS
kind-deploy:
desc: "Import and deploy Docker images to kind"
dir: '{{ .TASKFILE_DIR }}'
cmds:
- task: kind-import
- task: helm-deploy
install:
desc: "Install CRDs into the K8s cluster specified in ~/.kube/config"
deps: [manifests]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- kubectl apply -f ./crds/
uninstall:
desc: "Uninstall CRDs from the K8s cluster specified in ~/.kube/config"
deps: [manifests]
dir: '{{ .TASKFILE_DIR }}'
cmds:
- kubectl delete -f ./crds/