# SPDX-FileCopyrightText: 2021 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

# Sample deployment file, used to run Machine Controller Manager on your cluster

apiVersion: apps/v1 # Version may change based on kubernetes version
kind: Deployment
metadata:
  name: machine-controller-manager
spec:
  replicas: 1
  selector:
    matchLabels:
      role: machine-controller-manager
  template:
    metadata:
      labels:
        role: machine-controller-manager
    spec:
      containers:
      - name: machine-controller-manager
        image: eu.gcr.io/gardener-project/gardener/machine-controller-manager:v0.39.0
        imagePullPolicy: Always
        command:
          - ./machine-controller-manager
          - --target-kubeconfig=/var/lib/machine-controller-manager/kubeconfig  #$(TARGET_KUBECONFIG) Mandatory Parameter - Filepath to the target cluster's kubeconfig where node objects are expected to join.
          - --control-kubeconfig=inClusterConfig #$(CONTROL_KUBECONFIG) Optional Parameter - Default value is same as target-kubeconfig - Filepath to the control cluster's kubeconfig where machine objects would be created. Optionally you could also use "inClusterConfig" when pod is running inside control kubeconfig.
          # - --namespace=$(CONTROL_NAMESPACE) # Optional Parameter - Default value for namespace is 'default' - The control namespace where the controller watches for it's machine objects.
          - --safety-up=2 # Optional Parameter - Default value 2 - The number of excess machine objects permitted for any machineSet/machineDeployment beyond its expected number of replicas based on desired and max-surge, we call this the upper-limit. When this upper-limit is reached, the objects are frozen until the number of objects reduce. upper-limit = desired + maxSurge (if applicable) + safetyUp.
          - --safety-down=1 # Optional Parameter - Default value 1 - Upper-limit minus safety-down value gives the lower-limit. This is the limits below which any temporarily frozen machineSet/machineDeployment object is unfrozen. lower-limit = desired + maxSurge (if applicable) + safetyUp - safetyDown.
          - --machine-safety-overshooting-period=1m # Optional Parameter - Default value 1min - Time period (in time) used to poll for overshooting of machine objects backing a machineSet by safety controller.
          - --v=3
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 10258
            scheme: HTTP
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        volumeMounts:
        - mountPath: /var/lib/machine-controller-manager
          name: machine-controller-manager
          readOnly: true
        resources: {}
      - command:
        - ./machine-controller
        - --control-kubeconfig=inClusterConfig # $(TARGET_KUBECONFIG) Mandatory Parameter - Filepath to the target cluster's kubeconfig where node objects are expected to join.
        - --target-kubeconfig=/var/lib/machine-controller-manager/kubeconfig # $(CONTROL_KUBECONFIG) Optional Parameter - Default value is same as target-kubeconfig - Filepath to the control cluster's kubeconfig where machine objects would be created. Optionally you could also use "inClusterConfig" when pod is running inside control kubeconfig.
        # - --namespace=$(CONTROL_NAMESPACE) # Optional Parameter - Default value for namespace is 'default' - The control namespace where the controller watches for it's machine objects.
        - --machine-creation-timeout=20m # Optional Parameter - Timeout (in time) used while creation of machine before retrying by recreation.
        - --machine-drain-timeout=5m # Optional Parameter - Timeout (in time) used while draining of machine before deletion, beyond which MCM forcefully deletes machine.
        - --machine-health-timeout=10m  # Optional Parameter - Default value 10mins - Timeout (in time) used while joining (during creation) or re-joining (in case of temporary health issues) of machine before it is declared as failed.
        - --machine-safety-orphan-vms-period=30m # Optional Parameter - Default value 30mins - Time period (in time) used to poll for orphan VMs by safety controller.
        - --node-conditions=ReadonlyFilesystem,KernelDeadlock,DiskPressure # List of comma-separated/case-sensitive node-conditions which when set to True will change machine to a failed state after MachineHealthTimeout duration. It may further be replaced with a new machine if the machine is backed by a machine-set object.
        - --v=3
        image: eu.gcr.io/gardener-project/gardener/machine-controller-manager-provider-aws:v0.7.0
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 10259
            scheme: HTTP
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 5
        name: machine-controller
        ports:
        - containerPort: 10259
          name: metrics
          protocol: TCP
        resources:
          limits:
            cpu: "3"
            memory: 3000Mi
          requests:
            cpu: 50m
            memory: 64Mi
        volumeMounts:
        - mountPath: /var/lib/machine-controller-manager
          name: machine-controller-manager
          readOnly: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      securityContext: {}
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      volumes:
      - name: machine-controller-manager
        secret:
          defaultMode: 420
          secretName: machine-controller-manager