Repository: provectus/kafka-ui
Issue: Ingress resource will not survive k8s upgrade from 1.21 to 1.22
Labels: type/bug
status/accepted
scope/k8s

**Describe the bug**

Ingres template has wrong version logic
networking.k8s.io/v1beta1 - this api version is [depricated since 1.19 and totaly removed since 1.22](https://kubernetes.io/docs/reference/using-api/deprecation-guide/#ingress-v122)
Current logic will work fine for new setup on kubernetes v1.22, but it completely broken when you try upgrade kubernetes from v1.21 to v1.22. Because setup on 1.21 has api version that will be removed in 1.22. So on kubernetes upgrade ingress resorce will be removed and you must install helm chart again.

Steps to reproduce the behavior:

1. Install helm chart on kubernetes v 1.21
2. Upgrade kubernetes to v 1.22
3. Ingress will be broken

**Expected behavior**
Ingress resource must survive the kubernetes upgrade

**Additional context**
Related to this [issue](https://github.com/provectus/kafka-ui/issues/1337)


Issue comments:
Hello there keeperUA! 👋

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. 👀
@keeperUA hey, thanks for reporting!
Unfortunatly i dont have right to make PR
So there is a proposed ingress template


```
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "kafka-ui.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
apiVersion: networking.k8s.io/v1
{{- else if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{- else }}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
  name: {{ $fullName }}
  labels:
    {{- include "kafka-ui.labels" . | nindent 4 }}
  {{- with .Values.ingress.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.ingress.tls.enabled }}
  tls:
    - hosts:
        - {{ .Values.ingress.host }}
      secretName: {{ .Values.ingress.tls.secretName }}
  {{- end }}
  {{- if .Values.ingress.ingressClassName }}
  ingressClassName: {{ .Values.ingress.ingressClassName }}
  {{- end }}
  rules:
    - http:
        paths:
{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" -}}
          {{- range .Values.ingress.precedingPaths }}
          - path: {{ .path }}
            pathType: Prefix
            backend:
              service:
                name: {{ .serviceName }}
                port:
                  number: {{ .servicePort }}
          {{- end }}
          - backend:
              service:
                name: {{ $fullName }}
                port:
                  number: {{ $svcPort }}
            pathType: Prefix
{{- if .Values.ingress.path }}
            path: {{ .Values.ingress.path }}
{{- end }}
          {{- range .Values.ingress.succeedingPaths }}
          - path: {{ .path }}
            pathType: Prefix
            backend:
              service:
                name: {{ .serviceName }}
                port:
                  number: {{ .servicePort }}
          {{- end }}
{{- if .Values.ingress.host }}
      host: {{ .Values.ingress.host }}
{{- end }}
{{- else -}}
          {{- range .Values.ingress.precedingPaths }}
          - path: {{ .path }}
            backend:
              serviceName: {{ .serviceName }}
              servicePort: {{ .servicePort }}
          {{- end }}
          - backend:
              serviceName: {{ $fullName }}
              servicePort: {{ $svcPort }}
{{- if .Values.ingress.path }}
            path: {{ .Values.ingress.path }}
{{- end }}
          {{- range .Values.ingress.succeedingPaths }}
          - path: {{ .path }}
            backend:
              serviceName: {{ .serviceName }}
              servicePort: {{ .servicePort }}
          {{- end }}
{{- if .Values.ingress.host }}
      host: {{ .Values.ingress.host }}
{{- end }}
{{- end }}
{{- end }}

```
@keeperUA you def can open a PR, you just have to fork a repo first, make a branch there and propose the changes to the base repo. Or you can even do it via github UI (editing a specific file will fork a repo for you).
ok, i will try

Pull request review comments:

Patch that resolved the issue:
diff --git a/charts/kafka-ui/templates/ingress.yaml b/charts/kafka-ui/templates/ingress.yaml
index 7c1c046a0eb..06f70e990cb 100644
--- a/charts/kafka-ui/templates/ingress.yaml
+++ b/charts/kafka-ui/templates/ingress.yaml
@@ -1,11 +1,11 @@
 {{- if .Values.ingress.enabled -}}
 {{- $fullName := include "kafka-ui.fullname" . -}}
 {{- $svcPort := .Values.service.port -}}
-{{- if semverCompare ">=1.22-0" .Capabilities.KubeVersion.GitVersion -}}
+{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" }}
 apiVersion: networking.k8s.io/v1
-{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
+{{- else if $.Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
 apiVersion: networking.k8s.io/v1beta1
-{{- else -}}
+{{- else }}
 apiVersion: extensions/v1beta1
 {{- end }}
 kind: Ingress
@@ -30,7 +30,7 @@ spec:
   rules:
     - http:
         paths:
-{{- if semverCompare ">=1.22-0" .Capabilities.KubeVersion.GitVersion -}}
+{{- if $.Capabilities.APIVersions.Has "networking.k8s.io/v1" -}}
           {{- range .Values.ingress.precedingPaths }}
           - path: {{ .path }}
             pathType: Prefix
@@ -84,4 +84,4 @@ spec:
       host: {{ .Values.ingress.host }}
 {{- end }}
 {{- end }}
-{{- end }}
\ No newline at end of file
+{{- end }}


Test patch: