From 0204bc18bcf108d9c9e36644610e1fd55a752386 Mon Sep 17 00:00:00 2001 From: Abhijit Mukherjee Date: Tue, 30 Apr 2024 12:17:12 +0530 Subject: [PATCH] Refactor: Move JobID label suffix to constants (#2852) * Introduce jobid suffix as constant Signed-off-by: Abhijit Mukherjee * Addressed review comment Signed-off-by: Abhijit Mukherjee --------- Signed-off-by: Abhijit Mukherjee --- pkg/consts/consts.go | 1 + pkg/function/kube_task.go | 5 ++--- pkg/kube/pod_runner_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go index cc4d37442c..45a63b340b 100644 --- a/pkg/consts/consts.go +++ b/pkg/consts/consts.go @@ -26,6 +26,7 @@ const ( LabelKeyCreatedBy = "createdBy" LabelValueKanister = "kanister" LabelPrefix = "kanister.io/" + LabelSuffixJobID = "JobID" ) // These names are used to query ActionSet API objects. diff --git a/pkg/function/kube_task.go b/pkg/function/kube_task.go index 74b10c4cf8..c7eed9920f 100644 --- a/pkg/function/kube_task.go +++ b/pkg/function/kube_task.go @@ -34,8 +34,7 @@ import ( ) const ( - jobPrefix = "kanister-job-" - jobIDSuffix = "JobID" + jobPrefix = "kanister-job-" // KubeTaskFuncName gives the function name KubeTaskFuncName = "KubeTask" @@ -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) diff --git a/pkg/kube/pod_runner_test.go b/pkg/kube/pod_runner_test.go index 85d250de7a..74432cfd63 100644 --- a/pkg/kube/pod_runner_test.go +++ b/pkg/kube/pod_runner_test.go @@ -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