Skip to content

Commit

Permalink
[K10-2150] Create actionSet func with tomb (#5335)
Browse files Browse the repository at this point in the history
* Create actionSet func with tomb

* Fix imports

* Fix imports

* Fix imports

* Adress review comments
  • Loading branch information
DeepikaDixit authored and Ilya Kislenko committed Apr 4, 2019
1 parent 0139202 commit e7a6b50
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pkg/errors"
opkit "github.com/rook/operator-kit"
log "github.com/sirupsen/logrus"
"gopkg.in/tomb.v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -354,7 +355,8 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
return err
}
ns, name := as.GetNamespace(), as.GetName()
go func() {
t, _ := tomb.WithContext(ctx) // TODO: @Deepika Ignoring child context currently
t.Go(func() error {
for i, p := range phases {
c.logAndSuccessEvent(fmt.Sprintf("Executing phase %s", p.Name()), "Started Phase", as)
err = param.InitPhaseParams(ctx, c.clientset, tp, p.Name(), p.Objects())
Expand Down Expand Up @@ -383,15 +385,15 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
reason := fmt.Sprintf("ActionSetFailed Action: %s", as.Spec.Actions[aIDX].Name)
msg := fmt.Sprintf("Failed to update phase: %#v:", as.Status.Actions[aIDX].Phases[i])
c.logAndErrorEvent(msg, reason, rErr, as, bp)
return
return nil
}
if err != nil {
reason := fmt.Sprintf("ActionSetFailed Action: %s", as.Spec.Actions[aIDX].Name)
if msg == "" {
msg = fmt.Sprintf("Failed to execute phase: %#v:", as.Status.Actions[aIDX].Phases[i])
}
c.logAndErrorEvent(msg, reason, err, as, bp)
return
return nil
}
param.UpdatePhaseParams(ctx, tp, p.Name(), output)
c.logAndSuccessEvent(fmt.Sprintf("Completed phase %s", p.Name()), "Ended Phase", as)
Expand All @@ -408,7 +410,7 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
msg := fmt.Sprintf("Failed to update ActionSet: %s", name)
c.logAndErrorEvent(msg, reason, err, as, bp)
}
return
return nil
}
// Render the artifacts
arts, err := param.RenderArtifacts(artTpls, *tp)
Expand All @@ -430,15 +432,16 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
reason := fmt.Sprintf("ActionSetFailed Action: %s", action.Name)
msg := fmt.Sprintf("Failed to update Output Artifacts: %#v:", artTpls)
c.logAndErrorEvent(msg, reason, aErr, as, bp)
return
return nil
}
if err != nil {
reason := fmt.Sprintf("ActionSetFailed Action: %s", action.Name)
msg := "Failed to render output artifacts"
c.logAndErrorEvent(msg, reason, err, as, bp)
return
return nil
}
}()
return nil
})
return nil
}

Expand Down

0 comments on commit e7a6b50

Please sign in to comment.