Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move constants from field package to consts package #297

Merged
merged 1 commit into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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