apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

## global namespace must be set due to:
## https://github.com/kubernetes-sigs/kustomize/issues/1301#issuecomment-1308228710
namespace: kubeflow

resources:
  ## upstream
  - upstream/apps/katib/upstream/installs/katib-with-kubeflow

  ## local
  {{<- if tmpl.Exec "kubeflow_katib.mysql.auth.secret_is_cloned" . >}}
  - resources/clone-mysql-secret-clusterpolicy.yaml
  {{<- else >}}
  - resources/restart-on-mysql-secret-update-clusterpolicy.yaml
  {{<- end >}}

  {{<- if .Values.kubeflow_tools.katib.extraManifests >}}
  - resources/extra-manifests.yaml
  {{<- end >}}
  
  {{<- if not (tmpl.Exec "kubeflow_katib.use_embedded_mysql" .) >}}
  {{<- if not .Values.kubeflow_tools.katib.mysql.auth.existingSecret >}}
  - resources/pipelines-mysql-secret.yaml
  {{<- end >}}
  {{<- end >}}

patchesStrategicMerge:
  - patches/patch-katib-db-manager-deployment.yaml
  - patches/patch-katib-ui-authorizationpolicy.yaml
  - patches/patch-katib-ui-deployment.yaml
  - patches/patch-katib-ui-virtualservice.yaml
  - patches/patch-katib-mutatingwebhook.yaml
  - patches/patch-katib-validatingwebhook.yaml

  ## removals
  - patches/removals/mysql-resources.yaml

configMapGenerator:
  - name: katib-mysql-config
    literals:
      - dbHost="{{< tmpl.Exec "kubeflow_katib.mysql.hostname" . >}}"
      - dbPort="{{< tmpl.Exec "kubeflow_katib.mysql.port" . >}}"
      - dbName="{{< .Values.kubeflow_tools.katib.mysqlDatabase >}}"

images:
  - name: docker.io/kubeflowkatib/katib-controller
    newName: {{< .Values.kubeflow_tools.katib.images.katibController.repository | quote >}}
    {{<- if .Values.kubeflow_tools.katib.images.katibController.tag >}}
    newTag: {{< .Values.kubeflow_tools.katib.images.katibController.tag | quote >}}
    {{<- end >}}
  - name: docker.io/kubeflowkatib/katib-db-manager
    newName: {{< .Values.kubeflow_tools.katib.images.katibDbManager.repository | quote >}}
    {{<- if .Values.kubeflow_tools.katib.images.katibDbManager.tag >}}
    newTag: {{< .Values.kubeflow_tools.katib.images.katibDbManager.tag | quote >}}
    {{<- end >}}
  - name: docker.io/kubeflowkatib/katib-ui
    newName: {{< .Values.kubeflow_tools.katib.images.katibUi.repository | quote >}}
    {{<- if .Values.kubeflow_tools.katib.images.katibUi.tag >}}
    newTag: {{< .Values.kubeflow_tools.katib.images.katibUi.tag | quote >}}
    {{<- end >}}
