# Copyright 2021 The Tekton Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License

apiVersion: apps/v1
kind: Deployment
metadata:
  name: pipeline-in-pod-controller
  namespace: tekton-pipeline-in-pod
  labels:
    app.kubernetes.io/name: pipeline-in-pod-controller
    app.kubernetes.io/component: pipeline-in-pod-controller
    app.kubernetes.io/instance: default
    app.kubernetes.io/version: devel
    app.kubernetes.io/part-of: tekton-pipeline-in-pod
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: pipeline-in-pod-controller
      app.kubernetes.io/component: pipeline-in-pod-controller
      app.kubernetes.io/instance: default
      app.kubernetes.io/part-of: tekton-pipeline-in-pod
  template:
    metadata:
      annotations:
        cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
      labels:
        app.kubernetes.io/name: pipeline-in-pod-controller
        app.kubernetes.io/component: pipeline-in-pod-controller
        app.kubernetes.io/instance: default
        app.kubernetes.io/version: devel
        app.kubernetes.io/part-of: tekton-pipeline-in-pod
        app: pipeline-in-pod-controller
    spec:
      serviceAccountName: pipeline-in-pod-controller
      containers:
        - name: pipeline-in-pod-controller
          image: ko://github.com/tektoncd/experimental/pipeline-in-pod/cmd/controller
          args: [
            # These images are built on-demand by `ko resolve` and are replaced
            # by image references by digest.
            "-kubeconfig-writer-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/kubeconfigwriter",
            "-git-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init",
            "-entrypoint-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint",
            "-nop-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop",
            "-imagedigest-exporter-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter",
            # This is gcr.io/google.com/cloudsdktool/cloud-sdk:302.0.0-slim
            "-gsutil-image", "gcr.io/google.com/cloudsdktool/cloud-sdk@sha256:27b2c22bf259d9bc1a291e99c63791ba0c27a04d2db0a43241ba0f1f20f4067f",
            # The shell image must be root in order to create directories and copy files to PVCs.
            # gcr.io/distroless/base:debug as of October 21, 2021
            # image shall not contains tag, so it will be supported on a runtime like cri-o
            "-shell-image", "gcr.io/distroless/base@sha256:cfdc553400d41b47fd231b028403469811fcdbc0e69d66ea8030c5a0b5fbac2b",
            # for script mode to work with windows we need a powershell image
            # pinning to nanoserver tag as of July 15 2021
            "-shell-image-win", "mcr.microsoft.com/powershell:nanoserver@sha256:b6d5ff841b78bdf2dfed7550000fd4f3437385b8fa686ec0f010be24777654d6",
          ]
          volumeMounts:
            - name: config-logging
              mountPath: /etc/config-logging
          env:
            - name: SYSTEM_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            # If you are changing these names, you will also need to update
            # the controller's Role in 200-role.yaml to include the new
            # values in the "configmaps" "get" rule.
            - name: CONFIG_LOGGING_NAME
              value: config-logging
            - name: METRICS_DOMAIN
              value: experimental.tekton.dev/pipeline-in-pod
      volumes:
        - name: config-logging
          configMap:
            name: config-logging