Repository: provectus/kafka-ui
Issue: Add the possibility to not specify the image.registry value
Labels: type/enhancement
status/accepted
scope/k8s

**Describe the bug**
It's not a bug but an improvement on how the docker image of the kafka-ui application is built which will allow us to have less values in our deployment.

<!--(A clear and concise description of what the bug is.)-->
We're using that application in several environments (dev, qa, prod, etc...) for each environment we have configured docker/containerd to use a default mirror. 
The fact that the image is using `.Values.image.registry` as mandatory is making that we need to define this value per environment, overcomplicating the maintance of these values.

If we simply set the `.Values.image.registry` to an empty string, the deployment generated does not work
**Set up**
<!--
How do you run the app? Please provide as much info as possible:
1. App version (docker image version or check commit hash in the top left corner in UI)
2. Helm chart version, if you use one
3. Any IAAC configs

We might close the issue without further explanation if you don't provide such information.
-->


**Steps to Reproduce**
Steps to reproduce the behavior:

1. Set this default value:
   `image:
           registry: ""` 
2. Execute `helm template .`

**Expected behavior**
Generate a valid image to be pulled:

`
provectuslabs/kafka-ui:latest
`

Right now the value generated is `/provectuslabs/kafka-ui:latest` which generate that error

`
git pull /provectuslabs/kafka-ui:latest
fatal: '/provectuslabs/kafka-ui:latest' does not appear to be a git repository
fatal: Could not read from remote repository.
` 


Issue comments:
@joseacl thank you. We'll take a look soon.

Pull request review comments:

Patch that resolved the issue:
diff --git a/charts/kafka-ui/templates/_helpers.tpl b/charts/kafka-ui/templates/_helpers.tpl
index 076c4886f80..510452d4cf3 100644
--- a/charts/kafka-ui/templates/_helpers.tpl
+++ b/charts/kafka-ui/templates/_helpers.tpl
@@ -61,3 +61,19 @@ Create the name of the service account to use
 {{- default "default" .Values.serviceAccount.name }}
 {{- end }}
 {{- end }}
+
+
+{{/*
+This allows us to check if the registry of the image is specified or not.
+*/}}
+{{- define "kafka-ui.imageName" -}}
+{{- $registryName := .Values.image.registry -}}
+{{- $repository := .Values.image.repository -}}
+{{- $tag := .Values.image.tag | default .Chart.AppVersion -}}
+{{- if $registryName }}
+{{- printf "%s/%s:%s" $registryName $repository $tag -}}
+{{- else }}
+{{- printf "%s:%s" $repository $tag -}}
+{{- end }}
+{{- end -}}
+
diff --git a/charts/kafka-ui/templates/deployment.yaml b/charts/kafka-ui/templates/deployment.yaml
index 22149bb7513..1f7f6c92ad4 100644
--- a/charts/kafka-ui/templates/deployment.yaml
+++ b/charts/kafka-ui/templates/deployment.yaml
@@ -40,7 +40,7 @@ spec:
         - name: {{ .Chart.Name }}
           securityContext:
             {{- toYaml .Values.securityContext | nindent 12 }}
-          image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
+          image: {{ include "kafka-ui.imageName" . }}
           imagePullPolicy: {{ .Values.image.pullPolicy }}
           {{- if or .Values.env  .Values.yamlApplicationConfig .Values.yamlApplicationConfigConfigMap}}
           env:


Test patch: