Skip to content

Commit

Permalink
[kjobctl] Add validation for priority required field. (#3418)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbobrovskyi authored Nov 4, 2024
1 parent 9f77f52 commit 8ac14ac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/experimental/kjobctl/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var (
noNTasksSpecifiedErr = errors.New("no ntasks specified")
noOutputSpecifiedErr = errors.New("no output specified")
noPartitionSpecifiedErr = errors.New("no partition specified")
noPrioritySpecifiedErr = errors.New("no priority specified")
noTimeSpecifiedErr = errors.New("no time specified")
)

Expand Down Expand Up @@ -461,6 +462,10 @@ func (b *Builder) validateFlags() error {
return noPartitionSpecifiedErr
}

if slices.Contains(b.mode.RequiredFlags, v1alpha1.PriorityFlag) && b.priority == "" {
return noPrioritySpecifiedErr
}

if slices.Contains(b.mode.RequiredFlags, v1alpha1.TimeFlag) && b.timeLimit == "" {
return noTimeSpecifiedErr
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/experimental/kjobctl/pkg/builder/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,20 @@ func TestBuilder(t *testing.T) {
},
wantErr: noPartitionSpecifiedErr,
},
"shouldn't build job because priority not specified with required flags": {
namespace: metav1.NamespaceDefault,
profile: "profile",
mode: v1alpha1.SlurmMode,
kjobctlObjs: []runtime.Object{
wrappers.MakeApplicationProfile("profile", metav1.NamespaceDefault).
WithSupportedMode(v1alpha1.SupportedMode{
Name: v1alpha1.SlurmMode,
RequiredFlags: []v1alpha1.Flag{v1alpha1.PriorityFlag},
}).
Obj(),
},
wantErr: noPrioritySpecifiedErr,
},
"should build job": {
namespace: metav1.NamespaceDefault,
profile: "profile",
Expand Down

0 comments on commit 8ac14ac

Please sign in to comment.