Skip to content

Commit 35c6ad7

Browse files
committed
[CRD][RayJob] Define new DeletionStrategy in RayJob CRD
Signed-off-by: wei-chenglai <[email protected]>
1 parent e37b70c commit 35c6ad7

File tree

12 files changed

+1025
-133
lines changed

12 files changed

+1025
-133
lines changed

docs/reference/api.md

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,29 @@ _Appears in:_
5555

5656

5757

58-
#### DeletionPolicy
58+
#### DeletionCondition
59+
5960

6061

62+
DeletionCondition specifies the trigger conditions for a deletion action.
6163

6264

6365

66+
_Appears in:_
67+
- [DeletionRule](#deletionrule)
68+
69+
| Field | Description | Default | Validation |
70+
| --- | --- | --- | --- |
71+
| `ttlSecondsAfterFinished` _integer_ | TTLSecondsAfterFinished is the time in seconds from when the JobStatus<br />reaches the specified terminal state to when this deletion action should be triggered.<br />The value must be a non-negative integer. | 0 | Minimum: 0 <br /> |
72+
73+
74+
#### DeletionPolicy
75+
76+
77+
78+
DeletionPolicy is the legacy single-stage deletion policy.
79+
Deprecated: This struct is part of the legacy API. Use DeletionRule for new configurations.
80+
6481

6582

6683
_Appears in:_
@@ -81,14 +98,54 @@ _Underlying type:_ _string_
8198

8299
_Appears in:_
83100
- [DeletionPolicy](#deletionpolicy)
101+
- [DeletionRule](#deletionrule)
102+
103+
104+
105+
#### DeletionRule
106+
84107

85108

109+
DeletionRule defines a single deletion action and its trigger condition.
110+
This is the new, recommended way to define deletion behavior.
111+
112+
113+
114+
_Appears in:_
115+
- [DeletionStrategy](#deletionstrategy)
116+
117+
| Field | Description | Default | Validation |
118+
| --- | --- | --- | --- |
119+
| `policy` _[DeletionPolicyType](#deletionpolicytype)_ | The policy to take when the condition is met. This field is required. | | Enum: [DeleteCluster DeleteWorkers DeleteSelf DeleteNone] <br /> |
120+
| `condition` _[DeletionCondition](#deletioncondition)_ | The condition under which this deletion rule is triggered. This field is required. | | |
121+
86122

87123
#### DeletionStrategy
88124

89125

90126

127+
DeletionStrategy defines the deletion policies for a RayJob.
128+
It allows for fine-grained control over resource cleanup after a job finishes.
129+
130+
131+
Legacy fields `onSuccess` and `onFailure` are still supported for backward compatibility,
132+
but it is highly recommended to migrate to the new `deletionRules` field.
133+
134+
135+
Notes:
136+
- When this block is set, you must configure **either**
137+
(a) BOTH `onSuccess` and `onFailure` policies,
138+
OR
139+
(b) the `deletionRules` field (which may be empty, in which case no deletion will occur).
140+
- `onSuccess` / `onFailure` must NOT be used together with `deletionRules`.
141+
- `onSuccess` and `onFailure` are **deprecated** and planned for removal in a future release.
142+
143+
144+
Validation rules:
145+
1. Prevent mixing legacy and new fields
146+
91147

148+
2. Require either both legacy fields or deletionRules presence
92149

93150

94151

@@ -97,8 +154,9 @@ _Appears in:_
97154

98155
| Field | Description | Default | Validation |
99156
| --- | --- | --- | --- |
100-
| `onSuccess` _[DeletionPolicy](#deletionpolicy)_ | | | |
101-
| `onFailure` _[DeletionPolicy](#deletionpolicy)_ | | | |
157+
| `onSuccess` _[DeletionPolicy](#deletionpolicy)_ | OnSuccess is the deletion policy for a successful RayJob.<br />Deprecated: Use `deletionRules` instead for more flexible, multi-stage deletion strategies.<br />This field will be removed in a future release. | | |
158+
| `onFailure` _[DeletionPolicy](#deletionpolicy)_ | OnFailure is the deletion policy for a failed RayJob.<br />Deprecated: Use `deletionRules` instead for more flexible, multi-stage deletion strategies.<br />This field will be removed in a future release. | | |
159+
| `deletionRules` _[DeletionRule](#deletionrule) array_ | DeletionRules is a list of deletion rules, processed based on their trigger conditions.<br />While the rules can be used to define a sequence, if multiple rules are overdue (e.g., due to controller downtime),<br />the most impactful rule (e.g., DeleteCluster) will be executed first to prioritize resource cleanup and cost savings. | | |
102160

103161

104162

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

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

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

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,77 @@ const (
8787

8888
type DeletionPolicyType string
8989

90+
// DeletionStrategy defines the deletion policies for a RayJob.
91+
// It allows for fine-grained control over resource cleanup after a job finishes.
92+
//
93+
// Legacy fields `onSuccess` and `onFailure` are still supported for backward compatibility,
94+
// but it is highly recommended to migrate to the new `deletionRules` field.
95+
//
96+
// Notes:
97+
// - When this block is set, you must configure **either**
98+
// (a) BOTH `onSuccess` and `onFailure` policies,
99+
// OR
100+
// (b) the `deletionRules` field (which may be empty, in which case no deletion will occur).
101+
// - `onSuccess` / `onFailure` must NOT be used together with `deletionRules`.
102+
// - `onSuccess` and `onFailure` are **deprecated** and planned for removal in a future release.
103+
//
104+
// Validation rules:
105+
// 1. Prevent mixing legacy and new fields
106+
//
107+
// +kubebuilder:validation:XValidation:rule="!((has(self.onSuccess) || has(self.onFailure)) && has(self.deletionRules))",message="legacy policies (onSuccess/onFailure) and deletionRules cannot be used together within the same deletionStrategy"
108+
// 2. Require either both legacy fields or deletionRules presence
109+
//
110+
// +kubebuilder:validation:XValidation:rule="((has(self.onSuccess) && has(self.onFailure)) || has(self.deletionRules))",message="deletionStrategy requires either BOTH onSuccess and onFailure, OR the deletionRules field (which may be empty)"
90111
type DeletionStrategy struct {
91-
OnSuccess DeletionPolicy `json:"onSuccess"`
92-
OnFailure DeletionPolicy `json:"onFailure"`
112+
// OnSuccess is the deletion policy for a successful RayJob.
113+
// Deprecated: Use `deletionRules` instead for more flexible, multi-stage deletion strategies.
114+
// This field will be removed in a future release.
115+
// +optional
116+
OnSuccess DeletionPolicy `json:"onSuccess,omitempty"`
117+
118+
// OnFailure is the deletion policy for a failed RayJob.
119+
// Deprecated: Use `deletionRules` instead for more flexible, multi-stage deletion strategies.
120+
// This field will be removed in a future release.
121+
// +optional
122+
OnFailure DeletionPolicy `json:"onFailure,omitempty"`
123+
124+
// DeletionRules is a list of deletion rules, processed based on their trigger conditions.
125+
// While the rules can be used to define a sequence, if multiple rules are overdue (e.g., due to controller downtime),
126+
// the most impactful rule (e.g., DeleteCluster) will be executed first to prioritize resource cleanup and cost savings.
127+
// +optional
128+
// +listType=atomic
129+
DeletionRules []DeletionRule `json:"deletionRules,omitempty"`
130+
}
131+
132+
// DeletionRule defines a single deletion action and its trigger condition.
133+
// This is the new, recommended way to define deletion behavior.
134+
type DeletionRule struct {
135+
// The policy to take when the condition is met. This field is required.
136+
// +kubebuilder:validation:Enum=DeleteCluster;DeleteWorkers;DeleteSelf;DeleteNone
137+
Policy DeletionPolicyType `json:"policy"`
138+
139+
// The condition under which this deletion rule is triggered. This field is required.
140+
Condition DeletionCondition `json:"condition"`
141+
}
142+
143+
// DeletionCondition specifies the trigger conditions for a deletion action.
144+
type DeletionCondition struct {
145+
// The terminal status of the RayJob that triggers this condition. This field is required.
146+
// For the initial implementation, only "SUCCEEDED" and "FAILED" are supported.
147+
// +kubebuilder:validation:Enum=SUCCEEDED;FAILED
148+
JobStatus JobStatus `json:"jobStatus"`
149+
150+
// TTLSecondsAfterFinished is the time in seconds from when the JobStatus
151+
// reaches the specified terminal state to when this deletion action should be triggered.
152+
// The value must be a non-negative integer.
153+
// +kubebuilder:default=0
154+
// +kubebuilder:validation:Minimum=0
155+
// +optional
156+
TTLSecondsAfterFinished int32 `json:"ttlSecondsAfterFinished,omitempty"`
93157
}
94158

159+
// DeletionPolicy is the legacy single-stage deletion policy.
160+
// Deprecated: This struct is part of the legacy API. Use DeletionRule for new configurations.
95161
type DeletionPolicy struct {
96162
// Valid values are 'DeleteCluster', 'DeleteWorkers', 'DeleteSelf' or 'DeleteNone'.
97163
// +kubebuilder:validation:XValidation:rule="self in ['DeleteCluster', 'DeleteWorkers', 'DeleteSelf', 'DeleteNone']",message="the policy field value must be either 'DeleteCluster', 'DeleteWorkers', 'DeleteSelf', or 'DeleteNone'"

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

Lines changed: 36 additions & 0 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: 38 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)