Skip to content

Commit

Permalink
[CPS-6393]fix(resync): resync the release controller when occured unk…
Browse files Browse the repository at this point in the history
…nown error (#151)

Co-authored-by: Lisheng Zheng <[email protected]>
  • Loading branch information
whalecold and Lisheng Zheng authored Apr 16, 2020
1 parent ceb4016 commit eac52d4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/controller/app/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func startReleaseController(ctx ControllerContext) error {
ctx.KubeClient.ReleaseV1alpha1(),
ctx.InformerFactory.Release().V1alpha1().Releases(),
ctx.IgnoredKinds,
ctx.ResyncPeriod,
)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions pkg/controller/release/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func NewReleaseController(
releaseClient releasev1alpha1.ReleaseV1alpha1Interface,
releaseInformer informerrelease.ReleaseInformer,
ignored []schema.GroupVersionKind,
reSyncPeriod int32,
) (*ReleaseController, error) {
client, err := kube.NewClientWithCacheLayer(clients, codec, store)
if err != nil {
Expand All @@ -48,13 +49,13 @@ func NewReleaseController(
releaseLister: releaseInformer.Lister(),
releaseHasSynced: releaseInformer.Informer().HasSynced,
}
releaseInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
releaseInformer.Informer().AddEventHandlerWithResyncPeriod(cache.ResourceEventHandlerFuncs{
AddFunc: rc.enqueueRelease,
UpdateFunc: func(oldObj, newObj interface{}) {
rc.enqueueRelease(newObj)
},
DeleteFunc: rc.enqueueRelease,
})
}, time.Duration(reSyncPeriod)*time.Second)
return rc, nil
}

Expand Down
10 changes: 9 additions & 1 deletion pkg/release/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ FOR:
if !(target != nil && rel.Spec.RollbackTo == nil &&
target.Spec.Config == rel.Spec.Config &&
reflect.DeepEqual(target.Spec.Suspend, rel.Spec.Suspend) &&
reflect.DeepEqual(target.Spec.Template, rel.Spec.Template)) {
reflect.DeepEqual(target.Spec.Template, rel.Spec.Template) &&
normalCondition(rel)) {
// Config was changed. Add it to queue.
target = rel
queue.Forget(target.Name)
Expand All @@ -88,3 +89,10 @@ FOR:

glog.V(2).Infof("Stopped handler: %s", getter.Key())
}

func normalCondition(rel *releaseapi.Release) bool {
if len(rel.Status.Conditions) == 0 {
return false
}
return rel.Status.Conditions[0].Type != releaseapi.ReleaseFailure
}

0 comments on commit eac52d4

Please sign in to comment.