apiVersion: v1
kind: Service
metadata:
  name: fe-static-sync
  namespace: frontend-static
  labels:
    app: fe-static-sync
    service: fe-static-sync
spec:
  clusterIP: None
  ports:
  - port: 9080
    name: http-fe-static-sync
  selector:
    app: fe-static-sync
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ovh-vars
  namespace: frontend-static
data:
  OVH_OBJECT_STORAGE: "OvhObjectStorage:prod-static-fe"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rclone-config
  namespace: frontend-static
data:
  rclone.conf: |
    # Copy the config entry below in your rclone configuration file.
    # Use 'rclone config file' to find which configuration file rclone uses.
    # You can also use 'rclone --config <file>' directly.
    [OvhObjectStorage]
    type = swift
    env_auth = false
    auth_version = 3
    auth = https://auth.cloud.ovh.net/v3/
    endpoint_type = public
    tenant_domain = default
    tenant = 3302683673846688
    domain = default
    user = user-7k4m5zkN3DWk
    key = 8Gcr445Fd4thZWKMgT8MD33cFag4dZvf
    region = SBG
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rclone-config-init
  namespace: frontend-static
data:
  entrypoint.sh: |-
    #!/bin/sh
    rclone sync -v "OvhObjectStorage:prod-static-fe" "/data"
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fe-static-sync
  namespace: frontend-static
spec:
  selector:
    matchLabels:
      name: fe-static-sync
  template:
    metadata:
      labels:
        name: fe-static-sync
        app: fe-static-sync
    spec:
      initContainers:
      - image: rclone/rclone
        command:
        - /entrypoint.sh
        imagePullPolicy: IfNotPresent
        volumeMounts:
          - name: sync-path
            mountPath: "/data"
          - name: config
            mountPath: "/config/rclone"
            readOnly: true
          - name: rclone-config-init
            mountPath: /entrypoint.sh
            readOnly: true
            subPath: entrypoint.sh
        name: static-fe-rclone-init
      containers:
      - image: docker.adaoncloud.com/frontend/static-sync:test
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        env:
        - name: ADA_KAFKA_BROKER
          value: "ada-cluster-kafka-bootstrap.ada-kafka.svc.cluster.local:9092"
        - name: ADA_KAFKA_TOPIC
          value: "fe-static-sync"
        - name: ADA_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: ADA_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: ADA_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: ADA_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: OVH_OBJECT_STORAGE
          valueFrom:
            configMapKeyRef:
              name: ovh-vars
              key: OVH_OBJECT_STORAGE
        - name: OVH_RCLONE_CONFIG
          value: "/rclone/rclone.conf"
        volumeMounts:
          - name: sync-path
            mountPath: "/data"
          - name: config
            mountPath: "/rclone"
            readOnly: true
        name: static-fe-rclone
      imagePullSecrets:
      - name: ada-registry
      volumes:
        - name: config
          configMap:
            name: rclone-config
        - name: sync-path
          hostPath:
            path: "/var/www/html/static-fe"
        - name: rclone-config-init
          configMap:
            defaultMode: 0700
            name: rclone-config-init