Skip to content

Conversation

davidxia
Copy link
Contributor

@davidxia davidxia commented Mar 17, 2025

in RayCluster CRD by marking it with // +optional.
Make it not serialized when empty with omitempty.

This change is backwards compatible on K8s clusters with existing
RayCluster CRD and RayCluster CRs.

  • RayClusters with non-empty RayStartParams will serialize the same as
    before this change.
  • RayClusters with empty RayStartParams will serialize the same as
    before this change: as an empty map, {} in YAML.
  • New behavior: we can kubectl create|apply RayClusters that lack
    RayStartParams in both head and worker groups. Previously the K8s API
    would return validation errors requiring this field to be present.
    When we get these RayClusters back with kubectl get raycluster -o yaml, there's no rayStartParams field present.

See Optional vs. Required in K8s API Conventions doc.

Optional fields have the following properties:

  • They have the +optional comment tag in Go.
  • They are a pointer type in the Go definition (e.g. AwesomeFlag *SomeFlag)
    or have a built-in nil value (e.g. maps and slices).
  • The API server should allow POSTing and PUTing a resource with this field
    unset.

The required changes to the RayCluster CRD YAML can be achieved with only
omitempty, but we also add // +optional as recommended by the doc above.

Signed-off-by: David Xia david@davidxia.com

@davidxia davidxia force-pushed the omitempty-raystartparams branch from a8efa58 to a1e53d9 Compare March 17, 2025 15:57
@davidxia davidxia changed the title addresses TODO in kubectl-plugin about not being able to set empty map [refactor][operator]: set omitempty on RayStartParams Mar 17, 2025
@davidxia davidxia force-pushed the omitempty-raystartparams branch 2 times, most recently from c9781e1 to 80eb350 Compare March 17, 2025 17:32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the important changes are in this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update tests

Comment on lines 89 to 149
// TODO: Look for better workaround/fixes for RayStartParams. Currently using `WithRayStartParams()` requires
// a non-empty map with valid key value pairs and will not populate the field with empty/nil values. This
// isn't ideal as it forces the generated RayCluster yamls to use those parameters.
headRayStartParams := map[string]string{
"dashboard-host": "0.0.0.0",
}
workerRayStartParams := map[string]string{
"metrics-export-port": "8080",
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this now since the map can be empty

@davidxia davidxia force-pushed the omitempty-raystartparams branch 3 times, most recently from 98625b2 to 973af72 Compare March 21, 2025 12:20
@davidxia davidxia force-pushed the omitempty-raystartparams branch 13 times, most recently from aa3243a to 8b0650b Compare March 23, 2025 17:06
@davidxia davidxia changed the title [refactor][operator]: set omitempty on RayStartParams [refactor][operator]: make RayStartParams optional Mar 23, 2025
@davidxia davidxia force-pushed the omitempty-raystartparams branch from 8b0650b to 6359479 Compare March 23, 2025 19:47
Comment on lines 57 to 60
expectedWorkerRayStartParams := map[string]string{
"metrics-export-port": "8080",
}
maps.Copy(expectedWorkerRayStartParams, testRayClusterYamlObject.WorkerRayStartParams)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the hard-coded metrics-export-port now.

Comment on lines -184 to -346
rayStartParams:
metrics-export-port: "8080"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows that when rayStartParams aren't set in the RayClusterApplyConfiguration, the field is absent from the serialized YAML.

@davidxia davidxia force-pushed the omitempty-raystartparams branch 3 times, most recently from 05f6a13 to 557b90a Compare March 24, 2025 15:36
* `RayClusters` with `rayStartParams: {}` will continue to be serialized with
  the empty map.
* `RayClusters` without `rayStartParams` will be serialized without the field.

This prevents a backwards-incompatible change with RayClusters that use the
autoscaler with Ray versions earlier than 2.45.0 which lack this change
ray-project/ray#51954.

Signed-off-by: David Xia <david@davidxia.com>
@davidxia davidxia force-pushed the omitempty-raystartparams branch from e940dbe to b1c0d28 Compare May 10, 2025 14:43
@davidxia
Copy link
Contributor Author

@kevin85421 I think b1c0d28 makes backwards compatible.

@kevin85421 kevin85421 merged commit bf8a931 into ray-project:master May 11, 2025
24 checks passed
@kevin85421 kevin85421 mentioned this pull request May 11, 2025
2 tasks
@kevin85421
Copy link
Member

Open a follow up issue: #3580

davidxia added a commit to davidxia/kuberay that referenced this pull request May 13, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request May 13, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request May 13, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
@davidxia davidxia deleted the omitempty-raystartparams branch May 22, 2025 12:26
pawelpaszki pushed a commit to opendatahub-io/kuberay that referenced this pull request May 26, 2025
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 1, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 1, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 1, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 1, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 2, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 3, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 3, 2025
No longer needed after ray-project#3202

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 20, 2025
in example YAMLs and tests. `rayStartParams` is optional after ray-project#3202
released in 1.4.0. We comment out with an explanation instead of removing
entirely so users with older RayCluster CRD versions have a hint about the
incompatibility.

Signed-off-by: David Xia <david@davidxia.com>
davidxia added a commit to davidxia/kuberay that referenced this pull request Jun 23, 2025
in example YAMLs and tests. `rayStartParams` is optional after ray-project#3202
released in 1.4.0. We comment out with an explanation instead of removing
entirely so users with older RayCluster CRD versions have a hint about the
incompatibility.

Signed-off-by: David Xia <david@davidxia.com>
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.

5 participants