Skip to content

Commit 99ca961

Browse files
committed
Verify with test cases any usage of tpl function
External.Domain could be defined as go lang template. In all places domain is passed to tpl function to correctly render the value. In Service type LoadBalancer the external addresses should be handled the same way as in ConfigMap. Every service should have annotation that starts with external address even if only single one is provided.
1 parent 662fa2e commit 99ca961

File tree

14 files changed

+6701
-644
lines changed

14 files changed

+6701
-644
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#### Added
77
#### Changed
88
#### Fixed
9+
* All occurrence of External Domain execution via tpl function
10+
* Calculating Service typed LoadBalancer annotation based on external addresses (even single one)
911
#### Removed
1012

1113
### [5.9.9](https://github.com/redpanda-data/helm-charts/releases/tag/redpanda-5.9.9) - 2024-10-24

charts/redpanda/certs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func ClientCerts(dot *helmette.Dot) []*certmanagerv1.Certificate {
4848

4949
if values.External.Domain != nil {
5050
names = append(names, helmette.Tpl(*values.External.Domain, dot))
51-
names = append(names, helmette.Tpl(fmt.Sprintf("*.%s", *values.External.Domain), dot))
51+
names = append(names, fmt.Sprintf("*.%s", helmette.Tpl(*values.External.Domain, dot)))
5252
}
5353

5454
duration := helmette.Default("43800h", data.Duration)

charts/redpanda/chart_test.go

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,6 +845,22 @@ func TestGoHelmEquivalence(t *testing.T) {
845845
// generally results in invalid inputs.
846846
values := redpanda.PartialValues{
847847
Enterprise: &redpanda.PartialEnterprise{License: ptr.To("LICENSE_PLACEHOLDER")},
848+
External: &redpanda.PartialExternalConfig{
849+
// include, required and tpl are not yet implemented in gotohelm package
850+
Domain: ptr.To("{{ trunc 4 .Values.external.prefixTemplate | lower | repeat 3 }}-testing "),
851+
Type: ptr.To(corev1.ServiceTypeLoadBalancer),
852+
PrefixTemplate: ptr.To("$POD_ORDINAL-XYZ-$(echo -n $HOST_IP_ADDRESS | sha256sum | head -c 7)"),
853+
ExternalDNS: &redpanda.PartialEnableable{Enabled: ptr.To(true)},
854+
},
855+
Statefulset: &redpanda.PartialStatefulset{
856+
ExtraVolumeMounts: ptr.To(`- name: test-extra-volume
857+
mountPath: {{ upper "/fake/lifecycle" }}`),
858+
ExtraVolumes: ptr.To(`- name: test-extra-volume
859+
secret:
860+
secretName: {{ trunc 5 .Values.enterprise.license }}-sts-lifecycle
861+
defaultMode: 0774`),
862+
InitContainers: GetInitContainer(),
863+
},
848864
}
849865

850866
// We're not interested in tests, console, or connectors so always disable
@@ -904,7 +920,7 @@ func TestGoHelmEquivalence(t *testing.T) {
904920
return strings.Compare(aStr, bStr)
905921
})
906922

907-
const stsIdx = 12
923+
const stsIdx = 14
908924

909925
// resource.Quantity is a special object. To Ensure they compare correctly,
910926
// we'll round trip it through JSON so the internal representations will
@@ -924,3 +940,65 @@ func TestGoHelmEquivalence(t *testing.T) {
924940
assert.Equal(t, helmObjs[i], goObjs[i])
925941
}
926942
}
943+
944+
func GetInitContainer() *struct {
945+
Configurator *struct {
946+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
947+
Resources map[string]any "json:\"resources,omitempty\""
948+
} "json:\"configurator,omitempty\""
949+
FSValidator *struct {
950+
Enabled *bool "json:\"enabled,omitempty\""
951+
Resources map[string]any "json:\"resources,omitempty\""
952+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
953+
ExpectedFS *string "json:\"expectedFS,omitempty\""
954+
} "json:\"fsValidator,omitempty\""
955+
SetDataDirOwnership *struct {
956+
Enabled *bool "json:\"enabled,omitempty\""
957+
Resources map[string]any "json:\"resources,omitempty\""
958+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
959+
} "json:\"setDataDirOwnership,omitempty\""
960+
SetTieredStorageCacheDirOwnership *struct {
961+
Resources map[string]any "json:\"resources,omitempty\""
962+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
963+
} "json:\"setTieredStorageCacheDirOwnership,omitempty\""
964+
Tuning *struct {
965+
Resources map[string]any "json:\"resources,omitempty\""
966+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
967+
} "json:\"tuning,omitempty\""
968+
ExtraInitContainers *string "json:\"extraInitContainers,omitempty\""
969+
} {
970+
return &struct {
971+
Configurator *struct {
972+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
973+
Resources map[string]any "json:\"resources,omitempty\""
974+
} "json:\"configurator,omitempty\""
975+
FSValidator *struct {
976+
Enabled *bool "json:\"enabled,omitempty\""
977+
Resources map[string]any "json:\"resources,omitempty\""
978+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
979+
ExpectedFS *string "json:\"expectedFS,omitempty\""
980+
} "json:\"fsValidator,omitempty\""
981+
SetDataDirOwnership *struct {
982+
Enabled *bool "json:\"enabled,omitempty\""
983+
Resources map[string]any "json:\"resources,omitempty\""
984+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
985+
} "json:\"setDataDirOwnership,omitempty\""
986+
SetTieredStorageCacheDirOwnership *struct {
987+
Resources map[string]any "json:\"resources,omitempty\""
988+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
989+
} "json:\"setTieredStorageCacheDirOwnership,omitempty\""
990+
Tuning *struct {
991+
Resources map[string]any "json:\"resources,omitempty\""
992+
ExtraVolumeMounts *string "json:\"extraVolumeMounts,omitempty\""
993+
} "json:\"tuning,omitempty\""
994+
ExtraInitContainers *string "json:\"extraInitContainers,omitempty\""
995+
}{
996+
ExtraInitContainers: ptr.To(`- name: "test-init-container"
997+
image: "mintel/docker-alpine-bash-curl-jq:latest"
998+
command: [ "/bin/bash", "-c" ]
999+
args:
1000+
- |
1001+
set -xe
1002+
echo "Hello World!"`),
1003+
}
1004+
}

