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

Add terminationPolicy to TfJobSpec #204

Merged
merged 10 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
33 changes: 27 additions & 6 deletions pkg/spec/tf_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (c *TfJob) AsOwner() metav1.OwnerReference {
// TODO: In 1.6 this is gonna be "k8s.io/kubernetes/pkg/apis/meta/v1"
// Both api.OwnerReference and metatypes.OwnerReference are combined into that.
return metav1.OwnerReference{
APIVersion: c.APIVersion,
Kind: c.Kind,
Name: c.Metadata.Name,
UID: c.Metadata.UID,
Controller: &trueVar,
BlockOwnerDeletion: &trueVar,
APIVersion: c.APIVersion,
Kind: c.Kind,
Name: c.Metadata.Name,
UID: c.Metadata.UID,
Controller: &trueVar,
BlockOwnerDeletion: &trueVar,
}
}

Expand All @@ -65,6 +65,9 @@ type TfJobSpec struct {
// TfImage defines the tensorflow docker image that should be used for Tensorboard
// and the default parameter server
TfImage string `json:"tfImage,omitempty"`

// TerminationPolicy specifies the condition that the tfjob should be considered finished.
TerminationPolicy *TerminationPolicySpec `json:"terminationPolicy,omitempty"`
}

// TfReplicaType determines how a set of TF processes are handled.
Expand Down Expand Up @@ -109,6 +112,16 @@ type TensorBoardSpec struct {
ServiceType v1.ServiceType `json:"serviceType"`
}

type TerminationPolicySpec struct {
// Chief policy waits for a particular process (which is the chief) to exit.
Chief *ChiefSpec `json:"chief,omitempty"`
}

type ChiefSpec struct {
ReplicaName string `json:"replicaName"`
ReplicaIndex int `json:"replicaIndex"`
}

// Validate checks that the TfJobSpec is valid.
func (c *TfJobSpec) Validate() error {
// Check that each replica has a TensorFlow container.
Expand Down Expand Up @@ -240,6 +253,14 @@ func (c *TfJobSpec) SetDefaults() error {
r.setDefaultPSPodTemplateSpec(c.TfImage)
}
}
if c.TerminationPolicy == nil {
c.TerminationPolicy = &TerminationPolicySpec{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are you setting the default policy here and not in
https://github.com/tensorflow/k8s/blob/master/pkg/spec/tf_job.go#L215?

In validate can we check that termination policy is a valid policy? So right now the only valid policy should be MASTER, index=0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in the SetDefaults(), I guess you thought it's in Validate because the code collapsed.

Added validation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks.
Resolved.

Chief: &ChiefSpec{
ReplicaName: "MASTER",
ReplicaIndex: 0,
},
}
}
return nil
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/spec/tf_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,12 @@ func TestSetDefaults(t *testing.T) {
},
},
TfImage: "tensorflow/tensorflow:1.3.0",
TerminationPolicy: &TerminationPolicySpec{
Chief: &ChiefSpec{
ReplicaName: "MASTER",
ReplicaIndex: 0,
},
},
},
},
{
Expand Down Expand Up @@ -312,6 +318,12 @@ func TestSetDefaults(t *testing.T) {
},
},
TfImage: "tensorflow/tensorflow:1.3.0",
TerminationPolicy: &TerminationPolicySpec{
Chief: &ChiefSpec{
ReplicaName: "MASTER",
ReplicaIndex: 0,
},
},
},
},
}
Expand Down