task-postgresql-service.yaml
2.36 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
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: task-postgresql-service
spec:
description: >-
This Task deploys (or delete) a Kubernetes resource (pod). It uses
kubectl for that.
params:
- name: kubectl-image
default: bitnami/kubectl:1.21
- name: bash-image
default: bash
- name: kustomize-image
default: us.gcr.io/k8s-artifacts-prod/kustomize/kustomize:v4.5.2
results:
- name: service-name
volumes:
- name: task-postgresql-service-kustomization
configMap:
name: task-postgresql-service-kustomization
steps:
- name: mount-postgresql-service-kustomization
image: $(params.bash-image)
script: |
#!/usr/bin/env bash
set -ex
mkdir /workspace/kustomizations
cd /srv/task-postgresql-service-kustomization-cm/
for file in *; do
translated="$(echo "$file" | sed "s,_,/,g")"
dir="$(dirname "$translated")"
base="$(basename "$translated")"
mkdir -p "/workspace/kustomizations/$dir"
cp "$file" "/workspace/kustomizations/$dir/$base"
done
volumeMounts:
- name: task-postgresql-service-kustomization
mountPath: /srv/task-postgresql-service-kustomization-cm
- name: run-kustomize-4-x
image: $(params.kustomize-image)
script: |
#!/bin/sh
set -ex
kustomize build /workspace/kustomizations/postgresql-service > /workspace/postgresql-service.yaml
env:
- name: PARENT_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: PARENT_POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
- name: set-generate-name
image: $(params.bash-image)
script: |
#!/usr/bin/env bash
set -ex
cat /workspace/postgresql-service.yaml
sed -i -e 's/^ name:/ generateName:/' /workspace/postgresql-service.yaml
cat /workspace/postgresql-service.yaml
- name: create-postgresql-service
image: $(params.kubectl-image)
script: |
#!/usr/bin/env bash
set -ex
kubectl create -f /workspace/postgresql-service.yaml -o go-template --template '{{ if eq .kind "Service" }}{{.metadata.name }}{{ end }}' > $(results.service-name.path)
echo "servie name: $(cat $(results.service-name.path))"
---