Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local copy of RunPolicy by MPI-operator #513

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/apis/kubeflow/v2beta1/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func setDefaultsTypeWorker(spec *common.ReplicaSpec) {
}
}

func setDefaultsRunPolicy(policy *common.RunPolicy) {
func setDefaultsRunPolicy(policy *RunPolicy) {
if policy.CleanPodPolicy == nil {
policy.CleanPodPolicy = newCleanPodPolicy(common.CleanPodPolicyNone)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/kubeflow/v2beta1/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
RunPolicy: common.RunPolicy{
RunPolicy: RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
Expand All @@ -42,7 +42,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
job: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
RunPolicy: common.RunPolicy{
RunPolicy: RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
Expand All @@ -55,7 +55,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(10),
RunPolicy: common.RunPolicy{
RunPolicy: RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
TTLSecondsAfterFinished: newInt32(2),
ActiveDeadlineSeconds: newInt64(3),
Expand All @@ -77,7 +77,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
RunPolicy: common.RunPolicy{
RunPolicy: RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
Expand All @@ -102,7 +102,7 @@ func TestSetDefaults_MPIJob(t *testing.T) {
want: MPIJob{
Spec: MPIJobSpec{
SlotsPerWorker: newInt32(1),
RunPolicy: common.RunPolicy{
RunPolicy: RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyNone),
},
SSHAuthMountPath: "/root/.ssh",
Expand Down
54 changes: 52 additions & 2 deletions pkg/apis/kubeflow/v2beta1/openapi_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion pkg/apis/kubeflow/v2beta1/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
"runPolicy": {
"description": "RunPolicy encapsulates various runtime policies of the job.",
"default": {},
"$ref": "#/definitions/v1.RunPolicy"
"$ref": "#/definitions/v2beta1.RunPolicy"
},
"slotsPerWorker": {
"description": "Specifies the number of slots per worker used in hostfile. Defaults to 1.",
Expand All @@ -272,6 +272,35 @@
"type": "string"
}
}
},
"v2beta1.RunPolicy": {
"description": "RunPolicy encapsulates various runtime policies of the distributed training job, for example how to clean up resources and how long the job can stay active.",
"type": "object",
"properties": {
"activeDeadlineSeconds": {
"description": "Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer.",
"type": "integer",
"format": "int64"
},
"backoffLimit": {
"description": "Optional number of retries before marking this job failed.",
"type": "integer",
"format": "int32"
},
"cleanPodPolicy": {
"description": "CleanPodPolicy defines the policy to kill pods after the job completes. Default to Running.",
"type": "string"
},
"schedulingPolicy": {
"description": "SchedulingPolicy defines the policy related to scheduling, e.g. gang-scheduling",
"$ref": "#/definitions/v1.SchedulingPolicy"
},
"ttlSecondsAfterFinished": {
"description": "TTLSecondsAfterFinished is the TTL to clean up jobs. It may take extra ReconcilePeriod seconds for the cleanup, since reconcile gets called periodically. Default to infinite.",
"type": "integer",
"format": "int32"
}
}
}
}
}
30 changes: 29 additions & 1 deletion pkg/apis/kubeflow/v2beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,34 @@ type MPIJobList struct {
Items []MPIJob `json:"items"`
}

// RunPolicy encapsulates various runtime policies of the distributed training
// job, for example how to clean up resources and how long the job can stay
// active.
type RunPolicy struct {
// CleanPodPolicy defines the policy to kill pods after the job completes.
// Default to Running.
CleanPodPolicy *common.CleanPodPolicy `json:"cleanPodPolicy,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy the CleanPodPolicy from kubeflow/common to this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, it wasn't clear to me from the so far discussions so did it with minimal changes required to place the suspend field, but let me update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to copy all types, and members to this repo since moving only part of those might make double management.

cc: @alculquicondor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied, PTAL at the last commit.


// TTLSecondsAfterFinished is the TTL to clean up jobs.
// It may take extra ReconcilePeriod seconds for the cleanup, since
// reconcile gets called periodically.
// Default to infinite.
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`

// Specifies the duration in seconds relative to the startTime that the job may be active
// before the system tries to terminate it; value must be positive integer.
// +optional
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty"`

// Optional number of retries before marking this job failed.
// +optional
BackoffLimit *int32 `json:"backoffLimit,omitempty"`

// SchedulingPolicy defines the policy related to scheduling, e.g. gang-scheduling
// +optional
SchedulingPolicy *common.SchedulingPolicy `json:"schedulingPolicy,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy the SchedulingPolicy from kubeflow/common to this repo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, about to copy too.

}

type MPIJobSpec struct {

// Specifies the number of slots per worker used in hostfile.
Expand All @@ -46,7 +74,7 @@ type MPIJobSpec struct {
SlotsPerWorker *int32 `json:"slotsPerWorker,omitempty"`

// RunPolicy encapsulates various runtime policies of the job.
RunPolicy common.RunPolicy `json:"runPolicy,omitempty"`
RunPolicy RunPolicy `json:"runPolicy,omitempty"`

// MPIReplicaSpecs contains maps from `MPIReplicaType` to `ReplicaSpec` that
// specify the MPI replicas to run.
Expand Down
41 changes: 41 additions & 0 deletions pkg/apis/kubeflow/v2beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apis/kubeflow/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func validateMPIJobSpec(spec *kubeflow.MPIJobSpec, path *field.Path) field.Error
return errs
}

func validateRunPolicy(policy *common.RunPolicy, path *field.Path) field.ErrorList {
func validateRunPolicy(policy *kubeflow.RunPolicy, path *field.Path) field.ErrorList {
var errs field.ErrorList
if policy.CleanPodPolicy == nil {
errs = append(errs, field.Required(path.Child("cleanPodPolicy"), "must have clean Pod policy"))
Expand Down
13 changes: 7 additions & 6 deletions pkg/apis/kubeflow/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
common "github.com/kubeflow/common/pkg/apis/common/v1"
"github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1"
kubeflow "github.com/kubeflow/mpi-operator/pkg/apis/kubeflow/v2beta1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand All @@ -38,7 +39,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
Expand All @@ -64,7 +65,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
},
SSHAuthMountPath: "/home/mpiuser/.ssh",
Expand Down Expand Up @@ -127,7 +128,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy("unknown"),
TTLSecondsAfterFinished: newInt32(-1),
ActiveDeadlineSeconds: newInt64(-1),
Expand Down Expand Up @@ -191,7 +192,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
},
SSHAuthMountPath: "/root/.ssh",
Expand All @@ -213,7 +214,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
},
SSHAuthMountPath: "/root/.ssh",
Expand Down Expand Up @@ -258,7 +259,7 @@ func TestValidateMPIJob(t *testing.T) {
},
Spec: v2beta1.MPIJobSpec{
SlotsPerWorker: newInt32(2),
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: newCleanPodPolicy(common.CleanPodPolicyRunning),
},
SSHAuthMountPath: "/root/.ssh",
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/mpi_job_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func newMPIJobCommon(name string, startTime, completionTime *metav1.Time) *kubef
Namespace: metav1.NamespaceDefault,
},
Spec: kubeflow.MPIJobSpec{
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
CleanPodPolicy: &cleanPodPolicyAll,
},
MPIReplicaSpecs: map[kubeflow.MPIReplicaType]*common.ReplicaSpec{
Expand Down Expand Up @@ -1091,7 +1091,7 @@ func TestNewLauncherAndWorker(t *testing.T) {
SSHAuthMountPath: "/home/mpiuser/.ssh",
SlotsPerWorker: newInt32(5),
MPIImplementation: kubeflow.MPIImplementationIntel,
RunPolicy: common.RunPolicy{
RunPolicy: kubeflow.RunPolicy{
TTLSecondsAfterFinished: newInt32(1),
ActiveDeadlineSeconds: newInt64(2),
BackoffLimit: newInt32(3),
Expand Down
1 change: 1 addition & 0 deletions sdk/python/v2beta1/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/python/v2beta1/docs/V2beta1MPIJobSpec.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions sdk/python/v2beta1/docs/V2beta1RunPolicy.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/python/v2beta1/mpijob/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/python/v2beta1/mpijob/models/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading