Skip to content

Commit

Permalink
[K10-2153] Store actionSet and tomb to map (#5340)
Browse files Browse the repository at this point in the history
* Save actionSet tomb to map

* Fix typo

* Address review comments

* Fix imports

* Make var lowerCase

* Address review comments

* Address Tom's comment

* Store tomb as a pointer
  • Loading branch information
DeepikaDixit authored and Ilya Kislenko committed Apr 4, 2019
1 parent e7a6b50 commit 3836635
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"context"
"fmt"
"reflect"
"sync"

"github.com/pkg/errors"
opkit "github.com/rook/operator-kit"
Expand All @@ -50,10 +51,11 @@ import (

// Controller represents a controller object for kanister custom resources
type Controller struct {
config *rest.Config
crClient versioned.Interface
clientset kubernetes.Interface
recorder record.EventRecorder
config *rest.Config
crClient versioned.Interface
clientset kubernetes.Interface
recorder record.EventRecorder
actionSetTombMap sync.Map
}

// New create controller for watching kanister custom resources created
Expand Down Expand Up @@ -320,8 +322,9 @@ func (c *Controller) handleActionSet(as *crv1alpha1.ActionSet) (err error) {
if as, err = c.crClient.CrV1alpha1().ActionSets(as.GetNamespace()).Update(as); err != nil {
return errors.WithStack(err)
}
ctx := context.Background()
for i := range as.Status.Actions {
if err = c.runAction(context.TODO(), as, i); err != nil {
if err = c.runAction(ctx, as, i); err != nil {
// If runAction returns an error, it is a failure in the synchronous
// part of running the action.
bpName := as.Spec.Actions[i].Blueprint
Expand Down Expand Up @@ -356,6 +359,7 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
}
ns, name := as.GetNamespace(), as.GetName()
t, _ := tomb.WithContext(ctx) // TODO: @Deepika Ignoring child context currently
c.actionSetTombMap.Store(as.Name, t)
t.Go(func() error {
for i, p := range phases {
c.logAndSuccessEvent(fmt.Sprintf("Executing phase %s", p.Name()), "Started Phase", as)
Expand Down

0 comments on commit 3836635

Please sign in to comment.