{{- if .Values.controller.enabled }}
{{- if .Values.controller.useBasicNames }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: controller-manager
  namespace: system
  labels:
    control-plane: controller-manager
    app.kubernetes.io/name: controller
    app.kubernetes.io/managed-by: kustomize
spec:
  selector:
    matchLabels:
      control-plane: controller-manager
  replicas: 1
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: manager
      labels:
        control-plane: controller-manager
    spec:
      securityContext:
        runAsNonRoot: true
        seccompProfile:
          type: RuntimeDefault
      containers:
      - command:
        - /manager
        args:
          - --leader-elect
          - --health-probe-bind-address=:8081
        image: ghcr.io/kubeflow/model-registry/controller:latest
        name: manager
        env:
          - name: NAMESPACE_LABEL
            value: ""
          - name: NAME_LABEL
            value: ""
          - name: URL_ANNOTATION
            value: ""
          - name: INFERENCE_SERVICE_ID_LABEL
            value: ""
          - name: MODEL_VERSION_ID_LABEL
            value: ""
          - name: REGISTERED_MODEL_ID_LABEL
            value: ""
          - name: FINALIZER
            value: ""
          - name: SERVICE_ANNOTATION
            value: ""
          - name: REGISTRIES_NAMESPACE
            value: ""
          - name: SKIP_TLS_VERIFY
            value: "false"
          - name: INFERENCE_SERVICE_CONTROLLER
            value: ""
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - "ALL"
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
        resources:
          limits:
            memory: 128Mi
          requests:
            cpu: 10m
            memory: 64Mi
      serviceAccountName: controller-manager
      terminationGracePeriodSeconds: 10
{{- else if .Values.controller.useSimpleNames }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: controller-controller-manager
  namespace: kubeflow
  labels:
    control-plane: controller-manager
    app.kubernetes.io/name: controller
    app.kubernetes.io/managed-by: kustomize
spec:
  selector:
    matchLabels:
      control-plane: controller-manager
  replicas: 1
  template:
    metadata:
      annotations:
        kubectl.kubernetes.io/default-container: manager
      labels:
        control-plane: controller-manager
    spec:
      securityContext:
        runAsNonRoot: true
        seccompProfile:
          type: RuntimeDefault
      containers:
      - command:
        - /manager
        args:
          - --metrics-bind-address=:8443
          - --leader-elect
          - --health-probe-bind-address=:8081
        image: ghcr.io/kubeflow/model-registry/controller:latest
        name: manager
        env:
          - name: NAMESPACE_LABEL
            value: ""
          - name: NAME_LABEL
            value: ""
          - name: URL_ANNOTATION
            value: ""
          - name: INFERENCE_SERVICE_ID_LABEL
            value: ""
          - name: MODEL_VERSION_ID_LABEL
            value: ""
          - name: REGISTERED_MODEL_ID_LABEL
            value: ""
          - name: FINALIZER
            value: ""
          - name: SERVICE_ANNOTATION
            value: ""
          - name: REGISTRIES_NAMESPACE
            value: ""
          - name: SKIP_TLS_VERIFY
            value: "false"
          - name: INFERENCE_SERVICE_CONTROLLER
            value: ""
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - "ALL"
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /readyz
            port: 8081
          initialDelaySeconds: 5
          periodSeconds: 10
        resources:
          limits:
            memory: 128Mi
          requests:
            cpu: 10m
            memory: 64Mi
      serviceAccountName: controller-controller-manager
      terminationGracePeriodSeconds: 10
{{- else }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "model-registry.controller.fullname" . }}-manager
  namespace: {{ include "model-registry.namespace" . }}
  labels:
    {{- include "model-registry.controller.labels" . | nindent 4 }}
    control-plane: controller-manager
spec:
  replicas: {{ .Values.controller.replicas }}
  selector:
    matchLabels:
      {{- include "model-registry.controller.selectorLabels" . | nindent 6 }}
      control-plane: controller-manager
  template:
    metadata:
      labels:
        {{- include "model-registry.controller.selectorLabels" . | nindent 8 }}
        control-plane: controller-manager
      annotations:
        kubectl.kubernetes.io/default-container: manager
        {{- with .Values.controller.podAnnotations }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      {{- with .Values.global.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "model-registry.controller.serviceAccountName" . }}
      securityContext:
        runAsNonRoot: true
        seccompProfile:
          type: RuntimeDefault
      containers:
      - name: manager
        image: {{ include "model-registry.controller.image" . }}
        imagePullPolicy: {{ include "model-registry.controller.imagePullPolicy" . }}
        command:
        - /manager
        args:
          - --metrics-bind-address=:{{ .Values.controller.ports.metrics }}
          - --leader-elect
          - --health-probe-bind-address=:{{ .Values.controller.ports.health }}
        env:
        - name: NAMESPACE_LABEL
          value: {{ .Values.controller.env.namespaceLabel | quote }}
        - name: NAME_LABEL
          value: {{ .Values.controller.env.nameLabel | quote }}
        - name: URL_ANNOTATION
          value: {{ .Values.controller.env.urlAnnotation | quote }}
        - name: INFERENCE_SERVICE_ID_LABEL
          value: {{ .Values.controller.env.inferenceServiceIdLabel | quote }}
        - name: MODEL_VERSION_ID_LABEL
          value: {{ .Values.controller.env.modelVersionIdLabel | quote }}
        - name: REGISTERED_MODEL_ID_LABEL
          value: {{ .Values.controller.env.registeredModelIdLabel | quote }}
        - name: FINALIZER
          value: {{ .Values.controller.env.finalizer | quote }}
        - name: SERVICE_ANNOTATION
          value: {{ .Values.controller.env.serviceAnnotation | quote }}
        - name: REGISTRIES_NAMESPACE
          value: {{ .Values.controller.env.registriesNamespace | quote }}
        - name: SKIP_TLS_VERIFY
          value: {{ .Values.controller.env.skipTlsVerify | quote }}
        - name: INFERENCE_SERVICE_CONTROLLER
          value: {{ .Values.controller.env.inferenceServiceController | quote }}
        {{- with .Values.controller.env.additional }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
        ports:
        - name: health
          containerPort: {{ .Values.controller.ports.health }}
          protocol: TCP
        {{- if .Values.controller.livenessProbe.enabled }}
        livenessProbe:
          httpGet:
            path: /healthz
            port: {{ .Values.controller.ports.health }}
          initialDelaySeconds: {{ .Values.controller.livenessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.controller.livenessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.controller.livenessProbe.timeoutSeconds }}
          failureThreshold: {{ .Values.controller.livenessProbe.failureThreshold }}
        {{- end }}
        {{- if .Values.controller.readinessProbe.enabled }}
        readinessProbe:
          httpGet:
            path: /readyz
            port: {{ .Values.controller.ports.health }}
          initialDelaySeconds: {{ .Values.controller.readinessProbe.initialDelaySeconds }}
          periodSeconds: {{ .Values.controller.readinessProbe.periodSeconds }}
          timeoutSeconds: {{ .Values.controller.readinessProbe.timeoutSeconds }}
          failureThreshold: {{ .Values.controller.readinessProbe.failureThreshold }}
        {{- end }}
        resources:
          {{- toYaml .Values.controller.resources | nindent 10 }}
        securityContext:
          allowPrivilegeEscalation: false
          capabilities:
            drop:
            - ALL
      {{- with .Values.controller.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.controller.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.controller.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      terminationGracePeriodSeconds: 10
{{- end }}
{{- end }} 