[TAS][Webhook 2/2] Deliver node labels to Ray workers through admission webhooks #5300
<!-- BUGBOT_REVIEW -->
<!-- BUGBOT_REVIEW_STALE -->
Stale Bugbot comment from a previous run.
Webhooks skip single-namespace install check
Medium Severity
<!-- DESCRIPTION START -->webhooks.enabled is documented as unsupported with singleNamespaceInstall, but unlike nodeEventForwarder the chart never fails that combination. Helm still writes cluster-scoped webhook configs and puts nodes get on the namespaced Role, which cannot grant Node access, so the binding webhook cannot read node labels and topology workers never receive them.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 402d9755-a3a9-410d-a9d5-cf32630b895f -->
<!-- LOCATIONS START
helm-chart/kuberay-operator/templates/_helpers.tpl#L177-L183
helm-chart/kuberay-operator/templates/webhooks.yaml#L1-L5
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
helm-chart/kuberay-operator/templates/webhooks.yaml#L1-L5</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmMwMTUwMjAyLTNiNjEtNDYzMi05NTAwLTUzZDk4YzU2ZDM1ZCIsImVuY3J5cHRpb25LZXkiOiJqeDJDLUVqN3RIWTBvX250Nk9TSnpMeUZsTVVsTzRyS2c4ZW5nQWl1MlNRIiwiYnJhbmNoIjoibGFiZWwtcHJvcC13ZWJob29rIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmMwMTUwMjAyLTNiNjEtNDYzMi05NTAwLTUzZDk4YzU2ZDM1ZCIsImVuY3J5cHRpb25LZXkiOiJqeDJDLUVqN3RIWTBvX250Nk9TSnpMeUZsTVVsTzRyS2c4ZW5nQWl1MlNRIiwiYnJhbmNoIjoibGFiZWwtcHJvcC13ZWJob29rIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTMwMCwiY29tbWl0U2hhIjoiOTVlZTdmYWJjYTg2MDM2ZDVlZmJkOGZiZjYzYjFiZTNmZjdmZjc2OCIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit 95ee7fabca86036d5efbd8fbf63b1be3ff7ff768. Configure here.</sup>
I don't think we should support this for singleNamespaceInstall, since Nodes are cluster-scoped.
Similar to line 149.
I think cert-manager shouldn't be required, users can also provide their own certificates. We could expose more fields to let users configure the webhook service as well. I think we can treat this as a follow-up.
I think it would be better to put these resources under a dedicated directory and split them into multiple files rather than keeping everything in a single file.
For example:
admission-webhooks/
service.yaml
issuer.yaml
certificate.yaml
mutating-webhook.yaml
validating-webhook.yaml
This would make the webhook-related resources easier to find and maintain.
if strings.ToLower(os.Getenv("ENABLE_WEBHOOKS")) == "true" {
nit
Is there a reason we use Ignore here? If the binding webhook fails, the Pod will still be bound, but without the RAY_NODE_LABELS_JSON. It will eventually fail when the container starts, right?
I think this is only needed for TopologyLabelDelivery. Maybe we can add if condition, to only render this when the TopologyLabelDelivery feature gate is enabled.
Maybe use ray.io/node-type: worker instead? Since we only check the workerGroup.
The informer cache only caches Ray pods with ray.io/node-type, so getPodMetadata will hit the API server (i.e. w.APIReader.Get(ctx, key, podMeta)) every time for non-Ray Pods. That amount of GET requests isn't very scalable, we should check the RayCluster informer cache using the bindings Pod name/namespace to see if there's a matching RayCluster with label mappings set - if not then we just pass-through.
is it correct to reject/error node labels withh empty values? is that ever a valid label
done
sounds good
sounds good-- done
done
Prefix match can drop node labels
Medium Severity
<!-- DESCRIPTION START -->labelRefsGroupForPod returns the first RayCluster/worker group whose generated name prefix matches the pod, and a later label mismatch admits the binding with no labels and no RequiredNodeLabelMissing event. Distinct cluster/group pairs can share that prefix, including common names such as cluster prod group ray-gpu versus cluster prod-ray group gpu, or long names truncated by PodName. The create webhook still prepares those workers, so they exit before ray start and crash-loop.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 7f852993-c3e1-4875-baf6-02e8494b9cd1 -->
<!-- LOCATIONS START
ray-operator/pkg/webhooks/v1/pod_binding_webhook.go#L95-L98
ray-operator/pkg/webhooks/v1/pod_binding_webhook.go#L125-L141
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
ray-operator/pkg/webhooks/v1/pod_binding_webhook.go#L125-L141</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjIzZDQ1YjM0LTQzMGItNDRiNC1hOTkyLTk4ODMyZDQwMTMyOSIsImVuY3J5cHRpb25LZXkiOiJMMWl5dTVfLXByd3AxcG5WNHI2RlVnUEhHVWlBWXBuWlVYeFd6dmdIRnl3IiwiYnJhbmNoIjoibGFiZWwtcHJvcC13ZWJob29rIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwcm92aWRlciI6ImdpdGh1YiJ9fQ" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjIzZDQ1YjM0LTQzMGItNDRiNC1hOTkyLTk4ODMyZDQwMTMyOSIsImVuY3J5cHRpb25LZXkiOiJMMWl5dTVfLXByd3AxcG5WNHI2RlVnUEhHVWlBWXBuWlVYeFd6dmdIRnl3IiwiYnJhbmNoIjoibGFiZWwtcHJvcC13ZWJob29rIiwicmVwb093bmVyIjoicmF5LXByb2plY3QiLCJyZXBvTmFtZSI6Imt1YmVyYXkiLCJwck51bWJlciI6NTMwMCwiY29tbWl0U2hhIjoiMTIyNGViZjNhOTdjMjYxNWU3ODMyODM2ZjkwYzk0NTZmMDNhYzE1NiIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by Cursor Bugbot for commit 1224ebf3a97c2615e7832836f90c9456f03ac156. Configure here.</sup>
<!-- BUGBOT_REVIEW -->
<!-- BUGBOT_REVIEW_STALE -->
Stale Bugbot comment from a previous run.
This webhook intercepts every pods/binding in the cluster. As such, with Fail, any operator outage, even a rollout, rejects every bindings in the cluster until it is recovered. On the other hand, with Ignore, only the workers that needed labels are affected: they bind without the annotation, exit before ray start, and get a RequiredNodeLabelMissing event.
done
good point-- done
ah good catch-- dropped this check
fixed
Should we check like IsQualifiedName or anything for the Ray or node label here? There is validation for the Ray label that will fail at runtime, but wondering if we should check anything here (i.e. disallowed chars included, must be valid k8s format, etc.) to fail fast
do we need to check features.Enabled(features.NodeLabelDelivery) here?
same comment, should we check: features.Enabled(features.NodeLabelDelivery)
The node label format is checked for the labels that gets written into allowedNodeLabels. Initially didn't have the check for Ray labels because I didn't see an issue with users setting whatever they want for ray labels. But if the ray start already enforce this, then it makes sense to add a check here.
done
sounds good-- added gates to {raycluster, rayservice, rayjob}_webhook.go
done
Sounds good, yeah we check all ray node labels here: https://github.com/ray-project/ray/blob/1331e57a55ef2c1ec31733b6b0d1ce77d610effe/python/ray/_private/label_utils.py#L123 using these rules: https://github.com/ray-project/ray/blob/1331e57a55ef2c1ec31733b6b0d1ce77d610effe/python/ray/_private/label_utils.py#L123, so node labels and ray labels should follow same format
sorry think my comment was misleading, we don't want the outer feature gate check here because then labelRefs aren't validated when the feature is disabled - which they should be and rejected. Here it should be:
if err := validateLabelRefs(&rayCluster.Spec, rayCluster.Annotations, w.AllowedNodeLabels, field.NewPath("spec")); err != nil {
allErrs = append(allErrs, err)
}
and in label_refs_validation.gothere should be a check like:
if !features.Enabled(features.NodeLabelDelivery) {
return field.Forbidden(path, "requires the NodeLabelDelivery feature gate to be enabled")
}
after line 24:
path := base.Child("workerGroupSpecs").Index(i).Child("labelRefs"). The expected behavior is:
1. No label refs -> do nothing regardless of feature gate
2. User sets labelRefs and NodeLabelDelivery feature is disabled -> reject with message
3. User sets labelRefs and NodeLabelDelivery feature is enabled -> validates normally, checks qualified name, etc.
should we do:
if errs := validation.IsQualifiedName(nodeLabel); len(errs) > 0 {
return field.Invalid(fieldPathRef, nodeLabel, strings.Join(errs, "; "))
}
here too
LGTM!
@cursor review
<!-- BUGBOT_REVIEW -->
<!-- BUGBOT_REVIEW_STALE -->
Stale Bugbot comment from a previous run.
Sorry for the delayed review. I was down with the flu for the past few days. I've reviewed the non-webhook files, and LGTM!
I'll finish reviewing the remaining webhook-related files today.
ryanaoleary
martinlhw
<!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. -->
Why are these changes needed?
This is the second and last PR of the series adding device-agnostic node label delivery webhook. #5260 added the API:
workerGroupSpecs[].labelRefsand theallowedNodeLabelsoperator config; this PR adds the delivery. Each worker pod receives the actual labels that are attainable in the kubernetes node after it's bound to. The feature is behind the alphaNodeLabelDelivery.gate and requires the operator to run with webhooks (ENABLE_WEBHOOKS).What this PR adds
1.
labelRefsvalidation in the existing validating webhooks, rejecting invalid worker groups at apply time. Rules invalidateLabelRefs, each shown with its message in the rejection table below.2. Reconciler checks rejecting
labelRefswhen the operator cannot deliver them. Rules inValidateRayClusterSpec.3. Two mutating webhooks. At pod CREATE, the worker's generated
ray startis wrapped to readRAY_NODE_LABELS_JSONfrom the pod annotationray.io/node-labelsand pass it as--labels-file. At pod binding, the bound node's referenced labels are written into that annotation; if any is missing, nothing is delivered, aRequiredNodeLabelMissingevent is recorded, and the container exits beforeray start.4. RBAC
nodes get. Kustomize webhook manifests and the objectSelector patch. Helm support behindwebhooks.enabled.Related issue number
N/A
<!-- For example: "Closes #1234" -->
Labels
<!-- Please add the appropriate labels to this PR. -->
doc-updates-requiredlabel.breaking-changelabel.Checks
- [x] Unit tests
- [x] Manual tests
- [ ] This PR is not tested :(
<!-- If you selected "Manual tests" above, please fill in the section below. Otherwise you can remove it. -->
Manual test instructions
Summary: On a kind cluster with labeled nodes: a worker with
labelRefsgets its node's labels as Ray node labels, a worker on a node missing a label is withheld with an event, admission rejects bad specs, other pods are untouched.1. Cluster, cert-manager, labeled nodes, operator with webhooks, allowlist and the gate on
2. Happy path.
traindelivers the clique asray.io/accelerator-domainand the zone under its own key, one worker per clique node.plainhas nolabelRefs.3. Missing label is withheld. Same
traingroup pinned totas-worker3.4. Admission rejections. Apply
topoagain with--dry-run=serverafter each edit to thetraingroup.| edit | error |
|---|---|
|
fieldPath: metadata.labels['cloud.google.com/gke-nodepool']|labelRefs[0].valueFrom.nodeRef.fieldPath: Forbidden: node label "cloud.google.com/gke-nodepool" is not in the operator's allowedNodeLabels||
fieldPath: metadata.annotations['topology.kubernetes.io/zone']|labelRefs[1].valueFrom.nodeRef.fieldPath: Invalid value: ... only metadata.labels['<key>'] is supported||
fieldPath: metadata.labels['bad key!']|labelRefs[1].valueFrom.nodeRef.fieldPath: Invalid value: "bad key!": name part must consist of alphanumeric characters, ...||
name: ray zone!|labelRefs[0].name: Invalid value: "ray zone!": ...|| both refs
name: ray.io/zone|labelRefs[1]: Duplicate value: "ray.io/zone"||
labels: {ray.io/accelerator-domain: static}on the group |labelRefs[0]: Forbidden: Ray label "ray.io/accelerator-domain" is also set in labels; ...||
rayStartParams: {labels-file: /x.yaml}(orlabels) |labelRefs: Forbidden: cannot be combined with rayStartParams labels-file||
env: [{name: RAY_NODE_LABELS_JSON, value: "{}"}]on the worker container |labelRefs: Forbidden: cannot be combined with the RAY_NODE_LABELS_JSON env var in the pod template; ...||
metadata.annotations: {ray.io/overwrite-container-cmd: "true"}on the RayCluster |labelRefs: Forbidden: cannot be combined with the ray.io/overwrite-container-cmd annotation; ...||
command: ["ray start --block"]on the worker container |labelRefs: Forbidden: cannot be combined with a container command that runs ray start; ...|| operator upgraded with
--set 'featureGates[0].enabled=false'|labelRefs: Forbidden: requires the NodeLabelDelivery feature gate to be enabled; the chart also stops rendering the pod webhooks |Field paths are shown without the
spec.workerGroupSpecs[0].prefix.5. Non-worker pods are not affected