Skip to content

Commit

Permalink
Move constants from field repo to consts repo (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
SupriyaKasten authored and julio-lopez committed Sep 17, 2019
1 parent 7b5a740 commit 8a6de45
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
8 changes: 8 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package consts

const (
ActionsetNameKey = "ActionSet"
PodNameKey = "Pod"
ContainerNameKey = "Container"
PhaseNameKey = "Phase"
)
9 changes: 5 additions & 4 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/client/clientset/versioned"
"github.com/kanisterio/kanister/pkg/client/clientset/versioned/scheme"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/eventer"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/param"
Expand Down Expand Up @@ -269,7 +270,7 @@ func (c *Controller) onDeleteBlueprint(bp *crv1alpha1.Blueprint) error {

func (c *Controller) initActionSetStatus(as *crv1alpha1.ActionSet) {
ctx := context.Background()
ctx = field.Context(ctx, field.ActionsetNameKey, as.GetName())
ctx = field.Context(ctx, consts.ActionsetNameKey, as.GetName())
if as.Spec == nil {
log.WithContext(ctx).Error("Cannot initialize an ActionSet without a spec.")
return
Expand Down Expand Up @@ -345,7 +346,7 @@ func (c *Controller) handleActionSet(as *crv1alpha1.ActionSet) (err error) {
return errors.WithStack(err)
}
ctx := context.Background()
ctx = field.Context(ctx, field.ActionsetNameKey, as.GetName())
ctx = field.Context(ctx, consts.ActionsetNameKey, as.GetName())
for i := range as.Status.Actions {
if err = c.runAction(ctx, as, i); err != nil {
// If runAction returns an error, it is a failure in the synchronous
Expand Down Expand Up @@ -384,10 +385,10 @@ func (c *Controller) runAction(ctx context.Context, as *crv1alpha1.ActionSet, aI
var t *tomb.Tomb
t, ctx = tomb.WithContext(ctx)
c.actionSetTombMap.Store(as.Name, t)
ctx = field.Context(ctx, field.ActionsetNameKey, as.GetName())
ctx = field.Context(ctx, consts.ActionsetNameKey, as.GetName())
t.Go(func() error {
for i, p := range phases {
ctx = field.Context(ctx, field.PhaseNameKey, p.Name())
ctx = field.Context(ctx, consts.PhaseNameKey, p.Name())
c.logAndSuccessEvent(ctx, fmt.Sprintf("Executing phase %s", p.Name()), "Started Phase", as)
err = param.InitPhaseParams(ctx, c.clientset, tp, p.Name(), p.Objects())
var output map[string]interface{}
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
crv1alpha1 "github.com/kanisterio/kanister/pkg/apis/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/client/clientset/versioned/scheme"
crclientv1alpha1 "github.com/kanisterio/kanister/pkg/client/clientset/versioned/typed/cr/v1alpha1"
"github.com/kanisterio/kanister/pkg/consts"
"github.com/kanisterio/kanister/pkg/eventer"
"github.com/kanisterio/kanister/pkg/field"
"github.com/kanisterio/kanister/pkg/kube"
Expand Down Expand Up @@ -400,7 +401,7 @@ func (s *ControllerSuite) TestRuntimeObjEventLogs(c *C) {

//Test the logAndErrorEvent function
ctx := context.Background()
ctx = field.Context(ctx, field.ActionsetNameKey, as.GetName())
ctx = field.Context(ctx, consts.ActionsetNameKey, as.GetName())
config, err := kube.LoadConfig()
c.Assert(err, IsNil)
ctlr := New(config)
Expand Down
7 changes: 0 additions & 7 deletions pkg/field/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import "context"

// context.Context support for fields

const (
ActionsetNameKey = "ActionSet"
PodNameKey = "Pod"
ContainerNameKey = "Container"
PhaseNameKey = "Phase"
)

type contextKey uint8

const ctxKey = contextKey(43)
Expand Down

0 comments on commit 8a6de45

Please sign in to comment.