From 94d41dba5ccffd157a80192786d5fe4fb75b41d6 Mon Sep 17 00:00:00 2001 From: mahdikhashan Date: Mon, 25 Aug 2025 13:13:09 +0200 Subject: [PATCH 1/2] add `retryPolicy` to jobflow type --- pkg/apis/flow/v1alpha1/jobflow_types.go | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pkg/apis/flow/v1alpha1/jobflow_types.go b/pkg/apis/flow/v1alpha1/jobflow_types.go index a3b0c994..dd541562 100644 --- a/pkg/apis/flow/v1alpha1/jobflow_types.go +++ b/pkg/apis/flow/v1alpha1/jobflow_types.go @@ -28,6 +28,8 @@ type JobFlowSpec struct { Flows []Flow `json:"flows,omitempty"` // +optional JobRetainPolicy RetainPolicy `json:"jobRetainPolicy,omitempty"` + // +optional + RetryPolicy *RetryPolicy `json:"retryPolicy,omitempty"` } // Flow defines the dependent of jobs @@ -37,6 +39,8 @@ type Flow struct { Name string `json:"name"` // +optional DependsOn *DependsOn `json:"dependsOn,omitempty"` + // +optional + RetryPolicy *RetryPolicy `json:"retryPolicy,omitempty"` } type DependsOn struct { @@ -46,6 +50,48 @@ type DependsOn struct { Probe *Probe `json:"probe,omitempty"` } +type RetryPolicy struct { + // Maximum number of retries allowed (default: 0 = no retry) + // +optional + // +kubebuilder:validation:Minimum=0 + MaxRetries int32 `json:"maxRetries,omitempty"` + + // +optional + // +kubebuilder:validation:Enum=Always;OnFailure;Never + Policy RetryStrategy `json:"policy,omitempty"` + + // +optional + Backoff *BackoffPolicy `json:"backoff,omitempty"` +} + +type RetryStrategy string + +const ( + RetryAlways RetryStrategy = "Always" + RetryOnFailure RetryStrategy = "OnFailure" + RetryNever RetryStrategy = "Never" +) + +type BackoffPolicy struct { + // +kubebuilder:validation:Enum=Constant;Exponential + Type BackoffType `json:"type,omitempty"` + + // Base delay before retry (e.g., 30s) + // +optional + BaseDelay metav1.Duration `json:"baseDelay,omitempty"` + + // Max delay cap (optional, mainly for exponential backoff) + // +optional + MaxDelay *metav1.Duration `json:"maxDelay,omitempty"` +} + +type BackoffType string + +const ( + BackoffConstant BackoffType = "Constant" + BackoffExponential BackoffType = "Exponential" +) + type Probe struct { // +optional HttpGetList []HttpGet `json:"httpGetList,omitempty"` @@ -119,6 +165,10 @@ type JobStatus struct { RestartCount int32 `json:"restartCount,omitempty"` // +optional RunningHistories []JobRunningHistory `json:"runningHistories,omitempty"` + // +optional + RetryCount int32 `json:"retryCount,omitempty"` + // +optional + LastFailureReason string `json:"lastFailureReason,omitempty"` } type JobRunningHistory struct { From 33154a3fde33857bfed810c6287656741dfb9e31 Mon Sep 17 00:00:00 2001 From: mahdikhashan Date: Mon, 25 Aug 2025 16:22:08 +0200 Subject: [PATCH 2/2] update code-gen (auto-generated) --- .../flow/v1alpha1/zz_generated.deepcopy.go | 53 ++++++++++++++++ .../flow/v1alpha1/backoffpolicy.go | 61 +++++++++++++++++++ .../applyconfiguration/flow/v1alpha1/flow.go | 13 +++- .../flow/v1alpha1/jobflowspec.go | 13 +++- .../flow/v1alpha1/jobstatus.go | 30 +++++++-- .../flow/v1alpha1/retrypolicy.go | 60 ++++++++++++++++++ pkg/client/applyconfiguration/utils.go | 4 ++ 7 files changed, 224 insertions(+), 10 deletions(-) create mode 100644 pkg/client/applyconfiguration/flow/v1alpha1/backoffpolicy.go create mode 100644 pkg/client/applyconfiguration/flow/v1alpha1/retrypolicy.go diff --git a/pkg/apis/flow/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/flow/v1alpha1/zz_generated.deepcopy.go index e5422d7c..86999e43 100644 --- a/pkg/apis/flow/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/flow/v1alpha1/zz_generated.deepcopy.go @@ -26,6 +26,28 @@ import ( batchv1alpha1 "volcano.sh/apis/pkg/apis/batch/v1alpha1" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BackoffPolicy) DeepCopyInto(out *BackoffPolicy) { + *out = *in + out.BaseDelay = in.BaseDelay + if in.MaxDelay != nil { + in, out := &in.MaxDelay, &out.MaxDelay + *out = new(v1.Duration) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackoffPolicy. +func (in *BackoffPolicy) DeepCopy() *BackoffPolicy { + if in == nil { + return nil + } + out := new(BackoffPolicy) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Condition) DeepCopyInto(out *Condition) { *out = *in @@ -89,6 +111,11 @@ func (in *Flow) DeepCopyInto(out *Flow) { *out = new(DependsOn) (*in).DeepCopyInto(*out) } + if in.RetryPolicy != nil { + in, out := &in.RetryPolicy, &out.RetryPolicy + *out = new(RetryPolicy) + (*in).DeepCopyInto(*out) + } return } @@ -190,6 +217,11 @@ func (in *JobFlowSpec) DeepCopyInto(out *JobFlowSpec) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.RetryPolicy != nil { + in, out := &in.RetryPolicy, &out.RetryPolicy + *out = new(RetryPolicy) + (*in).DeepCopyInto(*out) + } return } @@ -437,6 +469,27 @@ func (in *Probe) DeepCopy() *Probe { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RetryPolicy) DeepCopyInto(out *RetryPolicy) { + *out = *in + if in.Backoff != nil { + in, out := &in.Backoff, &out.Backoff + *out = new(BackoffPolicy) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RetryPolicy. +func (in *RetryPolicy) DeepCopy() *RetryPolicy { + if in == nil { + return nil + } + out := new(RetryPolicy) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *State) DeepCopyInto(out *State) { *out = *in diff --git a/pkg/client/applyconfiguration/flow/v1alpha1/backoffpolicy.go b/pkg/client/applyconfiguration/flow/v1alpha1/backoffpolicy.go new file mode 100644 index 00000000..8d7424ff --- /dev/null +++ b/pkg/client/applyconfiguration/flow/v1alpha1/backoffpolicy.go @@ -0,0 +1,61 @@ +/* +Copyright The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + flowv1alpha1 "volcano.sh/apis/pkg/apis/flow/v1alpha1" +) + +// BackoffPolicyApplyConfiguration represents a declarative configuration of the BackoffPolicy type for use +// with apply. +type BackoffPolicyApplyConfiguration struct { + Type *flowv1alpha1.BackoffType `json:"type,omitempty"` + BaseDelay *v1.Duration `json:"baseDelay,omitempty"` + MaxDelay *v1.Duration `json:"maxDelay,omitempty"` +} + +// BackoffPolicyApplyConfiguration constructs a declarative configuration of the BackoffPolicy type for use with +// apply. +func BackoffPolicy() *BackoffPolicyApplyConfiguration { + return &BackoffPolicyApplyConfiguration{} +} + +// WithType sets the Type field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Type field is set to the value of the last call. +func (b *BackoffPolicyApplyConfiguration) WithType(value flowv1alpha1.BackoffType) *BackoffPolicyApplyConfiguration { + b.Type = &value + return b +} + +// WithBaseDelay sets the BaseDelay field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the BaseDelay field is set to the value of the last call. +func (b *BackoffPolicyApplyConfiguration) WithBaseDelay(value v1.Duration) *BackoffPolicyApplyConfiguration { + b.BaseDelay = &value + return b +} + +// WithMaxDelay sets the MaxDelay field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the MaxDelay field is set to the value of the last call. +func (b *BackoffPolicyApplyConfiguration) WithMaxDelay(value v1.Duration) *BackoffPolicyApplyConfiguration { + b.MaxDelay = &value + return b +} diff --git a/pkg/client/applyconfiguration/flow/v1alpha1/flow.go b/pkg/client/applyconfiguration/flow/v1alpha1/flow.go index de2d0ea8..7076a879 100644 --- a/pkg/client/applyconfiguration/flow/v1alpha1/flow.go +++ b/pkg/client/applyconfiguration/flow/v1alpha1/flow.go @@ -20,8 +20,9 @@ package v1alpha1 // FlowApplyConfiguration represents a declarative configuration of the Flow type for use // with apply. type FlowApplyConfiguration struct { - Name *string `json:"name,omitempty"` - DependsOn *DependsOnApplyConfiguration `json:"dependsOn,omitempty"` + Name *string `json:"name,omitempty"` + DependsOn *DependsOnApplyConfiguration `json:"dependsOn,omitempty"` + RetryPolicy *RetryPolicyApplyConfiguration `json:"retryPolicy,omitempty"` } // FlowApplyConfiguration constructs a declarative configuration of the Flow type for use with @@ -45,3 +46,11 @@ func (b *FlowApplyConfiguration) WithDependsOn(value *DependsOnApplyConfiguratio b.DependsOn = value return b } + +// WithRetryPolicy sets the RetryPolicy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the RetryPolicy field is set to the value of the last call. +func (b *FlowApplyConfiguration) WithRetryPolicy(value *RetryPolicyApplyConfiguration) *FlowApplyConfiguration { + b.RetryPolicy = value + return b +} diff --git a/pkg/client/applyconfiguration/flow/v1alpha1/jobflowspec.go b/pkg/client/applyconfiguration/flow/v1alpha1/jobflowspec.go index 362131d6..86e5e355 100644 --- a/pkg/client/applyconfiguration/flow/v1alpha1/jobflowspec.go +++ b/pkg/client/applyconfiguration/flow/v1alpha1/jobflowspec.go @@ -24,8 +24,9 @@ import ( // JobFlowSpecApplyConfiguration represents a declarative configuration of the JobFlowSpec type for use // with apply. type JobFlowSpecApplyConfiguration struct { - Flows []FlowApplyConfiguration `json:"flows,omitempty"` - JobRetainPolicy *flowv1alpha1.RetainPolicy `json:"jobRetainPolicy,omitempty"` + Flows []FlowApplyConfiguration `json:"flows,omitempty"` + JobRetainPolicy *flowv1alpha1.RetainPolicy `json:"jobRetainPolicy,omitempty"` + RetryPolicy *RetryPolicyApplyConfiguration `json:"retryPolicy,omitempty"` } // JobFlowSpecApplyConfiguration constructs a declarative configuration of the JobFlowSpec type for use with @@ -54,3 +55,11 @@ func (b *JobFlowSpecApplyConfiguration) WithJobRetainPolicy(value flowv1alpha1.R b.JobRetainPolicy = &value return b } + +// WithRetryPolicy sets the RetryPolicy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the RetryPolicy field is set to the value of the last call. +func (b *JobFlowSpecApplyConfiguration) WithRetryPolicy(value *RetryPolicyApplyConfiguration) *JobFlowSpecApplyConfiguration { + b.RetryPolicy = value + return b +} diff --git a/pkg/client/applyconfiguration/flow/v1alpha1/jobstatus.go b/pkg/client/applyconfiguration/flow/v1alpha1/jobstatus.go index 18b91819..79b23111 100644 --- a/pkg/client/applyconfiguration/flow/v1alpha1/jobstatus.go +++ b/pkg/client/applyconfiguration/flow/v1alpha1/jobstatus.go @@ -25,12 +25,14 @@ import ( // JobStatusApplyConfiguration represents a declarative configuration of the JobStatus type for use // with apply. type JobStatusApplyConfiguration struct { - Name *string `json:"name,omitempty"` - State *batchv1alpha1.JobPhase `json:"state,omitempty"` - StartTimestamp *v1.Time `json:"startTimestamp,omitempty"` - EndTimestamp *v1.Time `json:"endTimestamp,omitempty"` - RestartCount *int32 `json:"restartCount,omitempty"` - RunningHistories []JobRunningHistoryApplyConfiguration `json:"runningHistories,omitempty"` + Name *string `json:"name,omitempty"` + State *batchv1alpha1.JobPhase `json:"state,omitempty"` + StartTimestamp *v1.Time `json:"startTimestamp,omitempty"` + EndTimestamp *v1.Time `json:"endTimestamp,omitempty"` + RestartCount *int32 `json:"restartCount,omitempty"` + RunningHistories []JobRunningHistoryApplyConfiguration `json:"runningHistories,omitempty"` + RetryCount *int32 `json:"retryCount,omitempty"` + LastFailureReason *string `json:"lastFailureReason,omitempty"` } // JobStatusApplyConfiguration constructs a declarative configuration of the JobStatus type for use with @@ -91,3 +93,19 @@ func (b *JobStatusApplyConfiguration) WithRunningHistories(values ...*JobRunning } return b } + +// WithRetryCount sets the RetryCount field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the RetryCount field is set to the value of the last call. +func (b *JobStatusApplyConfiguration) WithRetryCount(value int32) *JobStatusApplyConfiguration { + b.RetryCount = &value + return b +} + +// WithLastFailureReason sets the LastFailureReason field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the LastFailureReason field is set to the value of the last call. +func (b *JobStatusApplyConfiguration) WithLastFailureReason(value string) *JobStatusApplyConfiguration { + b.LastFailureReason = &value + return b +} diff --git a/pkg/client/applyconfiguration/flow/v1alpha1/retrypolicy.go b/pkg/client/applyconfiguration/flow/v1alpha1/retrypolicy.go new file mode 100644 index 00000000..92a768e5 --- /dev/null +++ b/pkg/client/applyconfiguration/flow/v1alpha1/retrypolicy.go @@ -0,0 +1,60 @@ +/* +Copyright The Volcano Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + flowv1alpha1 "volcano.sh/apis/pkg/apis/flow/v1alpha1" +) + +// RetryPolicyApplyConfiguration represents a declarative configuration of the RetryPolicy type for use +// with apply. +type RetryPolicyApplyConfiguration struct { + MaxRetries *int32 `json:"maxRetries,omitempty"` + Policy *flowv1alpha1.RetryStrategy `json:"policy,omitempty"` + Backoff *BackoffPolicyApplyConfiguration `json:"backoff,omitempty"` +} + +// RetryPolicyApplyConfiguration constructs a declarative configuration of the RetryPolicy type for use with +// apply. +func RetryPolicy() *RetryPolicyApplyConfiguration { + return &RetryPolicyApplyConfiguration{} +} + +// WithMaxRetries sets the MaxRetries field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the MaxRetries field is set to the value of the last call. +func (b *RetryPolicyApplyConfiguration) WithMaxRetries(value int32) *RetryPolicyApplyConfiguration { + b.MaxRetries = &value + return b +} + +// WithPolicy sets the Policy field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Policy field is set to the value of the last call. +func (b *RetryPolicyApplyConfiguration) WithPolicy(value flowv1alpha1.RetryStrategy) *RetryPolicyApplyConfiguration { + b.Policy = &value + return b +} + +// WithBackoff sets the Backoff field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Backoff field is set to the value of the last call. +func (b *RetryPolicyApplyConfiguration) WithBackoff(value *BackoffPolicyApplyConfiguration) *RetryPolicyApplyConfiguration { + b.Backoff = value + return b +} diff --git a/pkg/client/applyconfiguration/utils.go b/pkg/client/applyconfiguration/utils.go index 44d95e94..3533c1b3 100644 --- a/pkg/client/applyconfiguration/utils.go +++ b/pkg/client/applyconfiguration/utils.go @@ -69,6 +69,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationbusv1alpha1.CommandApplyConfiguration{} // Group=flow.volcano.sh, Version=v1alpha1 + case flowv1alpha1.SchemeGroupVersion.WithKind("BackoffPolicy"): + return &applyconfigurationflowv1alpha1.BackoffPolicyApplyConfiguration{} case flowv1alpha1.SchemeGroupVersion.WithKind("Condition"): return &applyconfigurationflowv1alpha1.ConditionApplyConfiguration{} case flowv1alpha1.SchemeGroupVersion.WithKind("DependsOn"): @@ -93,6 +95,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationflowv1alpha1.JobTemplateStatusApplyConfiguration{} case flowv1alpha1.SchemeGroupVersion.WithKind("Probe"): return &applyconfigurationflowv1alpha1.ProbeApplyConfiguration{} + case flowv1alpha1.SchemeGroupVersion.WithKind("RetryPolicy"): + return &applyconfigurationflowv1alpha1.RetryPolicyApplyConfiguration{} case flowv1alpha1.SchemeGroupVersion.WithKind("State"): return &applyconfigurationflowv1alpha1.StateApplyConfiguration{} case flowv1alpha1.SchemeGroupVersion.WithKind("TaskStatus"):