Skip to content

Commit 9407dc4

Browse files
sbocinecRafalKorepta
authored andcommitted
charts/redpanda: Enable using localhost for SR/PP internal clients
Add opt-in configuration to use localhost instead of headless service FQDN for Schema Registry and Pandaproxy internal client broker addresses via `pandaproxy_client.use_localhost` and `schema_registry_client.use_localhost`. Default behavior unchanged (continues using headless service FQDN for backward compatibility).
1 parent dba6d44 commit 9407dc4

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

charts/redpanda/chart/templates/_configmap.go.tpl

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@
120120
{{- $redpandaYaml := (dict "redpanda" $redpanda "schema_registry" (get (fromJson (include "redpanda.schemaRegistry" (dict "a" (list $state)))) "r") "pandaproxy" (get (fromJson (include "redpanda.pandaProxyListener" (dict "a" (list $state)))) "r") "config_file" "/etc/redpanda/redpanda.yaml") -}}
121121
{{- if $includeNonHashableItems -}}
122122
{{- $_ := (set $redpandaYaml "rpk" (get (fromJson (include "redpanda.rpkNodeConfig" (dict "a" (list $state $pool)))) "r")) -}}
123-
{{- $_ := (set $redpandaYaml "pandaproxy_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state)))) "r")) -}}
124-
{{- $_ := (set $redpandaYaml "schema_registry_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state)))) "r")) -}}
123+
{{- $_ := (set $redpandaYaml "pandaproxy_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state "pandaproxy")))) "r")) -}}
124+
{{- $_ := (set $redpandaYaml "schema_registry_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state "schema_registry")))) "r")) -}}
125125
{{- if (and (and (get (fromJson (include "redpanda.RedpandaAtLeast_23_3_0" (dict "a" (list $state)))) "r") $state.Values.auditLogging.enabled) (get (fromJson (include "redpanda.Auth.IsSASLEnabled" (dict "a" (list $state.Values.auth)))) "r")) -}}
126-
{{- $_ := (set $redpandaYaml "audit_log_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state)))) "r")) -}}
126+
{{- $_ := (set $redpandaYaml "audit_log_client" (get (fromJson (include "redpanda.kafkaClient" (dict "a" (list $state "audit_log")))) "r")) -}}
127127
{{- end -}}
128128
{{- end -}}
129129
{{- $_is_returning = true -}}
@@ -465,15 +465,34 @@
465465

466466
{{- define "redpanda.kafkaClient" -}}
467467
{{- $state := (index .a 0) -}}
468+
{{- $clientType := (index .a 1) -}}
468469
{{- range $_ := (list 1) -}}
469470
{{- $_is_returning := false -}}
470471
{{- $brokerList := (list) -}}
472+
{{- $useLocalhostKey := (printf "%s_client.use_localhost" $clientType) -}}
473+
{{- $useLocalhost := false -}}
474+
{{- $_506_val_ok := (get (fromJson (include "_shims.dicttest" (dict "a" (list $state.Values.config.node $useLocalhostKey (coalesce nil))))) "r") -}}
475+
{{- $val := (index $_506_val_ok 0) -}}
476+
{{- $ok := (index $_506_val_ok 1) -}}
477+
{{- if $ok -}}
478+
{{- if (kindIs "bool" $val) -}}
479+
{{- $useLocalhost = (eq $val true) -}}
480+
{{- else -}}{{- if (kindIs "string" $val) -}}
481+
{{- $strVal := (get (fromJson (include "_shims.typeassertion" (dict "a" (list "string" $val)))) "r") -}}
482+
{{- $useLocalhost = (or (or (or (eq $strVal "true") (eq $strVal "True")) (eq $strVal "TRUE")) (eq $strVal "1")) -}}
483+
{{- end -}}
484+
{{- end -}}
485+
{{- end -}}
486+
{{- if $useLocalhost -}}
487+
{{- $brokerList = (concat (default (list) $brokerList) (list (dict "address" "localhost" "port" ($state.Values.listeners.kafka.port | int)))) -}}
488+
{{- else -}}
471489
{{- range $_, $broker := (get (fromJson (include "redpanda.BrokerList" (dict "a" (list $state -1)))) "r") -}}
472490
{{- $brokerList = (concat (default (list) $brokerList) (list (dict "address" $broker "port" ($state.Values.listeners.kafka.port | int)))) -}}
473491
{{- end -}}
474492
{{- if $_is_returning -}}
475493
{{- break -}}
476494
{{- end -}}
495+
{{- end -}}
477496
{{- $kafkaTLS := $state.Values.listeners.kafka.tls -}}
478497
{{- $brokerTLS := (coalesce nil) -}}
479498
{{- if (get (fromJson (include "redpanda.InternalTLS.IsEnabled" (dict "a" (list $state.Values.listeners.kafka.tls $state.Values.tls)))) "r") -}}
@@ -623,17 +642,17 @@
623642
{{- end -}}
624643
{{- $enabledOptions := (dict "true" true "1" true "" true) -}}
625644
{{- $lockMemory := false -}}
626-
{{- $_671_value_14_ok_15 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $flags "--lock-memory" "")))) "r") -}}
627-
{{- $value_14 := (index $_671_value_14_ok_15 0) -}}
628-
{{- $ok_15 := (index $_671_value_14_ok_15 1) -}}
645+
{{- $_692_value_14_ok_15 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $flags "--lock-memory" "")))) "r") -}}
646+
{{- $value_14 := (index $_692_value_14_ok_15 0) -}}
647+
{{- $ok_15 := (index $_692_value_14_ok_15 1) -}}
629648
{{- if $ok_15 -}}
630649
{{- $lockMemory = (ternary (index $enabledOptions $value_14) false (hasKey $enabledOptions $value_14)) -}}
631650
{{- $_ := (unset $flags "--lock-memory") -}}
632651
{{- end -}}
633652
{{- $overprovisioned := false -}}
634-
{{- $_678_value_16_ok_17 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $flags "--overprovisioned" "")))) "r") -}}
635-
{{- $value_16 := (index $_678_value_16_ok_17 0) -}}
636-
{{- $ok_17 := (index $_678_value_16_ok_17 1) -}}
653+
{{- $_699_value_16_ok_17 := (get (fromJson (include "_shims.dicttest" (dict "a" (list $flags "--overprovisioned" "")))) "r") -}}
654+
{{- $value_16 := (index $_699_value_16_ok_17 0) -}}
655+
{{- $ok_17 := (index $_699_value_16_ok_17 1) -}}
637656
{{- if $ok_17 -}}
638657
{{- $overprovisioned = (ternary (index $enabledOptions $value_16) false (hasKey $enabledOptions $value_16)) -}}
639658
{{- $_ := (unset $flags "--overprovisioned") -}}

