Skip to content

Commit 5c876bb

Browse files
author
Akshay Chitneni
committed
Adding cel validations on trainjob crd
1 parent 126110f commit 5c876bb

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

manifests/v2/base/crds/kubeflow.org_trainjobs.yaml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,14 @@ spec:
197197
They will be merged with the TrainingRuntime values.
198198
type: object
199199
managedBy:
200-
description: |-
201-
ManagedBy is used to indicate the controller or entity that manages a TrainJob.
202-
The value must be either an empty, `kubeflow.org/trainjob-controller` or
203-
`kueue.x-k8s.io/multikueue`. The built-in TrainJob controller reconciles TrainJob which
204-
don't have this field at all or the field value is the reserved string
205-
`kubeflow.org/trainjob-controller`, but delegates reconciling TrainJobs
206-
with a 'kueue.x-k8s.io/multikueue' to the Kueue. The field is immutable.
207-
Defaults to `kubeflow.org/trainjob-controller`
200+
default: kubeflow.org/trainjob-controller
208201
type: string
202+
x-kubernetes-validations:
203+
- message: ManagedBy must be kubeflow.org/trainjob-controller or kueue.x-k8s.io/multikueue
204+
if set
205+
rule: self in ['kubeflow.org/trainjob-controller', 'kueue.x-k8s.io/multikueue']
206+
- message: ManagedBy value is immutable
207+
rule: self == oldSelf
209208
modelConfig:
210209
description: Configuration of the pre-trained and trained model.
211210
properties:
@@ -2733,6 +2732,7 @@ spec:
27332732
type: object
27342733
type: array
27352734
suspend:
2735+
default: false
27362736
description: |-
27372737
Whether the controller should suspend the running TrainJob.
27382738
Defaults to false.
@@ -2941,16 +2941,22 @@ spec:
29412941
description: Reference to the training runtime.
29422942
properties:
29432943
apiGroup:
2944+
default: kubeflow.org
29442945
description: |-
29452946
APIGroup of the runtime being referenced.
29462947
Defaults to `kubeflow.org`.
29472948
type: string
29482949
kind:
2950+
default: ClusterTrainingRuntime
29492951
description: |-
29502952
Kind of the runtime being referenced.
29512953
It must be one of TrainingRuntime or ClusterTrainingRuntime.
29522954
Defaults to ClusterTrainingRuntime.
29532955
type: string
2956+
x-kubernetes-validations:
2957+
- message: ManagedBy must be ClusterTrainingRuntime or TrainingRuntime
2958+
if set
2959+
rule: self in ['ClusterTrainingRuntime', 'TrainingRuntime']
29542960
name:
29552961
description: |-
29562962
Name of the runtime being referenced.
@@ -2963,6 +2969,9 @@ spec:
29632969
required:
29642970
- trainingRuntimeRef
29652971
type: object
2972+
x-kubernetes-validations:
2973+
- message: ManagedBy is required once set
2974+
rule: '!has(oldSelf.managedBy) || has(self.managedBy)'
29662975
status:
29672976
description: Current status of TrainJob.
29682977
properties:

pkg/apis/kubeflow.org/v2alpha1/trainjob_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type TrainJobList struct {
5656
}
5757

5858
// TrainJobSpec represents specification of the desired TrainJob.
59+
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.managedBy) || has(self.managedBy)", message="ManagedBy is required once set"
5960
type TrainJobSpec struct {
6061
// Reference to the training runtime.
6162
TrainingRuntimeRef TrainingRuntimeRef `json:"trainingRuntimeRef"`
@@ -82,6 +83,7 @@ type TrainJobSpec struct {
8283

8384
// Whether the controller should suspend the running TrainJob.
8485
// Defaults to false.
86+
// +kubebuilder:default=false
8587
Suspend *bool `json:"suspend,omitempty"`
8688

8789
// ManagedBy is used to indicate the controller or entity that manages a TrainJob.
@@ -91,6 +93,10 @@ type TrainJobSpec struct {
9193
// `kubeflow.org/trainjob-controller`, but delegates reconciling TrainJobs
9294
// with a 'kueue.x-k8s.io/multikueue' to the Kueue. The field is immutable.
9395
// Defaults to `kubeflow.org/trainjob-controller`
96+
97+
// +kubebuilder:default="kubeflow.org/trainjob-controller"
98+
// +kubebuilder:validation:XValidation:rule="self in ['kubeflow.org/trainjob-controller', 'kueue.x-k8s.io/multikueue']", message="ManagedBy must be kubeflow.org/trainjob-controller or kueue.x-k8s.io/multikueue if set"
99+
// +kubebuilder:validation:XValidation:rule="self == oldSelf", message="ManagedBy value is immutable"
94100
ManagedBy *string `json:"managedBy,omitempty"`
95101
}
96102

@@ -103,11 +109,14 @@ type TrainingRuntimeRef struct {
103109

104110
// APIGroup of the runtime being referenced.
105111
// Defaults to `kubeflow.org`.
112+
// +kubebuilder:default="kubeflow.org"
106113
APIGroup *string `json:"apiGroup,omitempty"`
107114

108115
// Kind of the runtime being referenced.
109116
// It must be one of TrainingRuntime or ClusterTrainingRuntime.
110117
// Defaults to ClusterTrainingRuntime.
118+
// +kubebuilder:default="ClusterTrainingRuntime"
119+
// +kubebuilder:validation:XValidation:rule="self in ['ClusterTrainingRuntime', 'TrainingRuntime']", message="ManagedBy must be ClusterTrainingRuntime or TrainingRuntime if set"
111120
Kind *string `json:"kind,omitempty"`
112121
}
113122

0 commit comments

Comments
 (0)