# Create the actual deployment
apiVersion: apps/v1
kind: Deployment
metadata:
  name: flyteadmin
  namespace: flyte
  labels:
    app: flyteadmin
spec:
  replicas: 1
  selector:
    matchLabels:
      app: flyteadmin
  template:
    metadata:
      labels:
        app: flyteadmin
        app.kubernetes.io/name: flyteadmin
        app.kubernetes.io/version: 0.3.29
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "10254"
        prometheus.io/path: "/metrics"
    spec:
      serviceAccountName: flyteadmin
      volumes:
      - name: shared-data
        emptyDir: {}
      - name: config-volume
        configMap:
          name: flyte-admin-config
      - name: resource-templates 
        configMap:
          name: clusterresource-template 
      - name: db-pass
        secret:
          secretName: db-pass
      initContainers:
      - name: run-migrations
        image: flyteadmin:v0.3.29
        imagePullPolicy: IfNotPresent
        command: ["flyteadmin", "--logtostderr", "--config", "/etc/flyte/config/*.yaml", "migrate", "run"]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/flyte/config
        - name: db-pass
          mountPath: /etc/db
      # Optional, These just seed the project - TODO move them to only
      - name: seed-projects
        image: flyteadmin:v0.3.29
        imagePullPolicy: IfNotPresent
        command: ["flyteadmin", "--logtostderr", "--config", "/etc/flyte/config/*.yaml",
                  "migrate", "seed-projects", "flytesnacks", "flytetester", "flyteexamples"]
        volumeMounts:
        - name: config-volume
          mountPath: /etc/flyte/config
        - name: db-pass
          mountPath: /etc/db
      - name: sync-cluster-resources
        image: flyteadmin:v0.3.29
        imagePullPolicy: IfNotPresent
        command: ["flyteadmin", "--logtostderr", "--config", "/etc/flyte/config/*.yaml", "clusterresource", "sync"]
        volumeMounts:
        - name: resource-templates 
          mountPath: /etc/flyte/clusterresource/templates
        - name: config-volume
          mountPath: /etc/flyte/config
        - name: db-pass
          mountPath: /etc/db
      containers:
      - name: flyteadmin
        image: flyteadmin:v0.3.29
        imagePullPolicy: IfNotPresent
        command: ["flyteadmin", "--logtostderr", "--config", "/etc/flyte/config/*.yaml", "serve"]
        ports:
        - containerPort: 8088
        - containerPort: 8089
        volumeMounts:
        - name: shared-data
          mountPath: /srv/flyte
        - name: config-volume
          mountPath: /etc/flyte/config
        - name: db-pass
          mountPath: /etc/db
      - name: redoc
        image: docker.io/redocly/redoc
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8087
        resources:
          limits:
            memory: "200Mi"
            cpu: "0.1"
        command:
        - sh
        - -c
        - ln -s /usr/share/nginx/html /usr/share/nginx/html/openapi && sh /usr/local/bin/docker-run.sh
        env:
        - name: PAGE_TITLE
          value: "Flyte Admin OpenAPI"
        - name: SPEC_URL
          value: "/api/v1/openapi"
        - name: PORT
          value: "8087"
