softplayer-helmfile/charts/tekton-pipelines/templates/tasks/bootstrap-k3s.yml

112 lines
3.7 KiB
YAML
Raw Permalink Normal View History

2024-04-02 17:15:40 +00:00
---
apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
name: bootstrap-k3s
namespace: {{ .Values.pipelineNamespace }}
labels:
{{- include "tekton-pipelines.labels" . | nindent 4 }}
spec:
params:
- name: namespace
type: string
- name: environment
type: string
steps:
- name: get-ssh-key-and-inventory
image: alpine/k8s:1.29.2
script: |-
#!/bin/sh
kubectl get secret "$(params.environment)"-ssh \
--namespace "$(params.namespace)" -o yaml \
| yq '.data.ssh_key' \
| base64 -d > /tmp/outputs/ssh_key
kubectl get secret "$(params.environment)"-ssh \
--namespace "$(params.namespace)" -o yaml \
| yq '.data."ssh_key.pub"' \
| base64 -d > /tmp/outputs/ssh_key.pub
kubectl get secret "$(params.environment)"-inventory \
--namespace "$(params.namespace)" -o yaml \
| yq '.data."inventory.yaml"' \
| base64 -d > /tmp/outputs/inventory.yaml
chmod 0600 /tmp/outputs/ssh_key
chmod 0600 /tmp/outputs/ssh_key.pub
2024-04-06 17:56:56 +00:00
- name: annonate-an-env-cm
image: alpine/k8s:1.29.2
script: |-
#!/bin/sh
kubectl annotate --overwrite configmap \
"$(params.environment)" \
--namespace "$(params.namespace)" \
"softplayer.net/status=servers-configuration"
2024-04-02 17:15:40 +00:00
- name: prepare-servers
image: git.badhouseplants.net/softplayer/softplayer-coskgne:latest
env:
- name: SP_ENV
value: $(params.environment)
- name: SP_CUSTOMER
value: $(params.namespace)
- name: ANSIBLE_INVENTORY
value: /tmp/outputs/inventory.yaml
- name: ANSIBE_PRIVATE_KEY_FILE
value: /tmp/outputs/ssh_key
- name: ANSIBLE_HOST_KEY_CHECKING
value: "false"
script: |
#!/bin/sh
ansible-playbook /src/playbooks/systems/system-bootstrap/playbook.yml
2024-05-08 15:38:52 +00:00
2024-04-02 17:15:40 +00:00
- name: prepare-k3s
env:
- name: SP_ENV
value: $(params.environment)
- name: SP_CUSTOMER
value: $(params.namespace)
- name: ANSIBLE_INVENTORY
value: /tmp/outputs/inventory.yaml
- name: ANSIBE_PRIVATE_KEY_FILE
value: /tmp/outputs/ssh_key
- name: ANSIBLE_HOST_KEY_CHECKING
value: "false"
image: git.badhouseplants.net/softplayer/softplayer-coskgne:latest
script: |-
#!/bin/sh
ansible-playbook /src/playbooks/systems/k3s-bootstrap/playbook.yml
2024-05-08 15:38:52 +00:00
- name: get-config
image: git.badhouseplants.net/softplayer/softplayer-coskgne:latest
2024-04-02 17:15:40 +00:00
env:
- name: SP_ENV
value: $(params.environment)
- name: SP_CUSTOMER
value: $(params.namespace)
- name: ANSIBLE_INVENTORY
value: /tmp/outputs/inventory.yaml
- name: ANSIBE_PRIVATE_KEY_FILE
value: /tmp/outputs/ssh_key
- name: ANSIBLE_HOST_KEY_CHECKING
value: "false"
2024-05-08 15:38:52 +00:00
script: |
2024-04-02 17:15:40 +00:00
#!/bin/sh
2024-05-08 15:38:52 +00:00
ansible-playbook /src/playbooks/other/k3s-save-config/playbook.yml
export SERVICE_ENTRYPOINT=$(cat /tmp/outputs/inventory.yaml | yq '.servers.vars.service_entrypoint')
sed -i "s/127.0.0.1/${SERVICE_ENTRYPOINT}/" /tmp/outputs/config
2024-04-02 17:15:40 +00:00
- name: save-kubeconfig
image: alpine/k8s:1.29.2
script: |-
#!/bin/sh
kubectl delete secret \
"$(params.environment)"-config \
--namespace "$(params.namespace)"
kubectl create secret generic \
"$(params.environment)"-config \
--namespace "$(params.namespace)" \
2024-05-08 15:38:52 +00:00
--from-file=value=/tmp/outputs/config
2024-04-02 17:15:40 +00:00
workspaces:
2024-05-08 15:38:52 +00:00
- name: outputs
2024-04-02 17:15:40 +00:00
description: A folder to store outputs
optional: false
mountPath: /tmp/outputs