Skip to content

Commit

Permalink
Merge pull request #51 from ibuildthecloud/master
Browse files Browse the repository at this point in the history
Properly compare and mutate status
  • Loading branch information
ibuildthecloud authored Dec 5, 2019
2 parents 2a833f7 + 661f00f commit a1c3d06
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/controller-gen/generators/type_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,24 +343,24 @@ func (a *{{.lowerName}}StatusHandler) sync(key string, obj *{{.version}}.{{.type
return obj, nil
}
status := obj.Status
origStatus := obj.Status
obj = obj.DeepCopy()
newStatus, err := a.handler(obj, obj.Status)
if err != nil {
// Revert to old status on error
newStatus = *status.DeepCopy()
newStatus = *origStatus.DeepCopy()
}
obj.Status = newStatus
if a.condition != "" {
if errors.IsConflict(err) {
a.condition.SetError(obj, "", nil)
} else {
a.condition.SetError(obj, "", err)
}
}
if !equality.Semantic.DeepEqual(status, newStatus) {
if !equality.Semantic.DeepEqual(origStatus, obj.Status) {
var newErr error
obj.Status = newStatus
obj, newErr = a.client.UpdateStatus(obj)
if err == nil {
err = newErr
Expand Down

0 comments on commit a1c3d06

Please sign in to comment.