diff --git a/cmd/experimental/kjobctl/pkg/builder/slurm_builder.go b/cmd/experimental/kjobctl/pkg/builder/slurm_builder.go index 9f52fb883e..fd1b643239 100644 --- a/cmd/experimental/kjobctl/pkg/builder/slurm_builder.go +++ b/cmd/experimental/kjobctl/pkg/builder/slurm_builder.go @@ -36,6 +36,7 @@ import ( "k8s.io/utils/ptr" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/apis/v1alpha1" + kjobctlconstants "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/constants" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/parser" ) @@ -197,6 +198,13 @@ func (b *slurmBuilder) build(ctx context.Context) (runtime.Object, []runtime.Obj return nil, nil, err } + if b.script != "" { + if objectMeta.Annotations == nil { + objectMeta.Annotations = make(map[string]string, 1) + } + objectMeta.Annotations[kjobctlconstants.ScriptAnnotation] = b.script + } + job := &batchv1.Job{ TypeMeta: metav1.TypeMeta{Kind: "Job", APIVersion: "batch/v1"}, ObjectMeta: objectMeta, diff --git a/cmd/experimental/kjobctl/pkg/builder/slurm_builder_test.go b/cmd/experimental/kjobctl/pkg/builder/slurm_builder_test.go index 28b081caed..78fe933776 100644 --- a/cmd/experimental/kjobctl/pkg/builder/slurm_builder_test.go +++ b/cmd/experimental/kjobctl/pkg/builder/slurm_builder_test.go @@ -331,6 +331,13 @@ export $(cat /slurm/env/$JOB_CONTAINER_INDEX/slurm.env | xargs) defaultCmpOpts := []cmp.Option{cmpopts.IgnoreFields(metav1.ObjectMeta{}, "Name")} opts = append(defaultCmpOpts, tc.cmpopts...) + if job, ok := tc.wantRootObj.(*batchv1.Job); ok { + if job.Annotations == nil { + job.Annotations = make(map[string]string, 1) + } + job.Annotations[constants.ScriptAnnotation] = tc.tempFile + } + if diff := cmp.Diff(tc.wantRootObj, gotRootObj, opts...); diff != "" { t.Errorf("Root object after build (-want,+got):\n%s", diff) } diff --git a/cmd/experimental/kjobctl/pkg/cmd/create/create_test.go b/cmd/experimental/kjobctl/pkg/cmd/create/create_test.go index b29b8f874b..fd93421444 100644 --- a/cmd/experimental/kjobctl/pkg/cmd/create/create_test.go +++ b/cmd/experimental/kjobctl/pkg/cmd/create/create_test.go @@ -2085,6 +2085,15 @@ export $(cat /slurm/env/$JOB_CONTAINER_INDEX/slurm.env | xargs)cd /mydir return } + if job, ok := tc.wantLists[index].(*batchv1.JobList); ok && len(job.Items) > 0 { + if tc.tempFile != "" { + if job.Items[0].Annotations == nil { + job.Items[0].Annotations = make(map[string]string) + } + job.Items[0].Annotations[constants.ScriptAnnotation] = tc.tempFile + } + } + if diff := cmp.Diff(tc.wantLists[index], gotList, tc.cmpopts...); diff != "" { t.Errorf("Unexpected list for %s (-want/+got)\n%s", gvk.String(), diff) } diff --git a/cmd/experimental/kjobctl/pkg/cmd/describe/describe_printer.go b/cmd/experimental/kjobctl/pkg/cmd/describe/describe_printer.go index 28fe583633..c8c3ba0d93 100644 --- a/cmd/experimental/kjobctl/pkg/cmd/describe/describe_printer.go +++ b/cmd/experimental/kjobctl/pkg/cmd/describe/describe_printer.go @@ -86,6 +86,7 @@ func describeJob(job *batchv1.Job) (string, error) { w.Write(IndentLevelZero, "Name:\t%s\n", job.Name) w.Write(IndentLevelZero, "Namespace:\t%s\n", job.Namespace) printLabelsMultiline(w, "Labels", job.Labels) + printLabelsMultiline(w, "Annotations", job.Annotations) if job.Spec.Parallelism != nil { w.Write(IndentLevelZero, "Parallelism:\t%d\n", *job.Spec.Parallelism) } diff --git a/cmd/experimental/kjobctl/pkg/cmd/describe/describe_test.go b/cmd/experimental/kjobctl/pkg/cmd/describe/describe_test.go index 28b64e5432..20e8898646 100644 --- a/cmd/experimental/kjobctl/pkg/cmd/describe/describe_test.go +++ b/cmd/experimental/kjobctl/pkg/cmd/describe/describe_test.go @@ -42,6 +42,7 @@ import ( "sigs.k8s.io/kueue/cmd/experimental/kjobctl/apis/v1alpha1" cmdtesting "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/cmd/testing" + "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/constants" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/testing/wrappers" ) @@ -79,6 +80,7 @@ func TestDescribeCmd(t *testing.T) { wantOut: `Name: sample-job-8c7zt Namespace: default Labels: kjobctl.x-k8s.io/profile=sample-profile +Annotations: kjobctl.x-k8s.io/script=test.sh Parallelism: 3 Completions: 2 Start Time: Mon, 01 Jan 2024 00:00:00 +0000 @@ -208,6 +210,7 @@ error_path=$(unmask_filename "$SBATCH_ERROR") wantOut: `Name: sample-job-8c7zt Namespace: default Labels: kjobctl.x-k8s.io/profile=sample-profile +Annotations: kjobctl.x-k8s.io/script=test.sh Parallelism: 3 Completions: 2 Start Time: Mon, 01 Jan 2024 00:00:00 +0000 @@ -349,6 +352,7 @@ BinaryData wantOut: `Name: sample-job-8c7zt Namespace: default Labels: kjobctl.x-k8s.io/profile=sample-profile +Annotations: kjobctl.x-k8s.io/script=test.sh Parallelism: 3 Completions: 2 Start Time: Mon, 01 Jan 2024 00:00:00 +0000 @@ -390,6 +394,7 @@ Pod Template: wantOut: `Name: sample-job-5zd6r Namespace: default Labels: kjobctl.x-k8s.io/profile=sample-profile +Annotations: kjobctl.x-k8s.io/script=test.sh Parallelism: 3 Completions: 2 Start Time: Mon, 01 Jan 2024 00:00:00 +0000 @@ -417,6 +422,7 @@ Pod Template: Name: sample-job-8c7zt Namespace: default Labels: kjobctl.x-k8s.io/profile=sample-profile +Annotations: kjobctl.x-k8s.io/script=test.sh Parallelism: 3 Completions: 2 Start Time: Mon, 01 Jan 2024 00:00:00 +0000 @@ -744,6 +750,9 @@ func getSampleJob(name string) *batchv1.Job { Labels: map[string]string{ "kjobctl.x-k8s.io/profile": "sample-profile", }, + Annotations: map[string]string{ + constants.ScriptAnnotation: "test.sh", + }, }, Spec: batchv1.JobSpec{ Parallelism: ptr.To[int32](3), diff --git a/cmd/experimental/kjobctl/pkg/constants/constants.go b/cmd/experimental/kjobctl/pkg/constants/constants.go index a243442e47..778cb95c38 100644 --- a/cmd/experimental/kjobctl/pkg/constants/constants.go +++ b/cmd/experimental/kjobctl/pkg/constants/constants.go @@ -17,8 +17,9 @@ limitations under the License. package constants const ( - ProfileLabel = "kjobctl.x-k8s.io/profile" - ModeLabel = "kjobctl.x-k8s.io/mode" + ProfileLabel = "kjobctl.x-k8s.io/profile" + ModeLabel = "kjobctl.x-k8s.io/mode" + ScriptAnnotation = "kjobctl.x-k8s.io/script" ) const ( diff --git a/cmd/experimental/kjobctl/test/e2e/slurm_test.go b/cmd/experimental/kjobctl/test/e2e/slurm_test.go index 5ddb852c05..eaec679863 100644 --- a/cmd/experimental/kjobctl/test/e2e/slurm_test.go +++ b/cmd/experimental/kjobctl/test/e2e/slurm_test.go @@ -36,6 +36,7 @@ import ( "sigs.k8s.io/kueue/pkg/util/maps" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/apis/v1alpha1" + kjobctlconstants "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/constants" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/pkg/testing/wrappers" "sigs.k8s.io/kueue/cmd/experimental/kjobctl/test/util" ) @@ -122,7 +123,7 @@ var _ = ginkgo.Describe("Slurm", ginkgo.Ordered, func() { gomega.Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: jobName}, job)).To(gomega.Succeed()) gomega.Expect(ptr.Deref(job.Spec.Completions, 1)).To(gomega.Equal(expectCompletions)) gomega.Expect(ptr.Deref(job.Spec.Parallelism, 1)).To(gomega.Equal(expectParallelism)) - + gomega.Expect(job.Annotations).To(gomega.HaveKeyWithValue(kjobctlconstants.ScriptAnnotation, script.Name())) gomega.Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: configMapName}, configMap)).To(gomega.Succeed()) gomega.Expect(k8sClient.Get(ctx, client.ObjectKey{Namespace: ns.Name, Name: serviceName}, service)).To(gomega.Succeed()) })