Skip to content

Commit 63e3b0b

Browse files
authored
[operator] add // +optional to CRD fields with omitempty (#3220)
as recommended by [K8s API Conventions doc][1]. > Note that for backward compatibility, any field that has the `omitempty` struct > tag will be considered to be optional, but this may change in the future and > having the `+optional` comment tag is highly recommended. [1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#optional-vs-required Signed-off-by: David Xia <[email protected]>
1 parent 621a1ad commit 63e3b0b

File tree

1 file changed

+66
-12
lines changed

1 file changed

+66
-12
lines changed

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

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
type RayClusterSpec struct {
1414
// Suspend indicates whether a RayCluster should be suspended.
1515
// A suspended RayCluster will have head pods and worker pods deleted.
16+
// +optional
1617
Suspend *bool `json:"suspend,omitempty"`
1718
// ManagedBy is an optional configuration for the controller or entity that manages a RayCluster.
1819
// The value must be either 'ray.io/kuberay-operator' or 'kueue.x-k8s.io/multikueue'.
@@ -22,47 +23,62 @@ type RayClusterSpec struct {
2223
// The field is immutable.
2324
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="the managedBy field is immutable"
2425
// +kubebuilder:validation:XValidation:rule="self in ['ray.io/kuberay-operator', 'kueue.x-k8s.io/multikueue']",message="the managedBy field value must be either 'ray.io/kuberay-operator' or 'kueue.x-k8s.io/multikueue'"
26+
// +optional
2527
ManagedBy *string `json:"managedBy,omitempty"`
2628
// AutoscalerOptions specifies optional configuration for the Ray autoscaler.
27-
AutoscalerOptions *AutoscalerOptions `json:"autoscalerOptions,omitempty"`
28-
HeadServiceAnnotations map[string]string `json:"headServiceAnnotations,omitempty"`
29+
// +optional
30+
AutoscalerOptions *AutoscalerOptions `json:"autoscalerOptions,omitempty"`
31+
// +optional
32+
HeadServiceAnnotations map[string]string `json:"headServiceAnnotations,omitempty"`
2933
// EnableInTreeAutoscaling indicates whether operator should create in tree autoscaling configs
34+
// +optional
3035
EnableInTreeAutoscaling *bool `json:"enableInTreeAutoscaling,omitempty"`
3136
// GcsFaultToleranceOptions for enabling GCS FT
37+
// +optional
3238
GcsFaultToleranceOptions *GcsFaultToleranceOptions `json:"gcsFaultToleranceOptions,omitempty"`
3339
// HeadGroupSpec is the spec for the head pod
3440
HeadGroupSpec HeadGroupSpec `json:"headGroupSpec"`
3541
// RayVersion is used to determine the command for the Kubernetes Job managed by RayJob
42+
// +optional
3643
RayVersion string `json:"rayVersion,omitempty"`
3744
// WorkerGroupSpecs are the specs for the worker pods
45+
// +optional
3846
WorkerGroupSpecs []WorkerGroupSpec `json:"workerGroupSpecs,omitempty"`
3947
}
4048

4149
// GcsFaultToleranceOptions contains configs for GCS FT
4250
type GcsFaultToleranceOptions struct {
43-
RedisUsername *RedisCredential `json:"redisUsername,omitempty"`
44-
RedisPassword *RedisCredential `json:"redisPassword,omitempty"`
45-
ExternalStorageNamespace string `json:"externalStorageNamespace,omitempty"`
46-
RedisAddress string `json:"redisAddress"`
51+
// +optional
52+
RedisUsername *RedisCredential `json:"redisUsername,omitempty"`
53+
// +optional
54+
RedisPassword *RedisCredential `json:"redisPassword,omitempty"`
55+
// +optional
56+
ExternalStorageNamespace string `json:"externalStorageNamespace,omitempty"`
57+
RedisAddress string `json:"redisAddress"`
4758
}
4859

4960
// RedisCredential is the redis username/password or a reference to the source containing the username/password
5061
type RedisCredential struct {
62+
// +optional
5163
ValueFrom *corev1.EnvVarSource `json:"valueFrom,omitempty"`
52-
Value string `json:"value,omitempty"`
64+
// +optional
65+
Value string `json:"value,omitempty"`
5366
}
5467

5568
// HeadGroupSpec are the spec for the head pod
5669
type HeadGroupSpec struct {
5770
// Template is the exact pod template used in K8s depoyments, statefulsets, etc.
5871
Template corev1.PodTemplateSpec `json:"template"`
5972
// HeadService is the Kubernetes service of the head pod.
73+
// +optional
6074
HeadService *corev1.Service `json:"headService,omitempty"`
6175
// EnableIngress indicates whether operator should create ingress object for head service or not.
76+
// +optional
6277
EnableIngress *bool `json:"enableIngress,omitempty"`
6378
// RayStartParams are the params of the start command: node-manager-port, object-store-memory, ...
6479
RayStartParams map[string]string `json:"rayStartParams"`
6580
// ServiceType is Kubernetes service type of the head service. it will be used by the workers to connect to the head pod
81+
// +optional
6682
ServiceType corev1.ServiceType `json:"serviceType,omitempty"`
6783
}
6884

@@ -71,11 +87,13 @@ type WorkerGroupSpec struct {
7187
// Suspend indicates whether a worker group should be suspended.
7288
// A suspended worker group will have all pods deleted.
7389
// This is not a user-facing API and is only used by RayJob DeletionPolicy.
90+
// +optional
7491
Suspend *bool `json:"suspend,omitempty"`
7592
// we can have multiple worker groups, we distinguish them by name
7693
GroupName string `json:"groupName"`
7794
// Replicas is the number of desired Pods for this worker group. See https://github.com/ray-project/kuberay/pull/1443 for more details about the reason for making this field optional.
7895
// +kubebuilder:default:=0
96+
// +optional
7997
Replicas *int32 `json:"replicas,omitempty"`
8098
// MinReplicas denotes the minimum number of desired Pods for this worker group.
8199
// +kubebuilder:default:=0
@@ -85,15 +103,18 @@ type WorkerGroupSpec struct {
85103
MaxReplicas *int32 `json:"maxReplicas"`
86104
// IdleTimeoutSeconds denotes the number of seconds to wait before the v2 autoscaler terminates an idle worker pod of this type.
87105
// 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.
106+
// +optional
88107
IdleTimeoutSeconds *int32 `json:"idleTimeoutSeconds,omitempty"`
89108
// RayStartParams are the params of the start command: address, object-store-memory, ...
90109
RayStartParams map[string]string `json:"rayStartParams"`
91110
// Template is a pod template for the worker
92111
Template corev1.PodTemplateSpec `json:"template"`
93112
// ScaleStrategy defines which pods to remove
113+
// +optional
94114
ScaleStrategy ScaleStrategy `json:"scaleStrategy,omitempty"`
95115
// NumOfHosts denotes the number of hosts to create per replica. The default value is 1.
96116
// +kubebuilder:default:=1
117+
// +optional
97118
NumOfHosts int32 `json:"numOfHosts,omitempty"`
98119
}
99120

@@ -107,29 +128,38 @@ type ScaleStrategy struct {
107128
type AutoscalerOptions struct {
108129
// Resources specifies optional resource request and limit overrides for the autoscaler container.
109130
// Default values: 500m CPU request and limit. 512Mi memory request and limit.
131+
// +optional
110132
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
111133
// Image optionally overrides the autoscaler's container image. This override is for provided for autoscaler testing and development.
134+
// +optional
112135
Image *string `json:"image,omitempty"`
113136
// ImagePullPolicy optionally overrides the autoscaler container's image pull policy. This override is for provided for autoscaler testing and development.
137+
// +optional
114138
ImagePullPolicy *corev1.PullPolicy `json:"imagePullPolicy,omitempty"`
115139
// SecurityContext defines the security options the container should be run with.
116140
// If set, the fields of SecurityContext override the equivalent fields of PodSecurityContext.
117141
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context/
142+
// +optional
118143
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
119144
// IdleTimeoutSeconds is the number of seconds to wait before scaling down a worker pod which is not using Ray resources.
120145
// Defaults to 60 (one minute). It is not read by the KubeRay operator but by the Ray autoscaler.
146+
// +optional
121147
IdleTimeoutSeconds *int32 `json:"idleTimeoutSeconds,omitempty"`
122148
// UpscalingMode is "Conservative", "Default", or "Aggressive."
123149
// Conservative: Upscaling is rate-limited; the number of pending worker pods is at most the size of the Ray cluster.
124150
// Default: Upscaling is not rate-limited.
125151
// Aggressive: An alias for Default; upscaling is not rate-limited.
126152
// It is not read by the KubeRay operator but by the Ray autoscaler.
153+
// +optional
127154
UpscalingMode *UpscalingMode `json:"upscalingMode,omitempty"`
128155
// Optional list of environment variables to set in the autoscaler container.
156+
// +optional
129157
Env []corev1.EnvVar `json:"env,omitempty"`
130158
// Optional list of sources to populate environment variables in the autoscaler container.
159+
// +optional
131160
EnvFrom []corev1.EnvFromSource `json:"envFrom,omitempty"`
132161
// Optional list of volumeMounts. This is needed for enabling TLS for the autoscaler container.
162+
// +optional
133163
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"`
134164
}
135165

@@ -153,46 +183,62 @@ type RayClusterStatus struct {
153183
// Status reflects the status of the cluster
154184
//
155185
// Deprecated: the State field is replaced by the Conditions field.
186+
// +optional
156187
State ClusterState `json:"state,omitempty"`
157188
// DesiredCPU indicates total desired CPUs for the cluster
189+
// +optional
158190
DesiredCPU resource.Quantity `json:"desiredCPU,omitempty"`
159191
// DesiredMemory indicates total desired memory for the cluster
192+
// +optional
160193
DesiredMemory resource.Quantity `json:"desiredMemory,omitempty"`
161194
// DesiredGPU indicates total desired GPUs for the cluster
195+
// +optional
162196
DesiredGPU resource.Quantity `json:"desiredGPU,omitempty"`
163197
// DesiredTPU indicates total desired TPUs for the cluster
198+
// +optional
164199
DesiredTPU resource.Quantity `json:"desiredTPU,omitempty"`
165200
// LastUpdateTime indicates last update timestamp for this cluster status.
166201
// +nullable
167202
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`
168203
// StateTransitionTimes indicates the time of the last state transition for each state.
204+
// +optional
169205
StateTransitionTimes map[ClusterState]*metav1.Time `json:"stateTransitionTimes,omitempty"`
170206
// Service Endpoints
207+
// +optional
171208
Endpoints map[string]string `json:"endpoints,omitempty"`
172209
// Head info
210+
// +optional
173211
Head HeadInfo `json:"head,omitempty"`
174212
// Reason provides more information about current State
213+
// +optional
175214
Reason string `json:"reason,omitempty"`
176215

177216
// Represents the latest available observations of a RayCluster's current state.
178217
// +patchMergeKey=type
179218
// +patchStrategy=merge
180219
// +listType=map
181220
// +listMapKey=type
221+
// +optional
182222
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
183223

184224
// ReadyWorkerReplicas indicates how many worker replicas are ready in the cluster
225+
// +optional
185226
ReadyWorkerReplicas int32 `json:"readyWorkerReplicas,omitempty"`
186227
// AvailableWorkerReplicas indicates how many replicas are available in the cluster
228+
// +optional
187229
AvailableWorkerReplicas int32 `json:"availableWorkerReplicas,omitempty"`
188230
// DesiredWorkerReplicas indicates overall desired replicas claimed by the user at the cluster level.
231+
// +optional
189232
DesiredWorkerReplicas int32 `json:"desiredWorkerReplicas,omitempty"`
190233
// MinWorkerReplicas indicates sum of minimum replicas of each node group.
234+
// +optional
191235
MinWorkerReplicas int32 `json:"minWorkerReplicas,omitempty"`
192236
// MaxWorkerReplicas indicates sum of maximum replicas of each node group.
237+
// +optional
193238
MaxWorkerReplicas int32 `json:"maxWorkerReplicas,omitempty"`
194239
// observedGeneration is the most recent generation observed for this RayCluster. It corresponds to the
195240
// RayCluster's generation, which is updated on mutation by the API Server.
241+
// +optional
196242
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
197243
}
198244

@@ -224,9 +270,13 @@ const (
224270

225271
// HeadInfo gives info about head
226272
type HeadInfo struct {
227-
PodIP string `json:"podIP,omitempty"`
228-
ServiceIP string `json:"serviceIP,omitempty"`
229-
PodName string `json:"podName,omitempty"`
273+
// +optional
274+
PodIP string `json:"podIP,omitempty"`
275+
// +optional
276+
ServiceIP string `json:"serviceIP,omitempty"`
277+
// +optional
278+
PodName string `json:"podName,omitempty"`
279+
// +optional
230280
ServiceName string `json:"serviceName,omitempty"`
231281
}
232282

@@ -259,11 +309,14 @@ const (
259309
// +genclient
260310
type RayCluster struct {
261311
// Standard object metadata.
262-
metav1.TypeMeta `json:",inline"`
312+
metav1.TypeMeta `json:",inline"`
313+
// +optional
263314
metav1.ObjectMeta `json:"metadata,omitempty"`
264315

265316
// Specification of the desired behavior of the RayCluster.
266-
Spec RayClusterSpec `json:"spec,omitempty"`
317+
// +optional
318+
Spec RayClusterSpec `json:"spec,omitempty"`
319+
// +optional
267320
Status RayClusterStatus `json:"status,omitempty"`
268321
}
269322

@@ -272,6 +325,7 @@ type RayCluster struct {
272325
// RayClusterList contains a list of RayCluster
273326
type RayClusterList struct {
274327
metav1.TypeMeta `json:",inline"`
328+
// +optional
275329
metav1.ListMeta `json:"metadata,omitempty"`
276330
Items []RayCluster `json:"items"`
277331
}

0 commit comments

Comments
 (0)