Skip to content
Merged
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
20 changes: 10 additions & 10 deletions docs/advanced/fqdn-templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ The template uses the following data from the source object (e.g., a `Service` o

<!-- TODO: generate from code -->

| 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`<br/>`{{ 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`<br/>`{{ 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` |

---

Expand Down
33 changes: 33 additions & 0 deletions source/fqdn/fqdn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,39 @@ func TestExecTemplate(t *testing.T) {
},
want: []string{"test.example.com"},
},
{
name: "trim prefix",
tmpl: `{{ trimPrefix .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\" }}",
Expand Down
Loading