#
#  Copyright (c) 2021 Red Hat, Inc.
#    This program and the accompanying materials are made
#    available under the terms of the Eclipse Public License 2.0
#    which is available at https://www.eclipse.org/legal/epl-2.0/
#
#  SPDX-License-Identifier: EPL-2.0
#
#  Contributors:
#    Red Hat, Inc. - initial API and implementation

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: devworkspace-controller
    app.kubernetes.io/part-of: devworkspace-operator
  name: devworkspace-controller-manager
  namespace: devworkspace-controller
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: devworkspace-controller
      app.kubernetes.io/part-of: devworkspace-operator
  template:
    metadata:
      labels:
        app.kubernetes.io/name: devworkspace-controller
        app.kubernetes.io/part-of: devworkspace-operator
    spec:
      containers:
        - args:
            - /usr/local/bin/devworkspace-controller
            - --enable-leader-election
            - --metrics-addr=127.0.0.1:8080
          env:
            - name: CONTROLLER_SERVICE_ACCOUNT_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.serviceAccountName
            - name: MAX_CONCURRENT_RECONCILES
              value: '5'
            - name: OPERATOR_NAME
              value: devworkspace-operator
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: RELATED_IMAGE_devworkspace_webhook_server
              value: registry.redhat.io/codeready-workspaces/devworkspace-controller-rhel8:2.11
            - name: RELATED_IMAGE_kube_rbac_proxy
              value: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.8
            - name: RELATED_IMAGE_plugin_redhat_developer_web_terminal_4_5_0
              value: registry.redhat.io/codeready-workspaces/machineexec-rhel8:2.11
            - name: RELATED_IMAGE_pvc_cleanup_job
              value: registry.access.redhat.com/ubi8-micro:8.4-81
            - name: WATCH_NAMESPACE
              value: ''
            - name: WEBHOOKS_SERVER_CPU_LIMIT
              value: 200m
            - name: WEBHOOKS_SERVER_CPU_REQUEST
              value: 100m
            - name: WEBHOOKS_SERVER_MEMORY_LIMIT
              value: 300Mi
            - name: WEBHOOKS_SERVER_MEMORY_REQUEST
              value: 20Mi
            - name: WEBHOOK_SECRET_NAME
              value: devworkspace-webhookserver-tls
          image: registry.redhat.io/codeready-workspaces/devworkspace-controller-rhel8:2.11
          imagePullPolicy: Always
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /healthz
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 15
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          name: devworkspace-controller
          ports:
            - containerPort: 9443
              name: conversion
              protocol: TCP
            - containerPort: 6789
              name: liveness-port
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /readyz
              port: liveness-port
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 1000m
              memory: 1Gi
            requests:
              cpu: 250m
              memory: 100Mi
          volumeMounts:
            - mountPath: /tmp/k8s-webhook-server/serving-certs
              name: webhook-tls-certs
              readOnly: true
        - args:
            - --secure-listen-address=0.0.0.0:8443
            - --upstream=http://127.0.0.1:8080/
            - --logtostderr=true
            - --v=10
          image: registry.redhat.io/openshift4/ose-kube-rbac-proxy:v4.8
          name: kube-rbac-proxy
          ports:
            - containerPort: 8443
              name: metrics
      serviceAccountName: devworkspace-controller-serviceaccount
      terminationGracePeriodSeconds: 10
      volumes:
        - name: webhook-tls-certs
          secret:
            defaultMode: 420
            secretName: devworkspace-webhooks-tls
