Skip to content

Commit

Permalink
Merge pull request #2862 from dperny/revert-set-update-status
Browse files Browse the repository at this point in the history
Revert "Make Service.UpdateStatus non-ambiguous"
  • Loading branch information
dperny authored May 29, 2019
2 parents 1e20cbf + 4c1b27c commit fb584e7
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions manager/orchestrator/update/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,10 @@ func (u *Updater) Run(ctx context.Context, slots []orchestrator.Slot) {
}
// Abort immediately if all tasks are clean.
if len(dirtySlots) == 0 {
if service.UpdateStatus == nil {
if u.annotationsUpdated(service) {
// Annotation-only update; mark the update as completed
u.completeUpdate(ctx, service.ID, true)
}
return
}
if service.UpdateStatus.State == api.UpdateStatus_UPDATING || service.UpdateStatus.State == api.UpdateStatus_ROLLBACK_STARTED {
// Update or rollback was started, and is now complete
u.completeUpdate(ctx, service.ID, true)
return
if service.UpdateStatus != nil &&
(service.UpdateStatus.State == api.UpdateStatus_UPDATING ||
service.UpdateStatus.State == api.UpdateStatus_ROLLBACK_STARTED) {
u.completeUpdate(ctx, service.ID)
}
return
}
Expand Down Expand Up @@ -310,7 +303,7 @@ slotsLoop:
// have reached RUNNING by this point.

if !stopped {
u.completeUpdate(ctx, service.ID, false)
u.completeUpdate(ctx, service.ID)
}
}

Expand Down Expand Up @@ -623,32 +616,25 @@ func (u *Updater) rollbackUpdate(ctx context.Context, serviceID, message string)
}
}

func (u *Updater) completeUpdate(ctx context.Context, serviceID string, force bool) {
func (u *Updater) completeUpdate(ctx context.Context, serviceID string) {
log.G(ctx).Debugf("update of service %s complete", serviceID)

err := u.store.Update(func(tx store.Tx) error {
service := store.GetService(tx, serviceID)
switch {
case service == nil:
if service == nil {
return nil
case service.UpdateStatus == nil && force:
// Force marking the status as updated; to account for annotation-only updates.
service.UpdateStatus = &api.UpdateStatus{
StartedAt: ptypes.MustTimestampProto(time.Now()),
State: api.UpdateStatus_COMPLETED,
Message: "update completed",
}
case service.UpdateStatus == nil:
}
if service.UpdateStatus == nil {
// The service was changed since we started this update
return nil
case service.UpdateStatus.State == api.UpdateStatus_ROLLBACK_STARTED:
}
if service.UpdateStatus.State == api.UpdateStatus_ROLLBACK_STARTED {
service.UpdateStatus.State = api.UpdateStatus_ROLLBACK_COMPLETED
service.UpdateStatus.Message = "rollback completed"
default:
} else {
service.UpdateStatus.State = api.UpdateStatus_COMPLETED
service.UpdateStatus.Message = "update completed"
}

service.UpdateStatus.CompletedAt = ptypes.MustTimestampProto(time.Now())

return store.UpdateService(tx, service)
Expand All @@ -658,10 +644,3 @@ func (u *Updater) completeUpdate(ctx context.Context, serviceID string, force bo
log.G(ctx).WithError(err).Errorf("failed to mark update of service %s complete", serviceID)
}
}

func (u *Updater) annotationsUpdated(service *api.Service) bool {
if service.PreviousSpec == nil {
return false
}
return !reflect.DeepEqual(service.Spec, service.PreviousSpec)
}

0 comments on commit fb584e7

Please sign in to comment.