[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Commit

Permalink
Refine updateRemoteFrameworkStatus (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
yqwang-ms committed Jul 17, 2019
1 parent 63422e0 commit 1fb9e25
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func (c *FrameworkController) Run(stopCh <-chan struct{}) {
c.fInformer.HasSynced,
c.cmInformer.HasSynced,
c.podInformer.HasSynced) {
panic("Failed to WaitForCacheSync")
panic(fmt.Errorf("Failed to WaitForCacheSync"))
}

log.Infof("Running %v with %v workers",
Expand Down Expand Up @@ -1449,34 +1449,38 @@ func (c *FrameworkController) updateRemoteFrameworkStatus(f *ci.Framework) error
log.Infof(logPfx + "Started")
defer func() { log.Infof(logPfx + "Completed") }()

updateF := f
tried := false
updateErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
updateF.Status = f.Status
_, updateErr := c.fClient.FrameworkcontrollerV1().Frameworks(updateF.Namespace).Update(updateF)
if updateErr == nil {
return nil
}

// Try to resolve conflict by patching more recent object.
localF, getErr := c.fLister.Frameworks(updateF.Namespace).Get(updateF.Name)
if getErr != nil {
if apiErrors.IsNotFound(getErr) {
return fmt.Errorf("Framework cannot be found in local cache: %v", getErr)
} else {
log.Warnf(logPfx+"Framework cannot be got from local cache: %v", getErr)
}
var updateF *ci.Framework
if !tried {
// Using f to update optimistically, since f may not conflict with remote.
updateF = f
tried = true
} else {
// Only resolve conflict for the same object to avoid updating another
// object of the same name.
if f.UID != localF.UID {
return fmt.Errorf(
"Framework UID mismatch: Current UID %v, Local Cached UID %v",
f.UID, localF.UID)
// Only retry on conflict, so f must conflict with remote.
// Try to resolve conflict by patching f.Status on more recent object.
localF, getErr := c.fLister.Frameworks(f.Namespace).Get(f.Name)
if getErr != nil {
if apiErrors.IsNotFound(getErr) {
return fmt.Errorf("Framework cannot be found in local cache: %v", getErr)
} else {
return fmt.Errorf("Framework cannot be got from local cache: %v", getErr)
}
} else {
updateF = localF.DeepCopy()
// Only resolve conflict for the same object to avoid updating another
// object of the same name.
if f.UID != localF.UID {
return fmt.Errorf(
"Framework UID mismatch: Current UID %v, Local Cached UID %v",
f.UID, localF.UID)
} else {
updateF = localF.DeepCopy()
updateF.Status = f.Status
}
}
}

_, updateErr := c.fClient.FrameworkcontrollerV1().Frameworks(updateF.Namespace).Update(updateF)
return updateErr
})

Expand Down

0 comments on commit 1fb9e25

Please sign in to comment.