{{- if index .Values "rancherTurtles" "features" "day2operations" "enabled" }}
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    control-plane: controller-manager
    turtles-capi.cattle.io: day2-operations
  name: rancher-turtles-day2-operations-controller-manager
  namespace: '{{ .Values.rancherTurtles.namespace }}'
spec:
  replicas: 1
  selector:
    matchLabels:
      control-plane: controller-manager
      turtles-capi.cattle.io: day2-operations
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: manager
      labels:
        control-plane: controller-manager
        turtles-capi.cattle.io: day2-operations
    spec:
      containers:
      - args:
        - --leader-elect
        - --feature-gates=etcd-backup-restore={{ .Values.rancherTurtles.features.day2operations.etcdBackupRestore.enabled }}
        command:
        - ./turtles-day2-operations
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_UID
          valueFrom:
            fieldRef:
              fieldPath: metadata.uid
        {{- if (contains "sha256:" .Values.rancherTurtles.features.day2operations.imageVersion) }}
        image: '{{ .Values.rancherTurtles.features.day2operations.image }}@{{ .Values.rancherTurtles.features.day2operations.imageVersion }}'
        {{- else }}
        image: '{{ .Values.rancherTurtles.features.day2operations.image }}:{{ .Values.rancherTurtles.features.day2operations.imageVersion }}'
        {{- end }}
        imagePullPolicy: '{{ .Values.rancherTurtles.features.day2operations.imagePullPolicy }}'
        livenessProbe:
          httpGet:
            path: /healthz
            port: 9440
          initialDelaySeconds: 15
          periodSeconds: 20
        name: manager
        ports:
        - containerPort: 9443
          name: webhook-server
          protocol: TCP
        readinessProbe:
          httpGet:
            path: /readyz
            port: 9440
          initialDelaySeconds: 5
          periodSeconds: 10
        resources:
          limits:
            cpu: 500m
            memory: 128Mi
          requests:
            cpu: 10m
            memory: 64Mi
        volumeMounts:
        {{- if .Values.rancherTurtles.features.day2operations.etcdBackupRestore.enabled }}
        - mountPath: /tmp/k8s-webhook-server/serving-certs
          name: cert
          readOnly: true
        {{- end }}
      serviceAccountName: rancher-turtles-day2-operations-manager
      terminationGracePeriodSeconds: 10
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
      - effect: NoSchedule
        key: node-role.kubernetes.io/control-plane
      volumes:
      {{- if .Values.rancherTurtles.features.day2operations.etcdBackupRestore.enabled }}
      - name: cert
        secret:
          secretName: rancher-turtles-day2-operations-webhook-service-cert
      {{- end }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app.kubernetes.io/component: rbac
    app.kubernetes.io/created-by: rancher-turtles
    app.kubernetes.io/instance: controller-manager-sa
    app.kubernetes.io/managed-by: kustomize
    app.kubernetes.io/name: serviceaccount
    app.kubernetes.io/part-of: rancher-turtles
    turtles-capi.cattle.io: day2-operations
  name: rancher-turtles-day2-operations-manager
  namespace: '{{ .Values.rancherTurtles.namespace }}'
{{- end }}