Repository: provectus/kafka-ui
Issue: K8s secret is created even if no secret is provided as a value.
Labels: status/accepted
scope/k8s

<!--

Don't forget to check for existing issues/discussions regarding your proposal. We might already have it.
https://github.com/provectus/kafka-ui/issues
https://github.com/provectus/kafka-ui/discussions

-->

**Describe the bug**
<!--(A clear and concise description of what the bug is.)-->
This is not exactly a bug but I felt the `K8s/Helm` section is the appropriate to post this issue.
The chart's secret template renders every time and the resource is created, even when no secrets are provided it is just created with no data.
This may not be a big issue but we faced some conflicts while deploying which have been dealt with some workarounds.
For deploying `kafka-ui` we use both the official chart and a `common` chart we have developed to handle thing like ingress, `istio` routing and `sealed-secrects`. Since our `common` chart has the same naming conventions we ran into a conflict when `sealed-secrets` was trying to unseal and create the k8s secret with the same name.
To overcome this we performed a fullnameoverride in the `kafka-ui` chart but then the network routing broke due to breaking the `kubernetes` service naming convention assumed by our common chart.
We solved this by adding a second service template which works but it is messy because we create 2 services, but only one is used.

So I would like to ask if we could make the secret resource optional if no values are required.
If this is something that we can agree I can work on this and contribute.

**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.
-->
1. App version `0.5.0` 
2. Chart version `0.5.1`

**Steps to Reproduce**
Steps to reproduce the behavior:

1. Create secret with name matching the release name

**Expected behavior**
<!--
(A clear and concise description of what you expected to happen)
-->
Failure to create secret

Issue comments:
Hello there cpapad! 👋

Thank you and congratulations 🎉 for opening your very first issue in this project! 💖

In case you want to claim this issue, please comment down below! We will try to get back to you as soon as we can. 👀
Hey, thanks for reporting this. We'll take a look
> Hey, thanks for reporting this. We'll take a look

Thank you for your quick reply.
I'm more than happy to contribute.
@cpapad you can raise a PR if you wish!

Pull request review comments:

Patch that resolved the issue:
diff --git a/charts/kafka-ui/Chart.yaml b/charts/kafka-ui/Chart.yaml
index 3a1759a3911..6e5f0ee2d5b 100644
--- a/charts/kafka-ui/Chart.yaml
+++ b/charts/kafka-ui/Chart.yaml
@@ -2,6 +2,6 @@ apiVersion: v2
 name: kafka-ui
 description: A Helm chart for kafka-UI
 type: application
-version: 0.5.2
+version: 0.5.3
 appVersion: v0.5.0
 icon: https://github.com/provectus/kafka-ui/raw/master/documentation/images/kafka-ui-logo.png
diff --git a/charts/kafka-ui/templates/secret.yaml b/charts/kafka-ui/templates/secret.yaml
index a2d1f25fa2f..1f974503dc6 100644
--- a/charts/kafka-ui/templates/secret.yaml
+++ b/charts/kafka-ui/templates/secret.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.envs.secret -}}
 apiVersion: v1
 kind: Secret
 metadata:
@@ -9,3 +10,4 @@ data:
   {{- range $key, $val := .Values.envs.secret }}
   {{ $key }}: {{ $val | b64enc | quote }}
   {{- end -}}
+{{- end}}
\ No newline at end of file


Test patch: