task-postgresql-pod.yaml 2.24 KB
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: task-postgresql-pod
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: job-name
  volumes:
    - name: task-postgresql-pod-kustomization
      configMap:
        name: task-postgresql-pod-kustomization
  steps:
    - name: mount-postgresql-pod-kustomization
      image: $(params.bash-image)
      script: |
        #!/usr/bin/env bash
        set -ex
        mkdir /workspace/kustomizations
        cd /srv/task-postgresql-pod-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-pod-kustomization
          mountPath: /srv/task-postgresql-pod-kustomization-cm
    - name: run-kustomize-4-x
      image: $(params.kustomize-image)
      script: |
        #!/bin/sh
        set -ex
        kustomize build /workspace/kustomizations/postgresql-pod > /workspace/postgresql-pod.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-pod.yaml
        sed -i -e 's/^  name:/  generateName:/' /workspace/postgresql-pod.yaml
        cat /workspace/postgresql-pod.yaml
    - name: create-postgresql-pod
      image: $(params.kubectl-image)
      script: |
        #!/usr/bin/env bash

        set -ex
        kubectl create -f /workspace/postgresql-pod.yaml -o jsonpath --template '{.metadata.name}'/ > /workspace/create-output.json
        cat /workspace/create-output.json

---