Skip to content

Commit

Permalink
[CPS-6393] fix(resync): resync the release controller when occured un…
Browse files Browse the repository at this point in the history
…known error (#152) (#156)

* [CPS-6393]fix(resync): resync the release controller when occured unknown error (#152)

* [CPS-6393]fix(resync): resync the release controller when occured unknown error

* use time.During instead of int32

Co-authored-by: Lisheng Zheng <[email protected]>

* fix lint error

Co-authored-by: Lisheng Zheng <[email protected]>
  • Loading branch information
whalecold and Lisheng Zheng authored Jun 28, 2020
1 parent e2db779 commit 67124bc
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.ReleaseResyncPeriod,
)
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 time.Duration,
) (*Controller, 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,
})
}, reSyncPeriod)
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 67124bc

Please sign in to comment.