@@ -6,22 +6,25 @@ metadata:
6
6
labels :
7
7
app.kubernetes.io/version : " 0.8.0-dev"
8
8
annotations :
9
- tekton.dev/pipelines.minVersion : " 0.24 .x"
9
+ tekton.dev/pipelines.minVersion : " 0.44 .x"
10
10
tekton.dev/categories : infrastructure
11
11
tekton.dev/tags : infrastructure, aws, fedora
12
12
tekton.dev/displayName : " aws manager"
13
- tekton.dev/platforms : " linux/amd64"
13
+ tekton.dev/platforms : " linux/amd64, linux/arm64 "
14
14
spec :
15
15
description : |
16
16
Task provision a fedora dedicated on host on AWS
17
17
18
- The machine will offer nested virtualizataion capabilities as so it should be spin on a dedicated (baremetal) machine
19
-
20
- workspaces :
21
- - name : storage
22
- description : volume to store outputs to connect within the target machine + state file for the infrastructure
23
- mountPath : /opt/storage
18
+ volumes :
24
19
- name : aws-credentials
20
+ secret :
21
+ secretName : $(params.secret-aws-credentials)
22
+ - name : host-info
23
+ emptyDir : {}
24
+
25
+ params :
26
+ # mapt params
27
+ - name : secret-aws-credentials
25
28
description : |
26
29
ocp secret holding the aws credentials. Secret should be accessible to this task.
27
30
@@ -38,23 +41,42 @@ spec:
38
41
access-key: ${access_key}
39
42
secret-key: ${secret_key}
40
43
region: ${region}
41
- mountPath : /opt/aws-credentials
42
-
43
- params :
44
- # mapt params
45
- - name : project-name
46
- description : identifier for project.
47
- - name : backed-url
48
- description : |
49
- If we want to backed resources externally we can use s3 setting this param(i.e s3://existing-bucket).
50
-
51
- If default will be store on storage workspace at path set by param ws-output-path.
52
- default : " ''"
53
- - name : ws-output-path
54
- description : path on workspace where to store ephemeral assets related with the provisioning
44
+ bucket: ${bucket}
45
+ - name : id
46
+ description : identifier for the provisioned environment
55
47
- name : operation
56
48
description : operation to execute within the infrastructure. Current values (create, destroy)
57
49
50
+ # Secret result
51
+ # naming
52
+ - name : host-access-secret-name
53
+ type : string
54
+ default : " ''"
55
+ description : |
56
+ Once the target is provisioned the config to connect is addded to a secret
57
+ check resutls. If this param is set the secret will be created with the name set
58
+ otherwise it will be created with a random name.
59
+ # ownership
60
+ - name : ownerKind
61
+ type : string
62
+ default : PipelineRun
63
+ description : |
64
+ The type of resource that should own the generated SpaceRequest.
65
+ Deletion of this resource will trigger deletion of the SpaceRequest.
66
+ Supported values: `PipelineRun`, `TaskRun`.
67
+ - name : ownerName
68
+ type : string
69
+ description : |
70
+ The name of the resource that should own the generated SpaceRequest.
71
+ This should either be passed the value of `$(context.pipelineRun.name)`
72
+ or `$(context.taskRun.name)` depending on the value of `ownerKind`.
73
+ - name : ownerUid
74
+ type : string
75
+ description : |
76
+ The uid of the resource that should own the generated SpaceRequest.
77
+ This should either be passed the value of `$(context.pipelineRun.uid)`
78
+ or `$(context.taskRun.uid)` depending on the value of `ownerKind`.
79
+
58
80
# VM type params
59
81
- name : arch
60
82
description : Architecture for the machine. Allowed x86_64 or arm64 (default "x86_64")
74
96
75
97
# Fedora params
76
98
- name : version
77
- description : this task will spin a Fedora-Cloud image. This param will set the version for it. Default 40 .
78
- default : ' 40 '
99
+ description : this task will spin a Fedora-Cloud image. This param will set the version for it. Default 41 .
100
+ default : ' 41 '
79
101
80
102
# Topology params
81
103
- name : airgap
94
116
default : " ''"
95
117
96
118
# Control params
97
- - name : remove-lock
98
- description : in case a previous run fails the stack can be locked. This value allows to control if remove lock
99
- default : ' true'
100
119
- name : debug
101
120
description : |
102
121
Warning setting this param to true expose credentials
@@ -106,109 +125,129 @@ spec:
106
125
default : ' false'
107
126
108
127
results :
109
- - name : host
110
- description : ip to connect to the provisioned machine
111
- - name : username
112
- description : username to connect to the provisioned machine
113
- - name : key
114
- description : filename for the private key. The key is located at workspace-resources-path
115
- - name : bastion-host
116
- description : if airgap is set we get the bastion host as result
117
- - name : bastion-username
118
- description : if airgap is set we get the bastion username to connect as result
119
- - name : bastion-key
120
- description : if airgap is set we get the bastion filename for the private key. The key is located at workspace-resources-path
121
-
128
+ - name : host-access-secret
129
+ description : |
130
+ ocp secret holding the information to connect with the target machine.
131
+
132
+ ---
133
+ apiVersion: v1
134
+ kind: Secret
135
+ metadata:
136
+ name: ${name}
137
+ labels:
138
+ type: Opaque
139
+ data:
140
+ host: ${host}
141
+ username: ${username}
142
+ id_rsa: ${id_rsa}
143
+ # If airgap data for bastion host
144
+ bastion-host: ${bastion-host}
145
+ bastion-username: ${bastion-username}
146
+ bastion-id_rsa: ${bastion-id_rsa}
122
147
steps :
123
148
- name : provisioner
124
149
image : quay.io/redhat-developer/mapt:v0.8.0-dev
125
150
imagePullPolicy : Always
151
+ volumeMounts :
152
+ - name : aws-credentials
153
+ mountPath : /opt/aws-credentials
154
+ - name : host-info
155
+ mountPath : /opt/host-info
126
156
script : |
127
157
#!/bin/sh
128
158
159
+ set -euo pipefail
129
160
# If debug add verbosity
130
161
if [[ $(params.debug) == "true" ]]; then
131
- set -xuo
162
+ set -xeuo pipefail
132
163
fi
133
164
134
165
# Credentials
135
166
export AWS_ACCESS_KEY_ID=$(cat /opt/aws-credentials/access-key)
136
167
export AWS_SECRET_ACCESS_KEY=$(cat /opt/aws-credentials/secret-key)
137
168
export AWS_DEFAULT_REGION=$(cat /opt/aws-credentials/region)
138
-
139
- # Output folder
140
- workspace_path=/opt/storage/$(params.ws-output-path)
141
- mkdir -p ${workspace_path}
142
-
143
- # Remove lock
144
- if [[ $(params.remove-lock) == "true" ]]; then
145
- rm -rf ${workspace_path}/.pulumi/locks/*
146
- fi
169
+ BUCKET=$(cat /opt/aws-credentials/bucket)
147
170
148
171
# Run mapt
149
172
cmd="mapt aws fedora $(params.operation) "
150
- cmd="$cmd --project-name $(params.project-name) "
151
- # Set the backed url
152
- if [[ $(params.backed-url) != "" ]]; then
153
- cmd="$cmd --backed-url $(params.backed-url) "
154
- else
155
- cmd="$cmd --backed-url file://${workspace_path} "
156
- fi
173
+ cmd+="--project-name mapt-fedora-$(params.id) "
174
+ cmd+="--backed-url s3://${BUCKET}/mapt/fedora/$(params.id) "
157
175
if [[ $(params.operation) == "create" ]]; then
158
- cmd="$cmd --conn-details-output ${workspace_path} "
159
- cmd="$cmd --arch $(params.arch) "
160
- cmd="$cmd --cpus $(params.cpus) "
161
- cmd="$cmd --memory $(params.memory) "
162
- if [[ $(params.nested-virt) == "true" ]]; then
163
- cmd="$cmd --nested-virt "
164
- fi
165
- cmd="$cmd --version $(params.version) "
176
+ cmd+="--conn-details-output /opt/host-info "
177
+ cmd+="--arch $(params.arch) "
178
+ cmd+="--cpus $(params.cpus) "
179
+ cmd+="--memory $(params.memory) "
180
+ cmd+="--version $(params.version) "
181
+ if $($(params.nested-virt)); then cmd+="--nested-virt "; fi
182
+
166
183
if [[ $(params.spot) == "true" ]]; then
167
- cmd="$cmd --spot "
184
+ cmd+=" --spot "
168
185
fi
169
186
if [[ $(params.airgap) == "true" ]]; then
170
- cmd="$cmd --airgap "
171
- fi
172
- if [[ $(params.tags) != "" ]]; then
173
- cmd="$cmd --tags $(params.tags) "
187
+ cmd+="--airgap "
174
188
fi
189
+ cmd+="--tags $(params.tags) "
175
190
fi
176
191
eval "${cmd}"
177
-
178
- create_exit_code=$?
179
-
180
- # set task results
181
- cat "${workspace_path}/host" | tee $(results.host.path)
182
- cat "${workspace_path}/username" | tee $(results.username.path)
183
- echo -n "id_rsa" | tee $(results.key.path)
184
- if [[ $(params.airgap) == "true" ]]; then
185
- cat "${workspace_path}/bastion_host" | tee $(results.bastion-host.path)
186
- cat "${workspace_path}/bastion_username" | tee $(results.bastion-username.path)
187
- echo -n "bastion_id_rsa" | tee $(results.bastion-key.path)
188
- fi
189
-
190
- # If debug print credentials
191
- if [[ $(params.debug) == "true" ]]; then
192
- echo "Credentials to access target machine \n"
193
- cat "${workspace_path}/host"
194
- cat "${workspace_path}/username"
195
- cat "${workspace_path}/id_rsa"
196
- if [[ $(params.airgap) == "true" ]]; then
197
- cat "${workspace_path}/bastion_host"
198
- cat "${workspace_path}/bastion_username"
199
- cat "${workspace_path}/bastion_id_rsa"
200
- fi
201
- fi
202
-
203
- if [[ ${create_exit_code} -ne 0 ]]; then
204
- exit 1
205
- fi
206
-
207
192
resources :
208
193
requests :
209
194
memory : " 200Mi"
210
195
cpu : " 100m"
211
196
limits :
212
197
memory : " 600Mi"
213
198
cpu : " 300m"
214
-
199
+ - name : host-info-secret
200
+ image : registry.redhat.io/openshift4/ose-cli:4.13@sha256:e70eb2be867f1236b19f5cbfeb8e0625737ce0ec1369e32a4f9f146aaaf68d49
201
+ env :
202
+ - name : NAMESPACE
203
+ value : $(context.taskRun.namespace)
204
+ - name : OWNER_KIND
205
+ value : $(params.ownerKind)
206
+ - name : OWNER_NAME
207
+ value : $(params.ownerName)
208
+ - name : OWNER_UID
209
+ value : $(params.ownerUid)
210
+ volumeMounts :
211
+ - name : host-info
212
+ mountPath : /opt/host-info
213
+ script : |
214
+ #!/bin/bash
215
+ set -eo pipefail
216
+ if [[ $(params.operation) == "create" ]]; then
217
+ export SECRETNAME="generateName: mapt-aws-fedora-"
218
+ if [[ $(params.host-access-secret-name) != "" ]]; then
219
+ export SECRETNAME="name: $(params.host-access-secret-name)"
220
+ fi
221
+ cat <<EOF > host-info.yaml
222
+ apiVersion: v1
223
+ kind: Secret
224
+ metadata:
225
+ $SECRETNAME
226
+ namespace: $NAMESPACE
227
+ ownerReferences:
228
+ - apiVersion: tekton.dev/v1
229
+ kind: $OWNER_KIND
230
+ name: $OWNER_NAME
231
+ uid: $OWNER_UID
232
+ type: Opaque
233
+ data:
234
+ host: $(cat /opt/host-info/host | base64 -w0)
235
+ username: $(cat /opt/host-info/username | base64 -w0)
236
+ id_rsa: $(cat /opt/host-info/id_rsa | base64 -w0)
237
+ EOF
238
+ if [[ $(params.airgap) == "true" ]]; then
239
+ cat <<EOF >> host-info.yaml
240
+ bastion-host: $(cat /opt/host-info/bastion_host | base64 -w0)
241
+ bastion-username: $(cat /opt/host-info/bastion_username | base64 -w0)
242
+ bastion-id_rsa: $(cat /opt/host-info/bastion_id_rsa | base64 -w0)
243
+ EOF
244
+ fi
245
+
246
+ if [[ $(params.debug) == "true" ]]; then
247
+ cat /opt/host-info/*
248
+ fi
249
+
250
+ NAME=$(oc create -f host-info.yaml -o=jsonpath='{.metadata.name}')
251
+ echo -n "${NAME}" | tee $(results.host-access-secret.path)
252
+ fi
253
+
0 commit comments