### !CAUTION! ###
# Most cloud providers have a limit of 16 KB regarding the user-data that may be sent during VM creation.
# The result of this operating system config is exactly the user-data that will be sent to the providers.
# We must not exceed the 16 KB, so be careful when extending/changing anything in here.
### !CAUTION! ###
---
apiVersion: extensions.gardener.cloud/v1alpha1
kind: OperatingSystemConfig
metadata:
  name: {{ required "secretName is required" .Values.secretName }}-downloader
  namespace: {{ .Release.Namespace }}
  annotations:
    gardener.cloud/operation: reconcile
spec:
  type: {{ required "type is required" .Values.type }}
  purpose: {{ required "purpose is required" .Values.purpose }}
  units:
  - name: cloud-config-downloader.service
    command: start
    enable: true
    content: |
      [Unit]
      Description=Downloads the actual cloud config from the Shoot API server and executes it
      After=docker.service docker.socket
      Wants=docker.socket
      [Service]
      Restart=always
      RestartSec=30
      EnvironmentFile=/etc/environment
      ExecStart=/var/lib/cloud-config-downloader/download-cloud-config.sh
      [Install]
      WantedBy=multi-user.target
  files:
  - path: /var/lib/cloud-config-downloader/credentials/server
    permissions: 0644
    content:
      inline:
        encoding: b64
        data: {{ .Values.server | b64enc }}
  - path: /var/lib/cloud-config-downloader/credentials/ca.crt
    permissions: 0644
    content:
      secretRef:
        name: cloud-config-downloader
        dataKey: ca.crt
  - path: /var/lib/cloud-config-downloader/credentials/client.crt
    permissions: 0644
    content:
      secretRef:
        name: cloud-config-downloader
        dataKey: cloud-config-downloader.crt
  - path: /var/lib/cloud-config-downloader/credentials/client.key
    permissions: 0644
    content:
      secretRef:
        name: cloud-config-downloader
        dataKey: cloud-config-downloader.key
  - path: /var/lib/cloud-config-downloader/download-cloud-config.sh
    permissions: 0744
    content:
      inline:
        encoding: b64
        data: {{ include "seed-operatingsystemconfig.downloader.download-script" . | b64enc }}
