From 2ca8b6486bdd18e697105c4b2181b92e5aa172d0 Mon Sep 17 00:00:00 2001 From: brupje Date: Sat, 17 Oct 2026 17:00:28 +0200 Subject: [PATCH] feat: add k8s manifests and gitops sync workflow for smart-home --- .gitea/workflows/build-and-deploy.yaml | 76 ++++++++++++++++++++++++++ k8s/deployment.yaml | 58 ++++++++++++++++++++ k8s/kustomization.yaml | 10 ++++ k8s/namespace.yaml | 6 ++ k8s/pvc.yaml | 15 +++++ k8s/service.yaml | 17 ++++++ 6 files changed, 182 insertions(+) create mode 100644 .gitea/workflows/build-and-deploy.yaml create mode 100644 k8s/deployment.yaml create mode 100644 k8s/kustomization.yaml create mode 100644 k8s/namespace.yaml create mode 100644 k8s/pvc.yaml create mode 100644 k8s/service.yaml diff --git a/.gitea/workflows/build-and-deploy.yaml b/.gitea/workflows/build-and-deploy.yaml new file mode 100644 index 0000000..0140de6 --- /dev/null +++ b/.gitea/workflows/build-and-deploy.yaml @@ -0,0 +1,76 @@ +name: Sync Smart Home Manifests to GitOps + +on: + push: + branches: + - main + - master + paths: + - 'k8s/**' + - '.gitea/workflows/**' + +permissions: + contents: read + +env: + GITOPS_REPO: git.bnhmeijer.nl/bart/k8s-infra-vmserver.git + GITOPS_PATH: workloads/smart-home + ARGOCD_SERVER: ${{ vars.ARGOCD_SERVER || 'argocd.bnhmeijer.nl' }} + +jobs: + sync-to-gitops: + name: Sync Manifests to GitOps Repo + runs-on: ubuntu-latest + steps: + - name: Checkout smart-home repository + uses: actions/checkout@v4 + + - name: Sync manifests to k8s-infra-vmserver + env: + TOKEN: ${{ secrets.GITOPS_PAT || secrets.CI_TOKEN }} + GITEA_SHA: ${{ gitea.sha }} + run: | + git config --global user.name "Gitea Actions Bot" + git config --global user.email "actions@git.bnhmeijer.nl" + + echo "Cloning GitOps repository..." + git clone https://${TOKEN}@${GITOPS_REPO} gitops-repo + + echo "Syncing k8s manifests into ${GITOPS_PATH}..." + mkdir -p "gitops-repo/${GITOPS_PATH}" + rm -rf "gitops-repo/${GITOPS_PATH}"/* + cp -r k8s/* "gitops-repo/${GITOPS_PATH}/" + + cd gitops-repo + if [ -n "$(git status --porcelain)" ]; then + git add . + git commit -m "ci(smart-home): sync manifests (${GITEA_SHA::7})" + git push origin main + echo "Successfully pushed updated manifests to k8s-infra-vmserver!" + else + echo "No manifest changes detected in GitOps repository." + fi + + - name: Trigger ArgoCD Sync for smart-home + env: + ARGOCD_SERVER: ${{ env.ARGOCD_SERVER }} + ARGOCD_TOKEN: ${{ secrets.ARGOCD_TOKEN }} + run: | + if [ -n "$ARGOCD_TOKEN" ]; then + SERVER_URL="${ARGOCD_SERVER}" + if [[ ! "$SERVER_URL" =~ ^https?:// ]]; then + SERVER_URL="https://${SERVER_URL}" + fi + + echo "Triggering ArgoCD sync for application smart-home on $SERVER_URL..." + RESPONSE=$(curl -s -S -k -w "\nHTTP_STATUS:%{http_code}" -X POST \ + -H "Authorization: Bearer $ARGOCD_TOKEN" \ + -H "Content-Type: application/json" \ + "${SERVER_URL}/api/v1/applications/smart-home/sync" || true) + + HTTP_STATUS=$(echo "$RESPONSE" | grep "HTTP_STATUS:" | cut -d':' -f2) + BODY=$(echo "$RESPONSE" | grep -v "HTTP_STATUS:") + echo "ArgoCD API Response (HTTP $HTTP_STATUS): $BODY" + else + echo "ARGOCD_TOKEN secret is not set, skipping ArgoCD sync trigger (ArgoCD auto-sync will pick up changes)." + fi diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..276a47a --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: homeassistant + namespace: smart-home + labels: + app.kubernetes.io/name: homeassistant + app.kubernetes.io/part-of: smart-home +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: homeassistant + template: + metadata: + labels: + app: homeassistant + spec: + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + nodeSelector: + kubernetes.io/hostname: vmserver + containers: + - name: homeassistant + image: ghcr.io/home-assistant/home-assistant:2026.9.4 + env: + - name: TZ + value: "Europe/Amsterdam" + resources: + requests: + cpu: 250m + memory: 512Mi + limits: + cpu: 2000m + memory: 4Gi + volumeMounts: + - name: config + mountPath: /config + livenessProbe: + httpGet: + path: /manifest.json + port: 8123 + initialDelaySeconds: 60 + periodSeconds: 20 + timeoutSeconds: 5 + readinessProbe: + httpGet: + path: /manifest.json + port: 8123 + initialDelaySeconds: 30 + periodSeconds: 10 + timeoutSeconds: 5 + volumes: + - name: config + persistentVolumeClaim: + claimName: homeassistant-config diff --git a/k8s/kustomization.yaml b/k8s/kustomization.yaml new file mode 100644 index 0000000..05ecbc5 --- /dev/null +++ b/k8s/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +namespace: smart-home + +resources: + - namespace.yaml + - pvc.yaml + - service.yaml + - deployment.yaml diff --git a/k8s/namespace.yaml b/k8s/namespace.yaml new file mode 100644 index 0000000..3497160 --- /dev/null +++ b/k8s/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: smart-home + labels: + app.kubernetes.io/name: smart-home diff --git a/k8s/pvc.yaml b/k8s/pvc.yaml new file mode 100644 index 0000000..22ae5f4 --- /dev/null +++ b/k8s/pvc.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: homeassistant-config + namespace: smart-home + labels: + app.kubernetes.io/name: homeassistant + app.kubernetes.io/part-of: smart-home +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-path + resources: + requests: + storage: 20Gi diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..f80efab --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: homeassistant + namespace: smart-home + labels: + app.kubernetes.io/name: homeassistant + app.kubernetes.io/part-of: smart-home +spec: + type: ClusterIP + ports: + - port: 8123 + targetPort: 8123 + protocol: TCP + name: http + selector: + app: homeassistant