Skip to content

Commit c1e0082

Browse files
committed
feat: remove dependency for specific workspace feature offered by tekton
Previously mapt weas using workspaces as input spaces for cloud credentials this could be done by using more basic components from k8s volumes, also the resulting information to connect within the provisioned machine / service was return as a combination of plain results and stored files on location from workspaces. this commit will change the approach to create a specific secret holding the information as another basic resources offered by k8s Signed-off-by: Adrian Riobo <[email protected]>
1 parent 39be54b commit c1e0082

17 files changed

+2468
-1541
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ define tkn_update
3838
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-mac.yaml > tkn/infra-aws-mac.yaml
3939
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-rhel.yaml > tkn/infra-aws-rhel.yaml
4040
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-aws-windows-server.yaml > tkn/infra-aws-windows-server.yaml
41+
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-aks.yaml > tkn/infra-azure-aks.yaml
4142
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-rhel.yaml > tkn/infra-azure-rhel.yaml
4243
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-fedora.yaml > tkn/infra-azure-fedora.yaml
4344
sed -e 's%<IMAGE>%$(1)%g' -e 's%<VERSION>%$(2)%g' tkn/template/infra-azure-windows-desktop.yaml > tkn/infra-azure-windows-desktop.yaml

tkn/infra-aws-fedora.yaml

+140-101
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,25 @@ metadata:
66
labels:
77
app.kubernetes.io/version: "0.8.0-dev"
88
annotations:
9-
tekton.dev/pipelines.minVersion: "0.24.x"
9+
tekton.dev/pipelines.minVersion: "0.44.x"
1010
tekton.dev/categories: infrastructure
1111
tekton.dev/tags: infrastructure, aws, fedora
1212
tekton.dev/displayName: "aws manager"
13-
tekton.dev/platforms: "linux/amd64"
13+
tekton.dev/platforms: "linux/amd64, linux/arm64"
1414
spec:
1515
description: |
1616
Task provision a fedora dedicated on host on AWS
1717
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:
2419
- 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
2528
description: |
2629
ocp secret holding the aws credentials. Secret should be accessible to this task.
2730
@@ -38,23 +41,42 @@ spec:
3841
access-key: ${access_key}
3942
secret-key: ${secret_key}
4043
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
5547
- name: operation
5648
description: operation to execute within the infrastructure. Current values (create, destroy)
5749

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+
5880
# VM type params
5981
- name: arch
6082
description: Architecture for the machine. Allowed x86_64 or arm64 (default "x86_64")
@@ -74,8 +96,8 @@ spec:
7496

7597
# Fedora params
7698
- 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'
79101

80102
# Topology params
81103
- name: airgap
@@ -94,9 +116,6 @@ spec:
94116
default: "''"
95117

96118
# 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'
100119
- name: debug
101120
description: |
102121
Warning setting this param to true expose credentials
@@ -106,109 +125,129 @@ spec:
106125
default: 'false'
107126

108127
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}
122147
steps:
123148
- name: provisioner
124149
image: quay.io/redhat-developer/mapt:v0.8.0-dev
125150
imagePullPolicy: Always
151+
volumeMounts:
152+
- name: aws-credentials
153+
mountPath: /opt/aws-credentials
154+
- name: host-info
155+
mountPath: /opt/host-info
126156
script: |
127157
#!/bin/sh
128158
159+
set -euo pipefail
129160
# If debug add verbosity
130161
if [[ $(params.debug) == "true" ]]; then
131-
set -xuo
162+
set -xeuo pipefail
132163
fi
133164
134165
# Credentials
135166
export AWS_ACCESS_KEY_ID=$(cat /opt/aws-credentials/access-key)
136167
export AWS_SECRET_ACCESS_KEY=$(cat /opt/aws-credentials/secret-key)
137168
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)
147170
148171
# Run mapt
149172
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) "
157175
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+
166183
if [[ $(params.spot) == "true" ]]; then
167-
cmd="$cmd --spot "
184+
cmd+="--spot "
168185
fi
169186
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 "
174188
fi
189+
cmd+="--tags $(params.tags) "
175190
fi
176191
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-
207192
resources:
208193
requests:
209194
memory: "200Mi"
210195
cpu: "100m"
211196
limits:
212197
memory: "600Mi"
213198
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

Comments
 (0)