Skip to content

Commit 856c7a8

Browse files
Merge pull request #84 from roivaz/fix/propagate-conext-to-stoppable-manager
Propagate the context to the stoppable-managers for ordered shutdown
2 parents 4361490 + a544593 commit 856c7a8

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

pkg/util/lockedresourcecontroller/enforcing-reconciler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (er *EnforcingReconciler) UpdateLockedResourcesWithRestConfig(context conte
113113
er.log.Error(err, "unable to delete unmanaged", "resources", leftDifference)
114114
return err
115115
}
116-
err := lockedResourceManager.Restart(lockedResources, lockedPatches, false, config)
116+
err := lockedResourceManager.Restart(context, lockedResources, lockedPatches, false, config)
117117
if err != nil {
118118
er.log.Error(err, "unable to restart", "manager", lockedResourceManager)
119119
return err

pkg/util/lockedresourcecontroller/locked-resource-manager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (lrm *LockedResourceManager) IsStarted() bool {
119119
}
120120

121121
// Start starts the LockedResourceManager
122-
func (lrm *LockedResourceManager) Start(config *rest.Config) error {
122+
func (lrm *LockedResourceManager) Start(ctx context.Context, config *rest.Config) error {
123123
if lrm.stoppableManager != nil && lrm.stoppableManager.IsStarted() {
124124
return nil
125125
}
@@ -165,7 +165,7 @@ func (lrm *LockedResourceManager) Start(config *rest.Config) error {
165165
}
166166
lrm.patchReconcilers = patchReconcilers
167167

168-
lrm.stoppableManager.Start()
168+
lrm.stoppableManager.Start(ctx)
169169
return nil
170170
}
171171

@@ -210,7 +210,8 @@ func (lrm *LockedResourceManager) scanNamespaces() []string {
210210

211211
// Restart restarts the manager with a different set of resources
212212
// if deleteResources is set, resources that were enforced are deleted.
213-
func (lrm *LockedResourceManager) Restart(resources []lockedresource.LockedResource, patches []lockedpatch.LockedPatch, deleteResources bool, config *rest.Config) error {
213+
func (lrm *LockedResourceManager) Restart(ctx context.Context, resources []lockedresource.LockedResource,
214+
patches []lockedpatch.LockedPatch, deleteResources bool, config *rest.Config) error {
214215
if lrm.IsStarted() {
215216
err := lrm.Stop(deleteResources)
216217
if err != nil {
@@ -228,7 +229,7 @@ func (lrm *LockedResourceManager) Restart(resources []lockedresource.LockedResou
228229
lrm.log.Error(err, "unable to set", "patches", patches)
229230
return err
230231
}
231-
return lrm.Start(config)
232+
return lrm.Start(ctx, config)
232233
}
233234

234235
// IsSameResources checks whether the currently enforced resources are the same as the ones passed as parameters

pkg/util/stoppablemanager/stoppable-manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ func (sm *StoppableManager) Stop() {
3030
}
3131

3232
//Start starts the manager. Restarting a starated manager is a noop that will be logged.
33-
func (sm *StoppableManager) Start() {
33+
func (sm *StoppableManager) Start(parentCtx context.Context) {
3434
if sm.started {
3535
log.Error(errors.New("invalid argument"), "start called on a started channel")
3636
return
3737
}
38-
ctx, cancel := context.WithCancel(context.TODO())
38+
ctx, cancel := context.WithCancel(parentCtx)
3939
sm.cancelFunction = cancel
4040
go func() {
4141
err := sm.Manager.Start(ctx)

0 commit comments

Comments
 (0)