be988437 by Adam Heath

Initial set of files; haven't tried to use these remotely yet.

1 parent 1e93eb2c
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./task-postgresql-pod.yaml
configMapGenerator:
- name: task-postgresql-pod-kustomization
options:
disableNameSuffixHash: true
files:
- postgresql-pod_kustomization.yaml=postgresql-pod/kustomization.yaml
- postgresql-pod_postgresql-pod.yaml=postgresql-pod/postgresql-pod.yaml
- postgresql-pod_set-deployment-config_deployment-config.env=postgresql-pod/set-deployment-config/deployment-config.env
- postgresql-pod_set-deployment-config_kustomization.yaml=postgresql-pod/set-deployment-config/kustomization.yaml
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- postgresql-pod.yaml
components:
- set-deployment-config
patches:
- patch: |-
apiVersion: v1
kind: ConfigMap
metadata:
name: ignored
$patch: delete
target:
kind: ConfigMap
---
apiVersion: v1
kind: Service
metadata:
name: postgresql-server-
ownerReferences:
- apiVersion: v1
kind: Pod
blockOwnerDeletion: true
controller: true
name: PARENT_POD_NAME
uid: PARENT_POD_UID
spec:
type: ClusterIP
selector:
owner-uid: PARENT_POD_UID
ports:
- name: pgsql
protocol: TCP
port: 5432
targetPort: 5432
---
apiVersion: v1
kind: Pod
metadata:
name: postgresql-server-
labels:
owner-uid: PARENT_POD_UID
ownerReferences:
- apiVersion: v1
kind: Pod
blockOwnerDeletion: true
controller: true
name: PARENT_POD_NAME
uid: PARENT_POD_UID
spec:
volumes:
- name: postgresql-data
emptyDir: {}
containers:
- name: postgresql
image: bitnami/postgresql:14.1.0-debian-10-r66
#securityContext:
# runAsUser: 1001
# runAsGroup: 1001
env:
- name: POSTGRESQL_PASSWORD
value: CHANGEME
volumeMounts:
- name: postgresql-data
mountPath: /bitnami/postgresql
---
apiVersion: kustomize.config.k8s.io/v1alpha1
kind: Component
configMapGenerator:
- name: deployment-config
options:
disableNameSuffixHash: true
# behavior: merge
envs:
- deployment-config.env
replacements:
- source:
kind: ConfigMap
version: v1
name: deployment-config
fieldPath: data.PARENT_POD_NAME
targets:
- select:
kind: Pod
name: postgresql-server-
fieldPaths:
- metadata.ownerReferences.0.name
- select:
kind: Service
name: postgresql-server-
fieldPaths:
- metadata.ownerReferences.0.name
- source:
kind: ConfigMap
version: v1
name: deployment-config
fieldPath: data.PARENT_POD_UID
targets:
- select:
kind: Pod
name: postgresql-server-
fieldPaths:
- metadata.ownerReferences.0.uid
- metadata.labels.owner-uid
- select:
kind: Service
name: postgresql-server-
fieldPaths:
- metadata.ownerReferences.0.uid
- spec.selector.owner-uid
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: 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: postgresql-pod-kustomization
configMap:
name: 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/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: postgresql-pod-kustomization
mountPath: /srv/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
---