apiVersion: v1
kind: Service
metadata:
  name: <<appenv>>fe-static
  namespace: <<appenv>>frontend-static
  labels:
    app: <<appenv>>fe-static
    service: <<appenv>>fe-static
spec:
  ports:
  - port: 80
    name: http-<<appenv>>fe-static
  - port: 9080
    name: http-<<appenv>>fe-static-sync
  clusterIP: None
  selector:
    app: <<appenv>>fe-static
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: <<appenv>>fe-static-sync-role
  namespace: <<appenv>>frontend-static
rules:
- apiGroups: [""]
  resources: ["endpoints"]
  verbs: ["get", "watch", "list", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: <<appenv>>fe-static-sync-role-bd
  namespace: <<appenv>>frontend-static
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: <<appenv>>fe-static-sync-role
subjects:
- kind: ServiceAccount
  name: default
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: ovh-vars
  namespace: <<appenv>>frontend-static
data:
  OVH_OBJECT_STORAGE: "<<appenv>>OvhObjectStorage:<<appenv>>static-fe"
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: <<appenv>>rclone-config
  namespace: <<appenv>>frontend-static
data:
  rclone.conf: |
    [sta-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-ZDGwW7YxYmNw
    key = j7PASnJDRMzw8GsnaQspKqM2mGH7qCBS
    region = SBG

    [OvhObjectStorage]
    type = swift
    env_auth = false
    auth_version = 3
    auth = https://auth.cloud.ovh.net/v3/
    endpoint_type = public
    tenant_domain = default
    tenant = 1412618361272247
    domain = default
    user = user-fv7ugkuxqDvd
    key = YhFHy4hKuzFY6WXgW6mVhZqZRXphTHdk
    region = SBG
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: <<appenv>>frontend-static
  namespace: <<appenv>>frontend-static
spec:
  replicas: 1
  serviceName: "<<appenv>>fe-static"
  selector:
    matchLabels:
      app: <<appenv>>fe-static
  template:
    metadata:
      name: <<appenv>>fe-static
      labels:
        app: <<appenv>>fe-static
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - <<appenv>>fe-static
            topologyKey: "kubernetes.io/hostname"
      containers:
      - name: varnish
        image: varnish:old-alpine
        volumeMounts:
        - name: varnish-config
          mountPath: /etc/varnish
        ports:
        - containerPort: 80
        imagePullPolicy: Always
      - name: apache
        image: docker.adaoncloud.com/frontend/<<appenv>>static:<<imagetag>>
        volumeMounts:
        - mountPath: "/usr/local/apache2/htdocs/www"
          name: www-storage
        ports:
        - containerPort: 8080
          name: http
        env:
        - name: ADA_APP_ENV
          value: <<appenv>>
        imagePullPolicy: Always
      - name: sync
        image: docker.adaoncloud.com/frontend/<<appenv>>static-sync:<<imagetag>>
        imagePullPolicy: Always
        ports:
        - containerPort: 9080
        volumeMounts:
        - name: www-storage
          mountPath: "/data"
        - name: config
          mountPath: "root/.config/rclone"
          readOnly: true
        env:
        - name: ADA_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: ADA_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: ADA_SERVICE_NAME
          value: <<appenv>>fe-static
        - name: ADA_APP_ENV
          value: <<appenv>>
        - name: OVH_OBJECT_STORAGE
          valueFrom:
            configMapKeyRef:
              name: ovh-vars
              key: OVH_OBJECT_STORAGE
      restartPolicy: Always
      hostAliases:
      - ip: "127.0.0.1"
        hostnames:
        - "clicnew.internal"
        - "storynew.internal"
      imagePullSecrets:
        - name: ada-registry
      volumes:
      - name: varnish-config
        configMap:
          name: <<appenv>>fe-varnish-config
      - name: config
        configMap:
          name: <<appenv>>rclone-config
  volumeClaimTemplates:
  - metadata:
      name: www-storage
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "csi-cinder-high-speed"
      resources:
        requests:
          storage: 10Gi