Skip to content

Commit c7df70d

Browse files
bordeuxclaude
andcommitted
refactor: migrate Kubernetes functions to filter_functions (Phase 12)
Migrate k8s_label_safe, k8s_dns_label_safe, k8s_annotation_safe to the unified filter-functions architecture, supporting both function and filter syntax: - Function: {{ k8s_label_safe(value="My App") }} - Filter: {{ "My App" | k8s_label_safe }} Other Kubernetes functions remain function-only as they don't fit the filter pattern (multi-argument or complex objects). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 16fdd04 commit c7df70d

6 files changed

Lines changed: 476 additions & 29 deletions

File tree

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3090,7 +3090,7 @@ spec:
30903090
{{ k8s_resource_request(cpu="1000m", memory="1Gi") | indent(10) }}
30913091
```
30923092
3093-
#### `k8s_label_safe(value)`
3093+
#### `k8s_label_safe(value)` / `| k8s_label_safe`
30943094
30953095
Sanitize string to be Kubernetes label-safe.
30963096
@@ -3105,18 +3105,22 @@ Sanitize string to be Kubernetes label-safe.
31053105
31063106
**Example:**
31073107
```jinja
3108-
{# Sanitize label value #}
3108+
{# Function syntax #}
31093109
{{ k8s_label_safe(value="My App (v2.0)") }}
31103110
{# Output: my-app-v2.0 #}
31113111
3112+
{# Filter syntax #}
3113+
{{ "My App (v2.0)" | k8s_label_safe }}
3114+
{# Output: my-app-v2.0 #}
3115+
31123116
{# Use in labels #}
31133117
metadata:
31143118
labels:
3115-
app: {{ k8s_label_safe(value=app_name) }}
3116-
version: {{ k8s_label_safe(value=version) }}
3119+
app: {{ app_name | k8s_label_safe }}
3120+
version: {{ version | k8s_label_safe }}
31173121
```
31183122
3119-
#### `k8s_dns_label_safe(value)`
3123+
#### `k8s_dns_label_safe(value)` / `| k8s_dns_label_safe`
31203124
31213125
Format DNS-safe label (max 63 chars, lowercase, alphanumeric and dashes only).
31223126
@@ -3127,15 +3131,19 @@ Format DNS-safe label (max 63 chars, lowercase, alphanumeric and dashes only).
31273131
31283132
**Example:**
31293133
```jinja
3130-
{# Format DNS label #}
3134+
{# Function syntax #}
31313135
{{ k8s_dns_label_safe(value="My Service Name") }}
31323136
{# Output: my-service-name #}
31333137
3138+
{# Filter syntax #}
3139+
{{ "My Service Name" | k8s_dns_label_safe }}
3140+
{# Output: my-service-name #}
3141+
31343142
{# Use in service names #}
31353143
apiVersion: v1
31363144
kind: Service
31373145
metadata:
3138-
name: {{ k8s_dns_label_safe(value=service_name) }}
3146+
name: {{ service_name | k8s_dns_label_safe }}
31393147
```
31403148
31413149
#### `k8s_env_var_ref(var_name, source, name)`
@@ -3290,26 +3298,30 @@ metadata:
32903298
name: {{ helm_tpl(template="{{ .Release.Name }}-{{ .Chart.Name }}", values={"Release": {"Name": "prod"}, "Chart": {"Name": "webapp"}}) }}
32913299
```
32923300
3293-
#### `k8s_annotation_safe(string)`
3301+
#### `k8s_annotation_safe(value)` / `| k8s_annotation_safe`
32943302
32953303
Sanitize a string for use as a Kubernetes annotation value.
32963304
32973305
**Arguments:**
3298-
- `string` (required): The string to sanitize
3306+
- `value` (required): The string to sanitize
32993307
3300-
**Returns:** Sanitized string safe for annotation values (max 256KB, control chars removed)
3308+
**Returns:** Sanitized string safe for annotation values (max 64KB, control chars replaced with spaces)
33013309
33023310
**Example:**
33033311
```jinja
3304-
{# Sanitize annotation value #}
3305-
{{ k8s_annotation_safe(string="Description with\nnewlines and\ttabs") }}
3312+
{# Function syntax #}
3313+
{{ k8s_annotation_safe(value="Description with\nnewlines and\ttabs") }}
33063314
{# Output: Description with newlines and tabs #}
33073315
3316+
{# Filter syntax #}
3317+
{{ "Description with\nnewlines" | k8s_annotation_safe }}
3318+
{# Output: Description with newlines #}
3319+
33083320
{# In Kubernetes manifest #}
33093321
metadata:
33103322
annotations:
3311-
description: "{{ k8s_annotation_safe(string=description) }}"
3312-
config: "{{ k8s_annotation_safe(string=to_json(config_obj)) }}"
3323+
description: "{{ description | k8s_annotation_safe }}"
3324+
config: "{{ config_obj | to_json | k8s_annotation_safe }}"
33133325
```
33143326
33153327
#### `k8s_quantity_to_bytes(quantity)`

REFACTOR.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -668,22 +668,26 @@ These should NOT become filters (they require context, have side effects, or are
668668

669669
**Commit:** 4399e70
670670

671-
### Phase 12: Kubernetes Functions
671+
### Phase 12: Kubernetes Functions
672672

673-
**Category:** `kubernetes.rs`
673+
**Category:** `filter_functions/kubernetes.rs`
674674

675675
| Function | Filter | Status |
676676
|----------|--------|--------|
677-
| `k8s_label_safe` | `k8s_label_safe` | [ ] |
678-
| `k8s_dns_label_safe` | `k8s_dns_label_safe` | [ ] |
679-
| `k8s_annotation_safe` | `k8s_annotation_safe` | [ ] |
680-
681-
- [ ] Migrate implementations
682-
- [ ] Update unit tests
683-
- [ ] Update integration tests to test filter syntax
684-
- [ ] Update README.md
685-
- [ ] Run `cargo make qa`
686-
- [ ] Update REFACTOR.md with current state
677+
| `k8s_label_safe` | `k8s_label_safe` | [x] |
678+
| `k8s_dns_label_safe` | `k8s_dns_label_safe` | [x] |
679+
| `k8s_annotation_safe` | `k8s_annotation_safe` | [x] |
680+
681+
- [x] Migrate implementations to `src/filter_functions/kubernetes.rs`
682+
- [x] Update unit tests (existing tests still pass)
683+
- [x] Update integration tests to test filter syntax (6 new tests)
684+
- [x] Update README.md with both syntaxes
685+
- [x] Run `cargo make qa`
686+
- [x] Update REFACTOR.md with current state
687+
688+
**Note:** Other Kubernetes functions (`k8s_resource_request`, `k8s_env_var_ref`, `k8s_secret_ref`, `k8s_configmap_ref`, `helm_tpl`, `k8s_quantity_to_bytes`, `k8s_bytes_to_quantity`, `k8s_selector`, `k8s_pod_affinity`, `k8s_toleration`, `k8s_probe`) remain function-only as they don't fit the filter pattern (multi-argument or complex objects).
689+
690+
**Commit:** acfd33d
687691

688692
### Phase 13: Final Cleanup
689693

0 commit comments

Comments
 (0)