fix(kuberay): preserve useful characters when truncating K8s label values#356
Conversation
|
@peterroelants could you please update the PR description to something more concise (or I could do it if you're ok with it) I'm a bit hesitant about this fix since the initial truncation may drop a lot of useful characters. Imagine this input string: If the problem is with just the very last character then perhaps we could fix just it? It seems like how we handle it with We should also update our test suite with the correct k8s regexp to prevent this kind of problems in the future. Ideally if we verify regex matching at label creation time as well. |
7b7eb9e to
0a27101
Compare
…lues `normalize_k8s_label_values` stripped leading/trailing non-alphanumeric characters before truncating to 63 chars. For long inputs (e.g. git branch names used as `dagster/git-branch`-style labels), truncation could then land on `_`, `-`, or `.` and the resulting label would fail K8s's label-value regex `(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?`, causing RayCluster creation to fail with HTTP 422. Split the leading/trailing strip into two steps around the truncation: strip leading non-alphanumerics (so a leading `_`/`.` run doesn't eat the 63-char budget), truncate to 63, then strip trailing non-alphanumerics (handling whatever character truncation lands on). Also validate the final value against the K8s label-value regex and raise if it doesn't match, so future regressions in this function surface at normalize time instead of at the K8s API. Extend the tests with leading `_`/`.` runs and the §-style leading-garbage case from the PR review, assert the K8s label-value regex against every normalized output, and cover the validation path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0a27101 to
3ae2736
Compare
|
@danielgafni I should've addressed your comments |
Great, you're welcome. Btw, I don't think I have merge permissions on this, so I'll leave merging this in up to you. |
Problem
normalize_k8s_label_valuesstrips leading/trailing non-alphanumeric chars before truncating to 63. For long inputs (e.g. a branch name stuck intodagster/git-branch), the 63rd character can be_,-, or., which fails the K8s label-value regex(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?. This breaksRayClusterResourcecreation with HTTP 422, cascading into a 404 at cleanup.Fix
Split the leading/trailing strip into two steps around the truncation:
_/.run doesn't eat the 63-char budget on characters we'd immediately strip anyway.Then validate the result against the K8s label-value regex and raise if it doesn't match, so any future regression in this function surfaces at normalize time instead of at the K8s API.
Tests
test_normalize_k8s_label_values_truncated_tail_is_alphanumericis extended with long leading_/.runs and the§-style leading-garbage case from the review.test_normalize_k8s_label_values_preserves_useful_tail_after_leading_garbagepins the "useful tail survives" property.test_normalize_k8s_label_values_rejects_unexpectedly_invalid_outputpatches the trailing-strip to a no-op and asserts the K8s-regex validation raises.