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

and some safety check #683

Merged
merged 1 commit into from
Jun 19, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions pkg/controller.v2/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func (tc *TFJobController) enqueueTFJob(tfjob interface{}) {
return
}

// TODO: we may need add backoff here
tc.workQueue.Add(key)
}

Expand All @@ -344,6 +345,9 @@ func (tc *TFJobController) syncTFJob(key string) (bool, error) {
if err != nil {
return false, err
}
if len(namespace) == 0 || len(name) == 0 {
return false, fmt.Errorf("invalid tfjob key %q: either namespace or name is missing", key)
}

sharedTFJob, err := tc.getTFJobFromName(namespace, name)
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/controller.v2/controller_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func updateStatus(tfjob *tfv1alpha2.TFJob, rtype tfv1alpha2.TFReplicaType, repli
failed := int(tfjob.Status.TFReplicaStatuses[rtype].Failed)

// All workers are running, set StartTime.
if running == replicas {
if running == replicas && tfjob.Status.StartTime == nil {
now := metav1.Now()
tfjob.Status.StartTime = &now
}
Expand All @@ -61,8 +61,6 @@ func updateStatus(tfjob *tfv1alpha2.TFJob, rtype tfv1alpha2.TFReplicaType, repli
}
if expected == 0 {
msg := fmt.Sprintf("TFJob %s is successfully completed.", tfjob.Name)
now := metav1.Now()
tfjob.Status.CompletionTime = &now
err := updateTFJobConditions(tfjob, tfv1alpha2.TFJobSucceeded, tfJobSucceededReason, msg)
if err != nil {
loggerForTFJob(tfjob).Infof("Append tfjob condition error: %v", err)
Expand Down Expand Up @@ -96,8 +94,6 @@ func updateStatus(tfjob *tfv1alpha2.TFJob, rtype tfv1alpha2.TFReplicaType, repli
// All workers are succeeded, leave a succeeded condition.
if expected == 0 {
msg := fmt.Sprintf("TFJob %s is successfully completed.", tfjob.Name)
now := metav1.Now()
tfjob.Status.CompletionTime = &now
err := updateTFJobConditions(tfjob, tfv1alpha2.TFJobSucceeded, tfJobSucceededReason, msg)
if err != nil {
loggerForTFJob(tfjob).Infof("Append tfjob condition error: %v", err)
Expand Down Expand Up @@ -180,6 +176,7 @@ func getCondition(status tfv1alpha2.TFJobStatus, condType tfv1alpha2.TFJobCondit
// setCondition updates the tfjob to include the provided condition.
// If the condition that we are about to add already exists
// and has the same status and reason then we are not going to update.
// If condition is TFJobSucceeded, set CompletionTime.
func setCondition(status *tfv1alpha2.TFJobStatus, condition tfv1alpha2.TFJobCondition) {
currentCond := getCondition(*status, condition.Type)

Expand All @@ -193,6 +190,12 @@ func setCondition(status *tfv1alpha2.TFJobStatus, condition tfv1alpha2.TFJobCond
condition.LastTransitionTime = currentCond.LastTransitionTime
}

// if success, update with complete time
if condition.Type == tfv1alpha2.TFJobSucceeded && status.CompletionTime == nil {
now := metav1.Now()
status.CompletionTime = &now
}

// Append the updated condition to the
newConditions := filterOutCondition(status.Conditions, condition.Type)
status.Conditions = append(newConditions, condition)
Expand Down