Skip to content

feat(inflection): add dns_1123() for Kubernetes DNS-1123 label normalization#97

Merged
pyramation merged 1 commit into
mainfrom
feat/inflection-dns-1123
Jul 11, 2026
Merged

feat(inflection): add dns_1123() for Kubernetes DNS-1123 label normalization#97
pyramation merged 1 commit into
mainfrom
feat/inflection-dns-1123

Conversation

@pyramation

Copy link
Copy Markdown
Contributor

Summary

Adds inflection.dns_1123(text) — a single, readable SQL function that normalizes an arbitrary string into a Kubernetes DNS-1123 label. Downstream (constructive-db) derives Knative/K8s object names (<slug>-secrets, <slug>-config, service names) and currently hand-builds this exact regexp chain as inline SQL-AST nodes, producing an unreadable nested blob. Consolidating the logic into one named function lets callers emit a single inflection.dns_1123(slug) call.

None of the existing slugify/pg_slugify/dashed functions fit: they keep underscores (\w), have no 63-char label cap, and don't do the :-- namespacing K8s labels need.

inflection.dns_1123(value) =
  lower(value)
    |> replace(':', '--')                    -- keep namespaced-identifier boundary
    |> replace('_', '-')
    |> regexp_replace('[^a-z0-9-]', '', 'g')  -- strip invalid chars
    |> regexp_replace('^-+|-+$', '', 'g')     -- trim leading/trailing hyphens
    |> left(63)                               -- DNS label limit
    |> regexp_replace('[^a-z0-9]+$', '')      -- drop trailing '-' left by truncation

Examples: my_servicemy-service, org:apiorg--api, Hello, World!helloworld, 'a'×80'a'×63.

STRICT IMMUTABLE. 10 case tests added. pgpm package also synced the bundle/control/Makefile to the already-current 0.30.0 (they lagged at 0.15.5).

Link to Devin session: https://app.devin.ai/sessions/f4e36ac1d5854101838e6825df191c99
Requested by: @pyramation

…ization

Single readable SQL function that lowercases, maps ':' to '--' and '_' to '-', strips invalid chars, trims hyphens, caps at 63 chars (DNS label limit), and drops trailing non-alphanumerics after truncation. Mirrors the TS toK8sName() used to derive Knative/K8s object names.
@pyramation pyramation self-assigned this Jul 11, 2026
@devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation pyramation merged commit 6362a2f into main Jul 11, 2026
23 checks passed
@pyramation pyramation deleted the feat/inflection-dns-1123 branch July 11, 2026 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant