Skip to content

Commit ee7b3ba

Browse files
committed
Fix comments
Signed-off-by: Ryan O'Leary <ryanaoleary@google.com>
1 parent d75cfee commit ee7b3ba

File tree

15 files changed

+143
-289
lines changed

15 files changed

+143
-289
lines changed

docs/reference/api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ _Appears in:_
138138
| `template` _[PodTemplateSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#podtemplatespec-v1-core)_ | Template is the exact pod template used in K8s deployments, statefulsets, etc. | | |
139139
| `headService` _[Service](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#service-v1-core)_ | HeadService is the Kubernetes service of the head pod. | | |
140140
| `enableIngress` _boolean_ | EnableIngress indicates whether operator should create ingress object for head service or not. | | |
141+
| `resources` _object (keys:string, values:string)_ | Resources specifies the resource quantities for the head group.<br />These values override the resources passed to `rayStartParams` for the group, but<br />have no effect on the resources set at the K8s Pod container level. | | |
141142
| `labels` _object (keys:string, values:string)_ | Labels specifies the Ray node labels for the head group.<br />These labels will also be added to the Pods of this head group and override the `--labels`<br />argument passed to `rayStartParams`. | | |
142143
| `rayStartParams` _object (keys:string, values:string)_ | RayStartParams are the params of the start command: node-manager-port, object-store-memory, ... | | |
143144
| `serviceType` _[ServiceType](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#servicetype-v1-core)_ | ServiceType is Kubernetes service type of the head service. it will be used by the workers to connect to the head pod | | |
@@ -418,6 +419,7 @@ _Appears in:_
418419
| `minReplicas` _integer_ | MinReplicas denotes the minimum number of desired Pods for this worker group. | 0 | |
419420
| `maxReplicas` _integer_ | MaxReplicas denotes the maximum number of desired Pods for this worker group, and the default value is maxInt32. | 2147483647 | |
420421
| `idleTimeoutSeconds` _integer_ | IdleTimeoutSeconds denotes the number of seconds to wait before the v2 autoscaler terminates an idle worker pod of this type.<br />This value is only used with the Ray Autoscaler enabled and defaults to the value set by the AutoscalingConfig if not specified for this worker group. | | |
422+
| `resources` _object (keys:string, values:string)_ | Resources specifies the resource quantities for this worker group.<br />These values override the resources passed to `rayStartParams` for the group, but<br />have no effect on the resources set at the K8s Pod container level. | | |
421423
| `labels` _object (keys:string, values:string)_ | Labels specifies the Ray node labels for this worker group.<br />These labels will also be added to the Pods of this worker group and override the `--labels`<br />argument passed to `rayStartParams`. | | |
422424
| `rayStartParams` _object (keys:string, values:string)_ | RayStartParams are the params of the start command: address, object-store-memory, ... | | |
423425
| `template` _[PodTemplateSpec](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#podtemplatespec-v1-core)_ | Template is a pod template for the worker | | |

helm-chart/kuberay-operator/crds/ray.io_rayclusters.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helm-chart/kuberay-operator/crds/ray.io_rayjobs.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helm-chart/kuberay-operator/crds/ray.io_rayservices.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ray-operator/apis/ray/v1/raycluster_types.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ type HeadGroupSpec struct {
7676
// +optional
7777
EnableIngress *bool `json:"enableIngress,omitempty"`
7878
// Resources specifies the resource quantities for the head group.
79-
// These values override the resources passed to `rayStartParams` for the group.
79+
// These values override the resources passed to `rayStartParams` for the group, but
80+
// have no effect on the resources set at the K8s Pod container level.
8081
// +optional
81-
Resources corev1.ResourceList `json:"resources,omitempty"`
82+
Resources map[string]string `json:"resources,omitempty"`
8283
// Labels specifies the Ray node labels for the head group.
8384
// These labels will also be added to the Pods of this head group and override the `--labels`
8485
// argument passed to `rayStartParams`.
@@ -116,9 +117,10 @@ type WorkerGroupSpec struct {
116117
// +optional
117118
IdleTimeoutSeconds *int32 `json:"idleTimeoutSeconds,omitempty"`
118119
// Resources specifies the resource quantities for this worker group.
119-
// These values override the resources passed to `rayStartParams` for the group.
120+
// These values override the resources passed to `rayStartParams` for the group, but
121+
// have no effect on the resources set at the K8s Pod container level.
120122
// +optional
121-
Resources corev1.ResourceList `json:"resources,omitempty"`
123+
Resources map[string]string `json:"resources,omitempty"`
122124
// Labels specifies the Ray node labels for this worker group.
123125
// These labels will also be added to the Pods of this worker group and override the `--labels`
124126
// argument passed to `rayStartParams`.

ray-operator/apis/ray/v1/zz_generated.deepcopy.go

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ray-operator/config/crd/bases/ray.io_rayclusters.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ray-operator/config/crd/bases/ray.io_rayjobs.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ray-operator/config/crd/bases/ray.io_rayservices.yaml

Lines changed: 2 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ray-operator/controllers/ray/common/pod.go

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ func DefaultHeadPodTemplate(ctx context.Context, instance rayv1.RayCluster, head
172172
// This ensures privilege of KubeRay users are contained within the namespace of the RayCluster.
173173
podTemplate.ObjectMeta.Namespace = instance.Namespace
174174

175-
// Reconcile top-level Resources for head group with rayStartParams.
176-
reconcileRayStartParamsResources(headSpec.RayStartParams, headSpec.Resources)
175+
// Update rayStartParams with top-level Resources for head group.
176+
updateRayStartParamsResources(ctx, headSpec.RayStartParams, headSpec.Resources)
177177

178-
// Reconcile top-level Labels for head group with `--labels` in rayStartParams.
179-
reconcileRayStartParamsLabels(headSpec.RayStartParams, headSpec.Labels)
178+
// Update --labels` in rayStartParams with top-level Labels for head group.
179+
updateRayStartParamsLabels(headSpec.RayStartParams, headSpec.Labels)
180180

181181
// Merge K8s labels from the Pod template and the top-level `Labels` field.
182182
mergedLabels := mergeLabels(headSpec.Template.ObjectMeta.Labels, headSpec.Labels)
@@ -318,11 +318,11 @@ func DefaultWorkerPodTemplate(ctx context.Context, instance rayv1.RayCluster, wo
318318
// Hence, we set `ObjectMeta.Name` to an empty string, and use GenerateName to prevent name conflicts.
319319
podTemplate.ObjectMeta.Name = ""
320320

321-
// Reconcile top-level Resources for worker group with rayStartParams.
322-
reconcileRayStartParamsResources(workerSpec.RayStartParams, workerSpec.Resources)
321+
// Update rayStartParams with top-level Resources for worker group.
322+
updateRayStartParamsResources(ctx, workerSpec.RayStartParams, workerSpec.Resources)
323323

324-
// Reconcile top-level Labels for worker group with `--labels` in rayStartParams.
325-
reconcileRayStartParamsLabels(workerSpec.RayStartParams, workerSpec.Labels)
324+
// Update --labels` in rayStartParams with top-level Labels for worker group.
325+
updateRayStartParamsLabels(workerSpec.RayStartParams, workerSpec.Labels)
326326

327327
// Merge K8s labels from the Pod template and the top-level `Labels` field.
328328
mergedLabels := mergeLabels(workerSpec.Template.ObjectMeta.Labels, workerSpec.Labels)
@@ -1040,58 +1040,71 @@ func findMemoryReqOrLimit(container corev1.Container) (res *resource.Quantity) {
10401040
return nil
10411041
}
10421042

1043-
// reconcileRayStartParamsLabels reconciles `--labels` in rayStartParams based on group `Labels`.
1044-
func reconcileRayStartParamsLabels(rayStartParams map[string]string, groupLabels map[string]string) {
1045-
if len(groupLabels) > 0 {
1046-
var labels []string
1047-
// Sort label keys for deterministic output.
1048-
keys := make([]string, 0, len(groupLabels))
1049-
for k := range groupLabels {
1050-
keys = append(keys, k)
1051-
}
1052-
sort.Strings(keys)
1043+
// updateRayStartParamsLabels reconciles `--labels` in rayStartParams based on group `Labels`.
1044+
func updateRayStartParamsLabels(rayStartParams map[string]string, groupLabels map[string]string) {
1045+
if len(groupLabels) == 0 {
1046+
return
1047+
}
1048+
var labels []string
1049+
// Sort label keys for deterministic output.
1050+
keys := make([]string, 0, len(groupLabels))
1051+
for k := range groupLabels {
1052+
keys = append(keys, k)
1053+
}
1054+
sort.Strings(keys)
10531055

1054-
for _, k := range keys {
1055-
labels = append(labels, fmt.Sprintf("%s=%s", k, groupLabels[k]))
1056-
}
1057-
// When provided this will override any `--labels` value specified in rayStartParams.
1058-
rayStartParams["labels"] = strings.Join(labels, ",")
1056+
for _, k := range keys {
1057+
labels = append(labels, fmt.Sprintf("%s=%s", k, groupLabels[k]))
10591058
}
1059+
// When provided this will override any `--labels` value specified in rayStartParams.
1060+
rayStartParams["labels"] = strings.Join(labels, ",")
10601061
}
10611062

1062-
// reconcileRayStartParamsResources reconciles rayStartParams based on the top-level `Resources` field.
1063-
func reconcileRayStartParamsResources(rayStartParams map[string]string, topLevelResources corev1.ResourceList) {
1064-
if len(topLevelResources) > 0 {
1065-
// Override relevant rayStartParams fields to ensure consistency.
1066-
rayResourcesJson := make(map[string]float64)
1067-
for name, quantity := range topLevelResources {
1068-
strName := string(name)
1069-
if name == corev1.ResourceCPU {
1070-
rayStartParams["num-cpus"] = strconv.FormatInt(quantity.Value(), 10)
1071-
} else if name == corev1.ResourceMemory {
1072-
rayStartParams["memory"] = strconv.FormatInt(quantity.Value(), 10)
1073-
} else if utils.IsGPUResourceKey(strName) {
1074-
rayStartParams["num-gpus"] = strconv.FormatInt(quantity.Value(), 10)
1075-
} else {
1076-
rayResourcesJson[strName] = quantity.AsApproximateFloat64()
1077-
}
1063+
// updateRayStartParamsResources reconciles rayStartParams based on the top-level `Resources` field.
1064+
func updateRayStartParamsResources(ctx context.Context, rayStartParams map[string]string, groupResources map[string]string) {
1065+
log := ctrl.LoggerFrom(ctx)
1066+
1067+
if len(groupResources) == 0 {
1068+
return
1069+
}
1070+
// Override relevant rayStartParams fields to ensure consistency.
1071+
rayResourcesJson := make(map[string]float64)
1072+
for name, quantity := range groupResources {
1073+
q, err := resource.ParseQuantity(quantity)
1074+
if err != nil {
1075+
log.Info("Skipping resource %s: failed to parse quantity '%s': %v", name, quantity, err)
1076+
continue
10781077
}
10791078

1080-
if len(rayResourcesJson) > 0 {
1081-
jsonBytes, _ := json.Marshal(rayResourcesJson)
1082-
rayStartParams["resources"] = fmt.Sprintf("'%s'", string(jsonBytes))
1079+
if name == string(corev1.ResourceCPU) {
1080+
rayStartParams["num-cpus"] = strconv.FormatInt(q.Value(), 10)
1081+
} else if name == string(corev1.ResourceMemory) {
1082+
rayStartParams["memory"] = strconv.FormatInt(q.Value(), 10)
1083+
} else if utils.IsGPUResourceKey(name) {
1084+
rayStartParams["num-gpus"] = strconv.FormatInt(q.Value(), 10)
1085+
} else {
1086+
rayResourcesJson[name] = q.AsApproximateFloat64()
1087+
}
1088+
}
1089+
1090+
if len(rayResourcesJson) > 0 {
1091+
jsonBytes, err := json.Marshal(rayResourcesJson)
1092+
if err != nil {
1093+
log.Error(err, "Failed to marshal Ray Resources JSON for rayStartParams.")
1094+
return
10831095
}
1096+
rayStartParams["resources"] = fmt.Sprintf("'%s'", string(jsonBytes))
10841097
}
10851098
}
10861099

1087-
// mergeLabels combines labels from a pod template and a top-level `labels` spec,
1100+
// mergeLabels combines labels from a pod template and a group `labels` spec,
10881101
// with the top-level labels field taking precedence.
1089-
func mergeLabels(templateLabels map[string]string, topLevelLabels map[string]string) map[string]string {
1102+
func mergeLabels(templateLabels map[string]string, groupLabels map[string]string) map[string]string {
10901103
merged := make(map[string]string)
10911104
for k, v := range templateLabels {
10921105
merged[k] = v
10931106
}
1094-
for k, v := range topLevelLabels {
1107+
for k, v := range groupLabels {
10951108
merged[k] = v
10961109
}
10971110
return merged

0 commit comments

Comments
 (0)