charts/redpanda/chart/values.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -958,6 +958,10 @@ config:
958958

959959
# Reference schema registry client https://docs.redpanda.com/current/reference/node-configuration-sample/
960960
schema_registry_client: {}
961+
# # Override to use localhost instead of headless service FQDN.
962+
# # Useful when DNS issues occur. Default: false (uses headless service)
963+
# use_localhost: false
964+
#
961965
# # Number of times to retry a request to a broker
962966
# # Default: 5
963967
# retries: 5
@@ -1000,6 +1004,10 @@ config:
10001004

10011005
# Reference panda proxy client https://docs.redpanda.com/current/reference/node-configuration-sample/
10021006
pandaproxy_client: {}
1007+
# # Override to use localhost instead of headless service FQDN.
1008+
# # Useful when DNS issues occur. Default: false (uses headless service)
1009+
# use_localhost: false
1010+
#
10031011
# # Number of times to retry a request to a broker
10041012
# # Default: 5
10051013
# retries: 5

charts/redpanda/configmap.tpl.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ func RedpandaConfigFile(state *RenderState, includeNonHashableItems bool, pool P
147147

148148
if includeNonHashableItems {
149149
redpandaYaml["rpk"] = rpkNodeConfig(state, pool)
150-
redpandaYaml["pandaproxy_client"] = kafkaClient(state)
151-
redpandaYaml["schema_registry_client"] = kafkaClient(state)
150+
redpandaYaml["pandaproxy_client"] = kafkaClient(state, "pandaproxy")
151+
redpandaYaml["schema_registry_client"] = kafkaClient(state, "schema_registry")
152152
if RedpandaAtLeast_23_3_0(state) && state.Values.AuditLogging.Enabled && state.Values.Auth.IsSASLEnabled() {
153-
redpandaYaml["audit_log_client"] = kafkaClient(state)
153+
redpandaYaml["audit_log_client"] = kafkaClient(state, "audit_log")
154154
}
155155
}
156156

@@ -489,13 +489,34 @@ func rpkSchemaRegistryClientTLSConfiguration(state *RenderState) map[string]any
489489
// kafkaClient returns the configuration for internal components of redpanda to
490490
// connect to its own Kafka API. This is distinct from RPK's configuration for
491491
// Kafka API interactions.
492-
func kafkaClient(state *RenderState) map[string]any {
492+
func kafkaClient(state *RenderState, clientType string) map[string]any {
493493
brokerList := []map[string]any{}
494-
for _, broker := range BrokerList(state, -1) {
494+
495+
useLocalhostKey := fmt.Sprintf("%s_client.use_localhost", clientType)
496+
useLocalhost := false
497+
498+
val, ok := state.Values.Config.Node[useLocalhostKey]
499+
if ok {
500+
if helmette.KindIs("bool", val) {
501+
useLocalhost = val == true
502+
} else if helmette.KindIs("string", val) {
503+
strVal := val.(string)
504+
useLocalhost = strVal == "true" || strVal == "True" || strVal == "TRUE" || strVal == "1"
505+
}
506+
}
507+
508+
if useLocalhost {
495509
brokerList = append(brokerList, map[string]any{
496-
"address": broker,
510+
"address": "localhost",
497511
"port": state.Values.Listeners.Kafka.Port,
498512
})
513+
} else {
514+
for _, broker := range BrokerList(state, -1) {
515+
brokerList = append(brokerList, map[string]any{
516+
"address": broker,
517+
"port": state.Values.Listeners.Kafka.Port,
518+
})
519+
}
499520
}
500521

501522
kafkaTLS := state.Values.Listeners.Kafka.TLS

0 commit comments

Comments
 (0)