apiVersion: apps/v1
kind: Deployment
metadata:
  name: shelly-plug
  labels:
    app.kubernetes.io/controller: main
    app.kubernetes.io/instance: shelly-plug
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: shelly-plug
    helm.sh/chart: shelly-plug-4.5.0
  namespace: shelly-plug
spec:
  revisionHistoryLimit: 3
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/controller: main
      app.kubernetes.io/name: shelly-plug
      app.kubernetes.io/instance: shelly-plug
  template:
    metadata:
      labels:
        app.kubernetes.io/controller: main
        app.kubernetes.io/instance: shelly-plug
        app.kubernetes.io/name: shelly-plug
    spec:
      enableServiceLinks: false
      serviceAccountName: default
      automountServiceAccountToken: true
      hostIPC: false
      hostNetwork: false
      hostPID: false
      dnsPolicy: ClusterFirst
      initContainers:
        - command:
            - /bin/sh
            - -ec
            - |
              cd /var/www/html
              if [ -d ".git" ]; then
                echo "Git repository found. Pulling latest changes..."
                git pull
              else
                echo "Not a git repository. Initializing ..."
                git init
                git remote add origin https://github.com/geerlingguy/shelly-plug-prometheus.git
                git fetch origin
                git checkout origin/master -ft
              fi
          image: alpine/git:latest
          imagePullPolicy: IfNotPresent
          name: init-fetch-repo
          resources:
            requests:
              cpu: 10m
              memory: 128Mi
          securityContext:
            runAsUser: 0
          volumeMounts:
            - mountPath: /var/www/html
              name: script
      containers:
        - env:
            - name: SHELLY_HOSTNAME
              value: it05sp.alexlebens.net
            - name: SHELLY_GENERATION
              value: "2"
          envFrom:
            - secretRef:
                name: shelly-plug-config-secret
          image: php:8.5.1-apache-bookworm
          imagePullPolicy: IfNotPresent
          name: main
          resources:
            requests:
              cpu: 10m
              memory: 64Mi
          volumeMounts:
            - mountPath: /var/www/html
              name: script
      volumes:
        - name: script
          persistentVolumeClaim:
            claimName: shelly-plug