charts/redpanda/configmap.tpl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func advertisedHost(dot *helmette.Dot, i int32) string {
271271
}
272272

273273
if ptr.Deref(values.External.Domain, "") != "" {
274-
address = fmt.Sprintf("%s.%s", address, *values.External.Domain)
274+
address = fmt.Sprintf("%s.%s", address, helmette.Tpl(*values.External.Domain, dot))
275275
}
276276

277277
return address

charts/redpanda/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ func advertisedHostJSON(dot *helmette.Dot, externalName string, port int32, repl
726726
if domain := ptr.Deref(values.External.Domain, ""); domain != "" {
727727
host = map[string]any{
728728
"name": externalName,
729-
"address": fmt.Sprintf("%s.%s", address, domain),
729+
"address": fmt.Sprintf("%s.%s", address, helmette.Tpl(domain, dot)),
730730
"port": port,
731731
}
732732
} else {

charts/redpanda/service.loadbalancer.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ func LoadBalancerServices(dot *helmette.Dot) []*corev1.Service {
6363

6464
if externalDNS.Enabled {
6565
prefix := podname
66-
if len(values.External.Addresses) > int(i) {
67-
prefix = values.External.Addresses[i]
66+
if len(values.External.Addresses) > 0 {
67+
if len(values.External.Addresses) == 1 {
68+
prefix = values.External.Addresses[0]
69+
} else {
70+
prefix = values.External.Addresses[i]
71+
}
6872
}
6973

7074
address := fmt.Sprintf("%s.%s", prefix, helmette.Tpl(*values.External.Domain, dot))

charts/redpanda/templates/_certs.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{{- end -}}
3737
{{- if (ne (toJson $values.external.domain) "null") -}}
3838
{{- $names = (concat (default (list ) $names) (list (tpl $values.external.domain $dot))) -}}
39-
{{- $names = (concat (default (list ) $names) (list (tpl (printf "*.%s" $values.external.domain) $dot))) -}}
39+
{{- $names = (concat (default (list ) $names) (list (printf "*.%s" (tpl $values.external.domain $dot)))) -}}
4040
{{- end -}}
4141
{{- $duration := (default "43800h" $data.duration) -}}
4242
{{- $issuerRef := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $data.issuerRef (mustMergeOverwrite (dict "name" "" ) (dict "kind" "Issuer" "group" "cert-manager.io" "name" (printf "%s-%s-root-issuer" $fullname $name) ))) ))) "r") -}}

charts/redpanda/templates/_configmap.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
{{- $address = (index $values.external.addresses $i) -}}
205205
{{- end -}}
206206
{{- if (ne (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $values.external.domain "") ))) "r") "") -}}
207-
{{- $address = (printf "%s.%s" $address $values.external.domain) -}}
207+
{{- $address = (printf "%s.%s" $address (tpl $values.external.domain $dot)) -}}
208208
{{- end -}}
209209
{{- $_is_returning = true -}}
210210
{{- (dict "r" $address) | toJson -}}

charts/redpanda/templates/_secrets.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ echo "passed"`) -}}
379379
{{- end -}}
380380
{{- $domain_7 := (get (fromJson (include "_shims.ptr_Deref" (dict "a" (list $values.external.domain "") ))) "r") -}}
381381
{{- if (ne $domain_7 "") -}}
382-
{{- $host = (dict "name" $externalName "address" (printf "%s.%s" $address $domain_7) "port" $port ) -}}
382+
{{- $host = (dict "name" $externalName "address" (printf "%s.%s" $address (tpl $domain_7 $dot)) "port" $port ) -}}
383383
{{- else -}}
384384
{{- $host = (dict "name" $externalName "address" $address "port" $port ) -}}
385385
{{- end -}}

charts/redpanda/templates/_service.loadbalancer.go.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@
3232
{{- end -}}
3333
{{- if $externalDNS.enabled -}}
3434
{{- $prefix := $podname -}}
35-
{{- if (gt ((get (fromJson (include "_shims.len" (dict "a" (list $values.external.addresses) ))) "r") | int) ($i | int)) -}}
35+
{{- if (gt ((get (fromJson (include "_shims.len" (dict "a" (list $values.external.addresses) ))) "r") | int) (0 | int)) -}}
36+
{{- if (eq ((get (fromJson (include "_shims.len" (dict "a" (list $values.external.addresses) ))) "r") | int) (1 | int)) -}}
37+
{{- $prefix = (index $values.external.addresses (0 | int)) -}}
38+
{{- else -}}
3639
{{- $prefix = (index $values.external.addresses $i) -}}
3740
{{- end -}}
41+
{{- end -}}
3842
{{- $address := (printf "%s.%s" $prefix (tpl $values.external.domain $dot)) -}}
3943
{{- $_ := (set $annotations "external-dns.alpha.kubernetes.io/hostname" $address) -}}
4044
{{- end -}}

0 commit comments

Comments
 (0)