Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions charts/kafka-ui/templates/http-route.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{{- range $routeIdx, $route := .Values.httpRoutes }}
{{- if $route.enabled }}
{{- if or (not $route.gatewayParentRefs) (lt (len $route.gatewayParentRefs) 1) }}
{{- fail (printf "httpRoute[%d].gatewayParentRefs must be defined and contain at least one gateway reference." $routeIdx) }}
{{- end -}}

{{- if or (not $route.matches) (lt (len $route.matches) 1) }}
{{- fail (printf "httpRoute[%d].matches must be defined and contain at least one match element." $routeIdx) }}
{{- end -}}

apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: {{ tpl ($route.nameOverride | default (printf "%s-%s" $.Chart.Name (first $route.gatewayParentRefs).name)) $ }}-httproute
labels:
{{- include "kafka-ui.labels" $ | nindent 4 }}
{{- if $route.labels }}
{{- tpl (toYaml $route.labels) $ | nindent 4 }}
{{- end }}
{{- if $route.annotations }}
annotations:
{{- tpl (toYaml $route.annotations) $ | nindent 4 }}
{{- end }}
spec:
parentRefs:
{{- range $idx, $parentRef := $route.gatewayParentRefs }}
- group: gateway.networking.k8s.io
kind: Gateway
name: {{ tpl (required (printf "httpRoutes[%d].gatewayParentRefs[%d].name is required." $routeIdx $idx) $parentRef.name) $ }}
{{- if $parentRef.namespace }}
namespace: {{ tpl ($parentRef.namespace) $ }}
{{- end }}
{{- if $parentRef.sectionName }}
sectionName: {{ tpl ($parentRef.sectionName) $ }}
{{- end }}
{{- end }}
hostnames:
{{- tpl (toYaml $route.hostnames) $ | nindent 2 }}
Comment on lines +37 to +38
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Handle empty or undefined hostnames gracefully.

If hostnames is undefined or an empty array, toYaml will produce null or [], which may cause invalid YAML. Consider making the hostnames field conditional or adding validation.

💡 Proposed fix to make hostnames conditional
+  {{- if $route.hostnames }}
   hostnames:
   {{- tpl (toYaml $route.hostnames) $ | nindent 2 }}
+  {{- end }}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
hostnames:
{{- tpl (toYaml $route.hostnames) $ | nindent 2 }}
{{- if $route.hostnames }}
hostnames:
{{- tpl (toYaml $route.hostnames) $ | nindent 2 }}
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/templates/http-route.yaml` around lines 37 - 38, The
hostnames block currently always renders and may produce invalid YAML when
$route.hostnames is empty or undefined; update the template to conditionally
render the hostnames section only when $route.hostnames is set and non-empty
(e.g., wrap the existing line using an if test like "if $route.hostnames" or "if
and $route.hostnames (gt (len $route.hostnames) 0)" and keep the existing "{{-
tpl (toYaml $route.hostnames) $ | nindent 2 }}" inside that block) so that
hostnames is omitted entirely when there are no values.

rules:
- matches:
{{- tpl (toYaml $route.matches) $ | nindent 4 }}
{{- if $route.shouldRouteToService }}
backendRefs:
- group: ''
kind: Service
name: {{ include "kafka-ui.fullname" $ }}
port: {{ (tpl (default "80" ($.Values.service.port)) $) | int }}
weight: 1
{{- end }}
Comment on lines +42 to +49
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: Template execution failure and indentation error on port line.

Two issues on line 47:

  1. Tab character: Line 47 uses a tab for indentation instead of spaces, which will cause YAML parsing errors in the rendered output.

  2. tpl on integer: $.Values.service.port is an integer (default 80). The tpl function expects a string, so this will fail with "expected string; found int" when the template executes.

Since port values typically don't need Go template interpolation, tpl is unnecessary here.

🐛 Proposed fix
     backendRefs:
     - group: ''
       kind: Service
       name: {{ include "kafka-ui.fullname" $ }}
-	  port: {{ (tpl (default "80" ($.Values.service.port)) $) | int }}
+      port: {{ $.Values.service.port | default 80 | int }}
       weight: 1
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{{- if $route.shouldRouteToService }}
backendRefs:
- group: ''
kind: Service
name: {{ include "kafka-ui.fullname" $ }}
port: {{ (tpl (default "80" ($.Values.service.port)) $) | int }}
weight: 1
{{- end }}
{{- if $route.shouldRouteToService }}
backendRefs:
- group: ''
kind: Service
name: {{ include "kafka-ui.fullname" $ }}
port: {{ $.Values.service.port | default 80 | int }}
weight: 1
{{- end }}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@charts/kafka-ui/templates/http-route.yaml` around lines 42 - 49, Replace the
tab-indented, tpl-wrapped port line with a space-indented, non-tpl expression
that treats port as an integer; specifically, in the http-route.yaml backendRefs
block (the section guarded by {{- if $route.shouldRouteToService }} and
referencing include "kafka-ui.fullname" and $.Values.service.port) remove the
tpl call and the tab, then render the port as an integer, e.g. use a
spaces-indented line like: port: {{ $.Values.service.port | default 80 | int }}
so the template no longer calls tpl on an int and the YAML indentation uses
spaces.

