Skip to content

Commit

Permalink
Refactor: Move JobID label suffix to constants (#2852)
Browse files Browse the repository at this point in the history
* Introduce jobid suffix as constant

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

* Addressed review comment

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>

---------

Signed-off-by: Abhijit Mukherjee <abhijit.mukherjee@infracloud.io>
  • Loading branch information
mabhi authored Apr 30, 2024
1 parent 592e4f3 commit 0204bc1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
LabelKeyCreatedBy = "createdBy"
LabelValueKanister = "kanister"
LabelPrefix = "kanister.io/"
LabelSuffixJobID = "JobID"
)

// These names are used to query ActionSet API objects.
Expand Down
5 changes: 2 additions & 3 deletions pkg/function/kube_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import (
)

const (
jobPrefix = "kanister-job-"
jobIDSuffix = "JobID"
jobPrefix = "kanister-job-"

// KubeTaskFuncName gives the function name
KubeTaskFuncName = "KubeTask"
Expand Down Expand Up @@ -68,7 +67,7 @@ func kubeTask(ctx context.Context, cli kubernetes.Interface, namespace, image st
PodOverride: podOverride,
}
// Mark pod with label having key `kanister.io/JobID`, the value of which is a reference to the origin of the pod.
kube.AddLabelsToPodOptionsFromContext(ctx, options, path.Join(consts.LabelPrefix, jobIDSuffix))
kube.AddLabelsToPodOptionsFromContext(ctx, options, path.Join(consts.LabelPrefix, consts.LabelSuffixJobID))
pr := kube.NewPodRunner(cli, options)
podFunc := kubeTaskPodFunc()
return pr.Run(ctx, podFunc)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kube/pod_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (s *PodRunnerTestSuite) TestPodRunnerForSuccessCase(c *C) {
// TestPodRunnerWithDebugLabelForSuccessCase adds a debug entry into the context and verifies the
// pod got created with corresponding label using the entry or not.
func (s *PodRunnerTestSuite) TestPodRunnerWithDebugLabelForSuccessCase(c *C) {
jobIDSuffix := "JobID"
jobIDSuffix := consts.LabelSuffixJobID
for _, tc := range []struct {
name string
targetKey string
Expand Down

0 comments on commit 0204bc1

Please sign in to comment.