Skip to content

Commit

Permalink
[kjobctl] Provide the path of the executed script in the describe Slu…
Browse files Browse the repository at this point in the history
…rm command. (#3534)

* Provide path of the executed script in kjobctl describe slurm

Signed-off-by: Horiodino <[email protected]>

* added test case

Signed-off-by: Horiodino <[email protected]>

* Update annotation to kjobctl.x-k8s.io/script

Signed-off-by: Horiodino <[email protected]>

---------

Signed-off-by: Horiodino <[email protected]>
  • Loading branch information
Horiodino authored Nov 18, 2024
1 parent 9987c0d commit e49265b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/experimental/kjobctl/pkg/builder/slurm_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions cmd/experimental/kjobctl/pkg/builder/slurm_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/experimental/kjobctl/pkg/cmd/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions cmd/experimental/kjobctl/pkg/cmd/describe/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
5 changes: 3 additions & 2 deletions cmd/experimental/kjobctl/pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion cmd/experimental/kjobctl/test/e2e/slurm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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())
})
Expand Down

0 comments on commit e49265b

Please sign in to comment.