# Copyright 2019 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
#
#     http://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: tekton-pipelines-controller
  namespace: tekton-pipelines
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/instance: default
    app.kubernetes.io/name: controller
    app.kubernetes.io/part-of: tekton-pipelines
    app.kubernetes.io/version: "v0.32.0"
    # tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml
    pipeline.tekton.dev/release: "v0.32.0"
    # labels below are related to istio and should not be used for resource lookup
    version: "v0.32.0"
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/component: controller
      app.kubernetes.io/instance: default
      app.kubernetes.io/name: controller
      app.kubernetes.io/part-of: tekton-pipelines
  template:
    metadata:
      labels:
        # labels below are related to istio and should not be used for resource lookup
        app: tekton-pipelines-controller
        app.kubernetes.io/component: controller
        app.kubernetes.io/instance: default
        app.kubernetes.io/name: controller
        app.kubernetes.io/part-of: tekton-pipelines
        app.kubernetes.io/version: "v0.32.0"
        # tekton.dev/release value replaced with inputs.params.versionTag in pipeline/tekton/publish.yaml
        pipeline.tekton.dev/release: "v0.32.0"
        version: "v0.32.0"
    spec:
      serviceAccountName: tekton-pipelines-controller
      containers:
      - name: tekton-pipelines-controller
        image: gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/controller:v0.32.0@sha256:0e4f92e95c9ae8140ddfc8751bb54cf54e1b00d27aa542c11d5ad8663c5067ae
        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:v0.32.0@sha256:32fec74288f52ede279f091d8bac91d48ff6538fa3290251339b0075c59d0947", "-git-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/git-init:v0.32.0@sha256:fe3310b87b9fad4b5139ac93f0e570c25fb97dcb64a876a5b8eebbc877fc12e8", "-entrypoint-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/entrypoint:v0.32.0@sha256:7f50901900925357460e6c6c985580f0b69c0d316ade75965228adb8b081614e", "-nop-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/nop:v0.32.0@sha256:a8ffddd75b7a7078d5c07d09259d7c5db04614b4c5ba5c43e99b0632034f2479", "-imagedigest-exporter-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/imagedigestexporter:v0.32.0@sha256:2b39f19517523df8a00a366a0d3adb815ca2623fc9c51f05dd290773d5d308c7", "-pr-image", "gcr.io/tekton-releases/github.com/tektoncd/pipeline/cmd/pullrequest-init:v0.32.0@sha256:632b5086dba4d7f30f5b1e77f9e5e551b06c9e897cf2afc93e100b26f9c32e39",
          # 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"]
        ports:
        - name: metrics
          containerPort: 9090
        - name: profiling
          containerPort: 8008
        - name: probes
          containerPort: 8080
        env:
        - name: SYSTEM_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        # These phony AWS credentials are here to work around a bug in the aws go sdk
        # that causes extremely long delays in the execution of tasks after the initial
        # deployment of the Tekton Pipelines controller. See issue https://github.com/tektoncd/pipeline/issues/4087
        # for more information.
        - name: AWS_ACCESS_KEY_ID
          value: foobarbaz
        - name: AWS_SECRET_ACCESS_KEY
          value: foobarbaz
        - name: AWS_DEFAULT_REGION
          value: foobarbaz
        # 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_DEFAULTS_NAME
          value: config-defaults
        - name: CONFIG_LOGGING_NAME
          value: config-logging
        - name: CONFIG_OBSERVABILITY_NAME
          value: config-observability
        - name: CONFIG_ARTIFACT_BUCKET_NAME
          value: config-artifact-bucket
        - name: CONFIG_ARTIFACT_PVC_NAME
          value: config-artifact-pvc
        - name: CONFIG_FEATURE_FLAGS_NAME
          value: feature-flags
        - name: CONFIG_LEADERELECTION_NAME
          value: config-leader-election
        - name: SSL_CERT_FILE
          value: /etc/config-registry-cert/cert
        - name: SSL_CERT_DIR
          value: /etc/ssl/certs
        - name: METRICS_DOMAIN
          value: tekton.dev/pipeline
        volumeMounts:
        - name: config-logging
          mountPath: /etc/config-logging
        - name: config-registry-cert
          mountPath: /etc/config-registry-cert
        livenessProbe:
          httpGet:
            port: probes
            path: /health
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            port: probes
            path: /readiness
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          timeoutSeconds: 5
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - all
          runAsGroup: 65532
          # User 65532 is the distroless nonroot user ID
          runAsUser: 65532
      volumes:
      - name: config-logging
        configMap:
          name: config-logging
      - name: config-registry-cert
        configMap:
          name: config-registry-cert
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/os
                operator: NotIn
                values:
                - windows