{{- if $route.filters }}
filters:
{{- if $route.shouldStripPath }}
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: "/"
{{- end }}
{{- tpl (toYaml $route.filters) $ | nindent 4 }}
{{- else if $route.shouldStripPath }}
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: "/"
{{- end }}
{{- if $route.timeouts }}
timeouts:
{{- tpl (toYaml $route.timeouts) $ | nindent 4 }}
{{- end }}
{{- /* Add a document separator if there is another item coming */ -}}
{{- if lt (add1 $routeIdx) (len $.Values.httpRoutes) -}}
---
{{- end -}}
{{- end -}}
{{- end -}}
42 changes: 41 additions & 1 deletion charts/kafka-ui/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,47 @@ ingress:

## @param ingress.succeedingPaths [array] Http paths to add to the Ingress after the default path
succeedingPaths: []
## @param resources [object] Set Kafka-UI pod requests and limits for different resources like CPU or memory (essential for production workloads)

## Kafka-UI HTTPRoute configuration
## ref: https://gateway-api.sigs.k8s.io/api-types/httproute/
##
## @param httpRoutes [array] HTTPRoute resources to create.
httpRoutes:
## @param httpRoutes.enabled [string] Enable this HTTPRoute
- enabled: false
## @param httpRoutes.hostnames [array] Hostnames to expose this HTTPRoute under
hostnames:
- "example.com"
## @param httpRoutes.annotations [object] Additional annotations for the HTTPRoute resource.
annotations: {}
## @param httpRoutes.labels [object] Labels for the HTTPRoute
labels: {}
## @param httpRoutes.nameOverride [string] The name to give this HTTPRoute resource.
nameOverride: ""
## @param httpRoutes.gatewayParentRefs [array] Which gateway to bind this HTTPRoute to
gatewayParentRefs:
## @param httpRoutes.gatewayParentRefs.name [string] The name of the gateway to bind this HTTPRoute to.
- name: "gateway-example"
## @param httpRoutes.gatewayParentRefs.namespace [string] The namespace that the gateway is defined under.
namespace: "gateway-example"
## @param httpRoutes.gatewayParentRefs.sectionName [string] The section name of the listener to bind to on the Gateway.
sectionName: "http-listener"
## @param httpRoutes.shouldStripPath [string] Whether to strip the path before sending the request to the service.
shouldStripPath: true
## @param httpRoutes.shouldRouteToService [string] Whether this HTTPRoute should route to the backend service.
shouldRouteToService: true
## @param httpRoutes.matches [array] HTTPRoute match rules, ref: https://gateway-api.sigs.k8s.io/reference/spec/#httproutematch.
matches:
## @param httpRoutes.matches.path [object] Match the route based on this path structure.
- path:
## @param httpRoutes.matches.path.type [string] One of Exact, PathPrefix or RegularExpression.
type: PathPrefix
## @param httpRoutes.matches.path.value [string] The path to match on after the host.
value: "/kafka-ui"
## @param httpRoutes.filters [array] HTTPRoute filters, ref: https://gateway-api.sigs.k8s.io/reference/spec/#httproutefilter.
filters: []
## @param httpRoutes.timeouts [object] HTTPRoute timeouts, ref: https://gateway-api.sigs.k8s.io/reference/spec/#httproutetimeouts.
timeouts: {}

## @section Scheduling

Expand Down