From a227e25cbee76cd2d609752008154acee824c811 Mon Sep 17 00:00:00 2001 From: Zvi Cahana Date: Sun, 25 Jan 2026 17:28:03 +0200 Subject: [PATCH 1/3] Fix args ordering in FQDN Templating guide --- docs/advanced/fqdn-templating.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/advanced/fqdn-templating.md b/docs/advanced/fqdn-templating.md index baefc50b11..49e9bd412e 100644 --- a/docs/advanced/fqdn-templating.md +++ b/docs/advanced/fqdn-templating.md @@ -64,16 +64,16 @@ The template uses the following data from the source object (e.g., a `Service` o -| Function | Description | Example | -|:-------------|:------------------------------------------------------|:---------------------------------------------------------------------------------| -| `contains` | Check if `substr` is in `string` | `{{ contains "hello" "ell" }} → true` | -| `isIPv4` | Validate an IPv4 address | `{{ isIPv4 "192.168.1.1" }} → true` | -| `isIPv6` | Validate an IPv6 address (including IPv4-mapped IPv6) | `{{ isIPv6 "2001:db8::1" }} → true`
`{{ isIPv6 "::FFFF:192.168.1.1" }}→true` | -| `replace` | Replace `old` with `new` | `{{ replace "hello" "l" "w" }} → hewwo` | -| `trim` | Remove leading and trailing spaces | `{{ trim " hello " }} → hello` | -| `toLower` | Convert to lowercase | `{{ toLower "HELLO" }} → hello` | -| `trimPrefix` | Remove the leading `prefix` | `{{ trimPrefix "pre" "prefix" }} → fix` | -| `trimSuffix` | Remove the trailing `suffix` | `{{ trimSuffix "fix" "suffix" }} → suf` | +| Function | Description | Example | +|:-------------|:------------------------------------------------------|:-----------------------------------------------------------------------------------| +| `contains` | Check if `substr` is in `string` | `{{ contains "hello" "ell" }} → true` | +| `isIPv4` | Validate an IPv4 address | `{{ isIPv4 "192.168.1.1" }} → true` | +| `isIPv6` | Validate an IPv6 address (including IPv4-mapped IPv6) | `{{ isIPv6 "2001:db8::1" }} → true`
`{{ isIPv6 "::FFFF:192.168.1.1" }} → true` | +| `replace` | Replace `old` with `new` | `{{ replace "l" "w" "hello" }} → hewwo` | +| `trim` | Remove leading and trailing spaces | `{{ trim " hello " }} → hello` | +| `toLower` | Convert to lowercase | `{{ toLower "HELLO" }} → hello` | +| `trimPrefix` | Remove the leading `prefix` | `{{ trimPrefix "hello" "h" }} → ello` | +| `trimSuffix` | Remove the trailing `suffix` | `{{ trimSuffix "hello" "o" }} → hell` | --- From 98924fd5ccd40210a897edfcdb093b6f32c4331a Mon Sep 17 00:00:00 2001 From: Zvi Cahana Date: Sun, 25 Jan 2026 17:29:25 +0200 Subject: [PATCH 2/3] Add test cases for FQDN templates executions --- source/fqdn/fqdn_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/fqdn/fqdn_test.go b/source/fqdn/fqdn_test.go index 15eed953b4..147ab1ebb0 100644 --- a/source/fqdn/fqdn_test.go +++ b/source/fqdn/fqdn_test.go @@ -145,6 +145,39 @@ func TestExecTemplate(t *testing.T) { }, want: []string{"test.example.com"}, }, + { + name: "trim prefix", + tmpl: `{{ trimSuffix .Name "the-" }}.example.com`, + obj: &testObject{ + ObjectMeta: metav1.ObjectMeta{ + Name: "the-test", + Namespace: "default", + }, + }, + want: []string{"test.example.com"}, + }, + { + name: "trim suffix", + tmpl: `{{ trimSuffix .Name "-v2" }}.example.com`, + obj: &testObject{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-v2", + Namespace: "default", + }, + }, + want: []string{"test.example.com"}, + }, + { + name: "replace dash", + tmpl: `{{ replace "-" "." .Name }}.example.com`, + obj: &testObject{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-v2", + Namespace: "default", + }, + }, + want: []string{"test.v2.example.com"}, + }, { name: "annotations and labels", tmpl: "{{.Labels.environment }}.example.com, {{ index .ObjectMeta.Annotations \"alb.ingress.kubernetes.io/scheme\" }}.{{ .Labels.environment }}.{{ index .ObjectMeta.Annotations \"dns.company.com/zone\" }}", From 770d3d4b950264c27a2b45156cb4b72298a0faa6 Mon Sep 17 00:00:00 2001 From: Zvi Cahana Date: Thu, 29 Jan 2026 22:29:42 +0200 Subject: [PATCH 3/3] Fix unit test to use the correct template function --- source/fqdn/fqdn_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fqdn/fqdn_test.go b/source/fqdn/fqdn_test.go index 147ab1ebb0..d66f9b1e3d 100644 --- a/source/fqdn/fqdn_test.go +++ b/source/fqdn/fqdn_test.go @@ -147,7 +147,7 @@ func TestExecTemplate(t *testing.T) { }, { name: "trim prefix", - tmpl: `{{ trimSuffix .Name "the-" }}.example.com`, + tmpl: `{{ trimPrefix .Name "the-" }}.example.com`, obj: &testObject{ ObjectMeta: metav1.ObjectMeta{ Name: "the-test",