forked from redhat-developer/mapt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfra-aws-kind.yaml
More file actions
310 lines (282 loc) · 10.3 KB
/
Copy pathinfra-aws-kind.yaml
File metadata and controls
310 lines (282 loc) · 10.3 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: infra-aws-kind
labels:
app.kubernetes.io/version: "<VERSION>"
annotations:
tekton.dev/pipelines.minVersion: "0.44.x"
tekton.dev/categories: infrastructure
tekton.dev/tags: infrastructure, aws, kind
tekton.dev/displayName: "aws manager"
tekton.dev/platforms: "linux/amd64, linux/arm64"
spec:
description: |
Task provision a OpenShift Single Node Cluster based on OpenShift Local
volumes:
- name: aws-credentials
secret:
secretName: $(params.secret-aws-credentials)
- name: cluster-info
emptyDir: {}
params:
# Credentials
- name: secret-aws-credentials
description: |
ocp secret holding the aws credentials. Secret should be accessible to this task.
---
apiVersion: v1
kind: Secret
metadata:
name: aws-${name}
type: Opaque
data:
access-key: ${access_key}
secret-key: ${secret_key}
region: ${region}
bucket: ${bucket}
# Mapt params
- name: id
description: identifier for the provisioned environment
- name: operation
description: operation to execute within the infrastructure. Current values (create, destroy)
# Secret result
# naming
- name: cluster-access-secret-name
type: string
default: "''"
description: |
Once the target is provisioned the config to connect is addded to a secret
check resutls. If this param is set the secret will be created with the name set
otherwise it will be created with a random name.
# ownership
- name: ownerKind
type: string
default: PipelineRun
description: |
The type of resource that should own the generated SpaceRequest.
Deletion of this resource will trigger deletion of the SpaceRequest.
Supported values: `PipelineRun`, `TaskRun`.
- name: ownerName
type: string
default: "''"
description: |
The name of the resource that should own the generated SpaceRequest.
This should either be passed the value of `$(context.pipelineRun.name)`
or `$(context.taskRun.name)` depending on the value of `ownerKind`.
- name: ownerUid
type: string
default: "''"
description: |
The uid of the resource that should own the generated SpaceRequest.
This should either be passed the value of `$(context.pipelineRun.uid)`
or `$(context.taskRun.uid)` depending on the value of `ownerKind`.
# VM type params
- name: arch
description: Architecture for the machine. Allowed x86_64 or arm64 (default "x86_64")
default: 'x86_64'
- name: cpus
description: Number of CPUs for the cloud instance (default 8)
default: '8'
- name: memory
description: Amount of RAM for the cloud instance in GiB (default 64)
default: '64'
- name: nested-virt
description: Use cloud instance that has nested virtualization support
default: 'false'
- name: spot
description: Check best spot option to spin the machine and will create resources on that region.
default: 'true'
- name: spot-increase-rate
description: Percentage to be added on top of the current calculated spot price to increase chances to get the machine.
default: '20'
- name: spot-eviction-tolerance
description: |
if spot is enable we can define the minimum tolerance level of eviction.
Allowed value are: lowest, low, medium, high or highest
default: 'lowest'
# OCP params
- name: version
description: Version for k8s cluster. If not version set it will pick the latest stable
default: "''"
# Network params
- name: service-endpoints
description: |
Comma-separated list of VPC service endpoints to create.
Accepted values: s3, ecr, ssm. Empty = no endpoints created.
default: "''"
# Metadata params
- name: tags
description: tags for the resources created on the providers
default: "''"
# Control params
- name: debug
description: |
Warning setting this param to true exposes partially masked credentials
The parameter is intended to add verbosity on the task execution and also print masked credentials
(showing first and last character with *** in the middle) on stdout to help with debugging
default: 'false'
- name: force-destroy
description: |
If force-destroy is set the command will destroy even if there is a lock.
Allowed values: true, false
default: "false"
- name: keep-state
description: |
Keep Pulumi state files in S3 backend after successful destroy (by default, state files are removed). Only used when operation is destroy.
Allowed values: true, false
default: 'false'
- name: timeout
description: The Timeout value is a duration conforming to Go ParseDuration format. This will set a serverless destroy operation based on this.
default: "''"
results:
- name: cluster-access-secret
description: |
ocp secret holding the information to connect to the cluster
---
apiVersion: v1
kind: Secret
metadata:
name: ${name}
type: Opaque
data:
kubeconfig: ${kubeconfig}
steps:
- name: provisioner
image: <IMAGE>
imagePullPolicy: Always
env:
- name: HOME
value: /opt/mapt/run
volumeMounts:
- name: aws-credentials
mountPath: /opt/aws-credentials
- name: cluster-info
mountPath: /opt/cluster-info
script: |
#!/bin/sh
set -euo pipefail
# Function to mask credentials (show first and last char, hide middle)
mask_credential() {
local cred="$1"
local len=${#cred}
if [ $len -le 2 ]; then
echo "***"
else
echo "${cred:0:1}***${cred: -1}"
fi
}
# Credentials - set these BEFORE enabling debug mode
export AWS_ACCESS_KEY_ID=$(cat /opt/aws-credentials/access-key)
export AWS_SECRET_ACCESS_KEY=$(cat /opt/aws-credentials/secret-key)
export AWS_DEFAULT_REGION=$(cat /opt/aws-credentials/region)
BUCKET=$(cat /opt/aws-credentials/bucket)
# If debug add verbosity and print masked credentials
if [[ $(params.debug) == "true" ]]; then
echo "AWS_ACCESS_KEY_ID=$(mask_credential "$AWS_ACCESS_KEY_ID")"
echo "AWS_SECRET_ACCESS_KEY=$(mask_credential "$AWS_SECRET_ACCESS_KEY")"
echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
echo "BUCKET=$BUCKET"
set -xeuo pipefail
fi
if [[ $(params.operation) == "create" ]]; then
if [[ $(params.ownerName) == "" || $(params.ownerUid) == "" ]]; then
echo "Parameter ownerName and ownerUid is recommended when creating instance"
fi
fi
# Run mapt
cmd="mapt aws kind $(params.operation) "
cmd+="--project-name kind-$(params.id) "
cmd+="--backed-url s3://${BUCKET}/mapt/kind/$(params.id) "
if [[ $(params.debug) == "true" ]]; then
cmd+="--debug "
fi
if [[ $(params.operation) == "create" ]]; then
cmd+="--conn-details-output /opt/cluster-info "
cmd+="--arch $(params.arch) "
cmd+="--cpus $(params.cpus) "
cmd+="--memory $(params.memory) "
if [[ $(params.nested-virt) == "true" ]]; then
cmd+="--nested-virt "
fi
if [[ $(params.version) != "" ]]; then
cmd+="--version $(params.version) "
fi
if [[ $(params.spot) == "true" ]]; then
cmd+="--spot --spot-increase-rate $(params.spot-increase-rate) --spot-eviction-tolerance $(params.spot-eviction-tolerance) "
fi
if [[ $(params.timeout) != "" ]]; then
cmd+="--timeout $(params.timeout) "
fi
if [[ $(params.service-endpoints) != "" ]]; then
cmd+="--service-endpoints $(params.service-endpoints) "
fi
cmd+="--tags $(params.tags) "
fi
if [[ "$(params.operation)" == "destroy" ]]; then
if [[ "$(params.keep-state)" == "true" ]]; then
cmd+="--keep-state "
fi
if [[ "$(params.force-destroy)" == "true" ]]; then
cmd+="--force-destroy "
fi
fi
eval "${cmd}"
resources:
requests:
memory: "200Mi"
cpu: "100m"
limits:
memory: "600Mi"
cpu: "300m"
- name: host-info-secret
image: registry.redhat.io/openshift4/ose-cli:4.13@sha256:e70eb2be867f1236b19f5cbfeb8e0625737ce0ec1369e32a4f9f146aaaf68d49
env:
- name: NAMESPACE
value: $(context.taskRun.namespace)
- name: OWNER_KIND
value: $(params.ownerKind)
- name: OWNER_NAME
value: $(params.ownerName)
- name: OWNER_UID
value: $(params.ownerUid)
volumeMounts:
- name: cluster-info
mountPath: /opt/cluster-info
workingDir: /opt/cluster-info
script: |
#!/bin/bash
set -eo pipefail
if [[ $(params.operation) == "create" ]]; then
export SECRETNAME="generateName: mapt-aws-kind-"
if [[ $(params.cluster-access-secret-name) != "" ]]; then
export SECRETNAME="name: $(params.cluster-access-secret-name)"
fi
cat <<EOF > cluster-info.yaml
apiVersion: v1
kind: Secret
metadata:
$SECRETNAME
namespace: $NAMESPACE
EOF
if [[ "$OWNER_NAME" != "" && "$OWNER_UID" != "" ]]; then
cat <<EOF >> cluster-info.yaml
ownerReferences:
- apiVersion: tekton.dev/v1
kind: $OWNER_KIND
name: $OWNER_NAME
uid: $OWNER_UID
EOF
fi
cat <<EOF >> cluster-info.yaml
type: Opaque
data:
kubeconfig: $(cat /opt/cluster-info/kubeconfig | base64 -w0)
EOF
if [[ $(params.debug) == "true" ]]; then
cat /opt/cluster-info/*
fi
NAME=$(oc create -f cluster-info.yaml -o=jsonpath='{.metadata.name}')
echo -n "${NAME}" | tee $(results.cluster-access-secret.path)
fi