Skip to content

Commit

Permalink
restore the image cache spec to original contents during invalid spec…
Browse files Browse the repository at this point in the history
… update
  • Loading branch information
senthilrch committed Nov 28, 2018
1 parent 77ce7d4 commit a7e6be0
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions cmd/app/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ func (c *Controller) syncHandler(wqKey images.WorkQueueKey) error {
status.Reason = fledgedv1alpha1.ImageCacheReasonNotSupportedUpdates
status.Message = fledgedv1alpha1.ImageCacheMessageNotSupportedUpdates

if err = c.updateImageCacheStatus(imageCache, status); err != nil {
glog.Errorf("Error updating imagecache status to %s: %v", status.Status, err)
// Restore the Spec to it's original contents + update status
if err = c.updateImageCacheSpecAndStatus(imageCache, &wqKey.OldImageCache.Spec, status); err != nil {
glog.Errorf("Error updating imagecache spec and status to %s: %v", status.Status, err)
return err
}
glog.Errorf("%s: %s", fledgedv1alpha1.ImageCacheReasonNotSupportedUpdates, "Mismatch in no. of image lists")
Expand All @@ -481,8 +482,9 @@ func (c *Controller) syncHandler(wqKey images.WorkQueueKey) error {
status.Reason = fledgedv1alpha1.ImageCacheReasonNotSupportedUpdates
status.Message = fledgedv1alpha1.ImageCacheMessageNotSupportedUpdates

if err = c.updateImageCacheStatus(imageCache, status); err != nil {
glog.Errorf("Error updating imagecache status to %s: %v", status.Status, err)
// Restore the Spec to it's original contents + update status
if err = c.updateImageCacheSpecAndStatus(imageCache, &wqKey.OldImageCache.Spec, status); err != nil {
glog.Errorf("Error updating imagecache spec and status to %s: %v", status.Status, err)
return err
}
glog.Errorf("%s: %s", fledgedv1alpha1.ImageCacheReasonNotSupportedUpdates, "Mismatch in node selector")
Expand Down Expand Up @@ -688,6 +690,14 @@ func (c *Controller) updateImageCacheStatus(imageCache *fledgedv1alpha1.ImageCac
return err
}

func (c *Controller) updateImageCacheSpecAndStatus(imageCache *fledgedv1alpha1.ImageCache, spec *fledgedv1alpha1.ImageCacheSpec, status *fledgedv1alpha1.ImageCacheStatus) error {
imageCacheCopy := imageCache.DeepCopy()
imageCacheCopy.Spec = *spec
imageCacheCopy.Status = *status
_, err := c.fledgedclientset.FledgedV1alpha1().ImageCaches(imageCache.Namespace).Update(imageCacheCopy)
return err
}

func (c *Controller) addFinalizer(imageCache *fledgedv1alpha1.ImageCache) error {
if len(imageCache.Finalizers) != 0 && strings.Contains(strings.Join(imageCache.Finalizers, ":"), fledgedFinalizer) {
return nil
Expand Down

0 comments on commit a7e6be0

Please sign in to comment.