diff --git a/pkg/apis/common/v1/zz_generated.deepcopy.go b/pkg/apis/common/v1/zz_generated.deepcopy.go index 99e52d391a..1dc0dd3b1a 100644 --- a/pkg/apis/common/v1/zz_generated.deepcopy.go +++ b/pkg/apis/common/v1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/apis/common/v1beta2/zz_generated.deepcopy.go b/pkg/apis/common/v1beta2/zz_generated.deepcopy.go index ddc9521b17..e9a4a52283 100644 --- a/pkg/apis/common/v1beta2/zz_generated.deepcopy.go +++ b/pkg/apis/common/v1beta2/zz_generated.deepcopy.go @@ -1,6 +1,7 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/apis/tensorflow/v1/common.go b/pkg/apis/tensorflow/v1/common.go new file mode 100644 index 0000000000..4e508ebe00 --- /dev/null +++ b/pkg/apis/tensorflow/v1/common.go @@ -0,0 +1,23 @@ +// Copyright 2020 The Kubeflow 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. + +package v1 + +// SuccessPolicy is the success policy. +type SuccessPolicy string + +const ( + SuccessPolicyDefault SuccessPolicy = "" + SuccessPolicyAllWorkers SuccessPolicy = "AllWorkers" +) diff --git a/pkg/apis/tensorflow/v1/defaults.go b/pkg/apis/tensorflow/v1/defaults.go index 5dc0950e4f..c12ac6146d 100644 --- a/pkg/apis/tensorflow/v1/defaults.go +++ b/pkg/apis/tensorflow/v1/defaults.go @@ -18,7 +18,7 @@ import ( "strings" common "github.com/kubeflow/tf-operator/pkg/apis/common/v1" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -96,6 +96,12 @@ func SetDefaults_TFJob(tfjob *TFJob) { tfjob.Spec.CleanPodPolicy = &running } + // Set default success policy to "". + if tfjob.Spec.SuccessPolicy == nil { + defaultPolicy := SuccessPolicyDefault + tfjob.Spec.SuccessPolicy = &defaultPolicy + } + // Update the key of TFReplicaSpecs to camel case. setTypeNamesToCamelCase(tfjob) diff --git a/pkg/apis/tensorflow/v1/defaults_test.go b/pkg/apis/tensorflow/v1/defaults_test.go index d4f3c79d79..8ba96f45e5 100644 --- a/pkg/apis/tensorflow/v1/defaults_test.go +++ b/pkg/apis/tensorflow/v1/defaults_test.go @@ -18,7 +18,7 @@ import ( "reflect" "testing" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" common "github.com/kubeflow/tf-operator/pkg/apis/common/v1" "github.com/kubeflow/tf-operator/pkg/util" @@ -51,8 +51,11 @@ func expectedTFJob(cleanPodPolicy common.CleanPodPolicy, restartPolicy common.Re ) } + defaultSuccessPolicy := SuccessPolicyDefault + return &TFJob{ Spec: TFJobSpec{ + SuccessPolicy: &defaultSuccessPolicy, CleanPodPolicy: &cleanPodPolicy, TFReplicaSpecs: map[TFReplicaType]*common.ReplicaSpec{ TFReplicaTypeWorker: &common.ReplicaSpec{ diff --git a/pkg/apis/tensorflow/v1/types.go b/pkg/apis/tensorflow/v1/types.go index bfb278111d..060332b679 100644 --- a/pkg/apis/tensorflow/v1/types.go +++ b/pkg/apis/tensorflow/v1/types.go @@ -56,6 +56,11 @@ type TFJobSpec struct { // +optional BackoffLimit *int32 `json:"backoffLimit,omitempty"` + // SuccessPolicy defines the policy to mark the TFJob as succeeded. + // Default to "", using the default rules. + // +optional + SuccessPolicy *SuccessPolicy `json:"successPolicy,omitempty"` + // Defines the policy for cleaning up pods after the TFJob completes. // Defaults to Running. CleanPodPolicy *common.CleanPodPolicy `json:"cleanPodPolicy,omitempty"` diff --git a/pkg/apis/tensorflow/v1/zz_generated.deepcopy.go b/pkg/apis/tensorflow/v1/zz_generated.deepcopy.go index ef6ea4115f..83a3de2372 100644 --- a/pkg/apis/tensorflow/v1/zz_generated.deepcopy.go +++ b/pkg/apis/tensorflow/v1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ //go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2023 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -103,6 +103,11 @@ func (in *TFJobSpec) DeepCopyInto(out *TFJobSpec) { *out = new(int32) **out = **in } + if in.SuccessPolicy != nil { + in, out := &in.SuccessPolicy, &out.SuccessPolicy + *out = new(SuccessPolicy) + **out = **in + } if in.CleanPodPolicy != nil { in, out := &in.CleanPodPolicy, &out.CleanPodPolicy *out = new(commonv1.CleanPodPolicy) diff --git a/pkg/apis/tensorflow/v1beta2/zz_generated.deepcopy.go b/pkg/apis/tensorflow/v1beta2/zz_generated.deepcopy.go index 05c8c3c840..91e10d10ea 100644 --- a/pkg/apis/tensorflow/v1beta2/zz_generated.deepcopy.go +++ b/pkg/apis/tensorflow/v1beta2/zz_generated.deepcopy.go @@ -1,6 +1,7 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/apis/tensorflow/v1beta2/zz_generated.defaults.go b/pkg/apis/tensorflow/v1beta2/zz_generated.defaults.go index b56e22d55d..3816c31594 100644 --- a/pkg/apis/tensorflow/v1beta2/zz_generated.defaults.go +++ b/pkg/apis/tensorflow/v1beta2/zz_generated.defaults.go @@ -1,6 +1,7 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index d24fe894da..6672b6a278 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/doc.go b/pkg/client/clientset/versioned/doc.go index a311794354..a4ef74448d 100644 --- a/pkg/client/clientset/versioned/doc.go +++ b/pkg/client/clientset/versioned/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index a7ffc82c69..21b732cfbe 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/fake/doc.go b/pkg/client/clientset/versioned/fake/doc.go index 8c0be5ac41..061d108e56 100644 --- a/pkg/client/clientset/versioned/fake/doc.go +++ b/pkg/client/clientset/versioned/fake/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index fc01c38edf..97fea7ebe2 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,14 +37,14 @@ func init() { // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/clientset/versioned/scheme/doc.go b/pkg/client/clientset/versioned/scheme/doc.go index d0f752890d..103f11d7a7 100644 --- a/pkg/client/clientset/versioned/scheme/doc.go +++ b/pkg/client/clientset/versioned/scheme/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index bfc085130c..6285d565b6 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -37,14 +37,14 @@ func init() { // AddToScheme adds all types of this clientset into the given scheme. This allows composition // of clientsets, like in: // -// import ( -// "k8s.io/client-go/kubernetes" -// clientsetscheme "k8s.io/client-go/kubernetes/scheme" -// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" -// ) +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) // -// kclientset, _ := kubernetes.NewForConfig(c) -// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) // // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types // correctly. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/doc.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/doc.go index 5c8101df70..a40f7e875b 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/doc.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/doc.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/doc.go index ce2fa8a9b1..424308ee3b 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/doc.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tensorflow_client.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tensorflow_client.go index b5611341b4..be9b13c834 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tensorflow_client.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tensorflow_client.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tfjob.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tfjob.go index ab6dd06b05..c3cdc45313 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tfjob.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/fake/fake_tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/generated_expansion.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/generated_expansion.go index 98be8edca8..b8658c0a5a 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/tensorflow_client.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/tensorflow_client.go index 7a176883e7..1996f04169 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/tensorflow_client.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/tensorflow_client.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1/tfjob.go b/pkg/client/clientset/versioned/typed/tensorflow/v1/tfjob.go index b9f3d50576..91fd7043e9 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1/tfjob.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/doc.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/doc.go index 21389f741f..714fead0a5 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/doc.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/doc.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/doc.go index ce2fa8a9b1..424308ee3b 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/doc.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/doc.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tensorflow_client.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tensorflow_client.go index 47ca3390e1..54d410369c 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tensorflow_client.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tensorflow_client.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tfjob.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tfjob.go index cc7513228a..9a6dd270bc 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tfjob.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/fake/fake_tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/generated_expansion.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/generated_expansion.go index dd3ba76750..caa15123d6 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/generated_expansion.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tensorflow_client.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tensorflow_client.go index 267c3495af..3ffcfe3b60 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tensorflow_client.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tensorflow_client.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tfjob.go b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tfjob.go index 5b675c5eb8..681c5baade 100644 --- a/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tfjob.go +++ b/pkg/client/clientset/versioned/typed/tensorflow/v1beta2/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 52f2478afc..5361dc7ddb 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 3d6a3a7ae6..b609ed41aa 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go index 892f7488af..315c99ffd3 100644 --- a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/tensorflow/interface.go b/pkg/client/informers/externalversions/tensorflow/interface.go index f5919f97c7..94a26367f4 100644 --- a/pkg/client/informers/externalversions/tensorflow/interface.go +++ b/pkg/client/informers/externalversions/tensorflow/interface.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/tensorflow/v1/interface.go b/pkg/client/informers/externalversions/tensorflow/v1/interface.go index 3cb0c3fcec..ec16d554a0 100644 --- a/pkg/client/informers/externalversions/tensorflow/v1/interface.go +++ b/pkg/client/informers/externalversions/tensorflow/v1/interface.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/tensorflow/v1/tfjob.go b/pkg/client/informers/externalversions/tensorflow/v1/tfjob.go index 1406173d0a..dc31cb97c9 100644 --- a/pkg/client/informers/externalversions/tensorflow/v1/tfjob.go +++ b/pkg/client/informers/externalversions/tensorflow/v1/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/tensorflow/v1beta2/interface.go b/pkg/client/informers/externalversions/tensorflow/v1beta2/interface.go index d48c727ae6..7893dd23bb 100644 --- a/pkg/client/informers/externalversions/tensorflow/v1beta2/interface.go +++ b/pkg/client/informers/externalversions/tensorflow/v1beta2/interface.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/informers/externalversions/tensorflow/v1beta2/tfjob.go b/pkg/client/informers/externalversions/tensorflow/v1beta2/tfjob.go index d333f9b1dc..4272673ba9 100644 --- a/pkg/client/informers/externalversions/tensorflow/v1beta2/tfjob.go +++ b/pkg/client/informers/externalversions/tensorflow/v1beta2/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/listers/tensorflow/v1/expansion_generated.go b/pkg/client/listers/tensorflow/v1/expansion_generated.go index fc0f0ce634..be66f2b940 100644 --- a/pkg/client/listers/tensorflow/v1/expansion_generated.go +++ b/pkg/client/listers/tensorflow/v1/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/listers/tensorflow/v1/tfjob.go b/pkg/client/listers/tensorflow/v1/tfjob.go index 82b5432c66..86c0594985 100644 --- a/pkg/client/listers/tensorflow/v1/tfjob.go +++ b/pkg/client/listers/tensorflow/v1/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/listers/tensorflow/v1beta2/expansion_generated.go b/pkg/client/listers/tensorflow/v1beta2/expansion_generated.go index 591a5a3555..6cbfb07428 100644 --- a/pkg/client/listers/tensorflow/v1beta2/expansion_generated.go +++ b/pkg/client/listers/tensorflow/v1beta2/expansion_generated.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/client/listers/tensorflow/v1beta2/tfjob.go b/pkg/client/listers/tensorflow/v1beta2/tfjob.go index e7bb6cddcf..dc2dd36405 100644 --- a/pkg/client/listers/tensorflow/v1beta2/tfjob.go +++ b/pkg/client/listers/tensorflow/v1beta2/tfjob.go @@ -1,4 +1,4 @@ -// Copyright 2019 The Kubeflow Authors +// Copyright 2024 The Kubeflow Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/common/util/v1/testutil/tfjob.go b/pkg/common/util/v1/testutil/tfjob.go index 1aa363e47d..6f31415e7d 100644 --- a/pkg/common/util/v1/testutil/tfjob.go +++ b/pkg/common/util/v1/testutil/tfjob.go @@ -17,7 +17,7 @@ package testutil import ( "time" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" common "github.com/kubeflow/tf-operator/pkg/apis/common/v1" @@ -102,6 +102,12 @@ func NewTFJobWithEvaluator(worker, ps, evaluator int) *tfv1.TFJob { return tfJob } +func NewTFJobWithSuccessPolicy(worker, ps int, successPolicy tfv1.SuccessPolicy) *tfv1.TFJob { + tfJob := NewTFJob(worker, ps) + tfJob.Spec.SuccessPolicy = &successPolicy + return tfJob +} + func NewTFJob(worker, ps int) *tfv1.TFJob { tfJob := &tfv1.TFJob{ TypeMeta: metav1.TypeMeta{ diff --git a/pkg/controller.v1/tensorflow/status.go b/pkg/controller.v1/tensorflow/status.go index 9673c460c5..747876fd82 100644 --- a/pkg/controller.v1/tensorflow/status.go +++ b/pkg/controller.v1/tensorflow/status.go @@ -103,8 +103,10 @@ func (tc *TFController) updateStatusSingle(tfjob *tfv1.TFJob, rtype tfv1.TFRepli } } else { if rtype == tfv1.TFReplicaTypeWorker { - // All workers are succeeded or worker 0 completed, leave a succeeded condition. - if expected == 0 || worker0Completed { + // Leave a succeeded condition for the following two cases: + // 1. If default success policy is used and worker 0 has completed. + // 2. If `SuccessPolicyAllWorkers` success policy is used and all workers are succeeded. + if expected == 0 || (worker0Completed && *tfjob.Spec.SuccessPolicy != tfv1.SuccessPolicyAllWorkers) { msg := fmt.Sprintf("TFJob %s successfully completed.", tfjob.Name) tc.Recorder.Event(tfjob, v1.EventTypeNormal, tfJobSucceededReason, msg) if tfjob.Status.CompletionTime == nil { diff --git a/pkg/controller.v1/tensorflow/status_test.go b/pkg/controller.v1/tensorflow/status_test.go index d788f91441..d216b0b25c 100644 --- a/pkg/controller.v1/tensorflow/status_test.go +++ b/pkg/controller.v1/tensorflow/status_test.go @@ -19,7 +19,7 @@ import ( "testing" kubebatchclient "github.com/kubernetes-sigs/kube-batch/pkg/client/clientset/versioned" - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" kubeclientset "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/record" @@ -270,6 +270,54 @@ func TestStatus(t *testing.T) { worker0Completed: true, expectedType: common.JobSucceeded, }, + testCase{ + description: "(No chief worker, successPolicy: AllWorkers) worker-0 are succeeded, 3 workers are active", + tfJob: testutil.NewTFJobWithSuccessPolicy(4, 0, tfv1.SuccessPolicyAllWorkers), + expectedFailedPS: 0, + expectedSucceededPS: 0, + expectedActivePS: 0, + expectedFailedWorker: 0, + expectedSucceededWorker: 1, + expectedActiveWorker: 3, + expectedFailedChief: 0, + expectedSucceededChief: 0, + expectedActiveChief: 0, + restart: false, + worker0Completed: true, + expectedType: common.JobRunning, + }, + testCase{ + description: "(No chief worker, successPolicy: AllWorkers) 4 workers are succeeded", + tfJob: testutil.NewTFJobWithSuccessPolicy(4, 0, tfv1.SuccessPolicyAllWorkers), + expectedFailedPS: 0, + expectedSucceededPS: 0, + expectedActivePS: 0, + expectedFailedWorker: 0, + expectedSucceededWorker: 4, + expectedActiveWorker: 0, + expectedFailedChief: 0, + expectedSucceededChief: 0, + expectedActiveChief: 0, + restart: false, + worker0Completed: true, + expectedType: common.JobSucceeded, + }, + testCase{ + description: "(No chief worker, successPolicy: AllWorkers) worker-0 is succeeded, 2 workers are running, 1 worker is failed", + tfJob: testutil.NewTFJobWithSuccessPolicy(4, 0, tfv1.SuccessPolicyAllWorkers), + expectedFailedPS: 0, + expectedSucceededPS: 0, + expectedActivePS: 0, + expectedFailedWorker: 1, + expectedSucceededWorker: 1, + expectedActiveWorker: 2, + expectedFailedChief: 0, + expectedSucceededChief: 0, + expectedActiveChief: 0, + restart: false, + worker0Completed: true, + expectedType: common.JobFailed, + }, testCase{ description: "Chief is running, workers are failed", tfJob: testutil.NewTFJobWithChief(4, 2),