Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kjobctl] Skip kueue labels on child objects. #3455

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cmd/experimental/kjobctl/pkg/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,24 @@ func (b *Builder) buildObjectMeta(templateObjectMeta metav1.ObjectMeta) metav1.O
Annotations: templateObjectMeta.Annotations,
}

b.withKjobLabels(&objectMeta)
b.withKueueLabels(&objectMeta)

return objectMeta
}

func (b *Builder) buildChildObjectMeta() metav1.ObjectMeta {
objectMeta := metav1.ObjectMeta{
Namespace: b.profile.Namespace,
GenerateName: b.generatePrefixName(),
}

b.withKjobLabels(&objectMeta)

return objectMeta
}

func (b *Builder) withKjobLabels(objectMeta *metav1.ObjectMeta) {
if objectMeta.Labels == nil {
objectMeta.Labels = map[string]string{}
}
Expand All @@ -552,6 +570,12 @@ func (b *Builder) buildObjectMeta(templateObjectMeta metav1.ObjectMeta) metav1.O
if b.mode != nil {
objectMeta.Labels[constants.ModeLabel] = string(b.mode.Name)
}
}

func (b *Builder) withKueueLabels(objectMeta *metav1.ObjectMeta) {
if objectMeta.Labels == nil {
objectMeta.Labels = map[string]string{}
}

if len(b.localQueue) > 0 {
objectMeta.Labels[kueueconstants.QueueLabel] = b.localQueue
Expand All @@ -560,8 +584,6 @@ func (b *Builder) buildObjectMeta(templateObjectMeta metav1.ObjectMeta) metav1.O
if len(b.priority) != 0 {
objectMeta.Labels[kueueconstants.WorkloadPriorityClassLabel] = b.priority
}

return objectMeta
}

func (b *Builder) buildPodSpec(templateSpec corev1.PodSpec) corev1.PodSpec {
Expand Down
34 changes: 24 additions & 10 deletions cmd/experimental/kjobctl/pkg/builder/slurm_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ func (b *slurmBuilder) validateMutuallyExclusiveFlags() error {
return nil
}

func (b *slurmBuilder) buildObjectMeta(templateObjectMeta metav1.ObjectMeta) metav1.ObjectMeta {
objectMeta := b.Builder.buildObjectMeta(templateObjectMeta)
objectMeta.GenerateName = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks strange, maybe b.Builder.buildObjectMeta(templateObjectMeta) should not set GeneratName if it's not generally useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s used in other modes. Only Slurm no need it for now.

objectMeta.Name = b.objectName

if b.maxExecutionTimeSeconds != nil {
objectMeta.Labels[constants.MaxExecTimeSecondsLabel] = fmt.Sprint(ptr.Deref(b.maxExecutionTimeSeconds, 0))
}

return objectMeta
}

func (b *slurmBuilder) buildChildObjectMeta() metav1.ObjectMeta {
objectMeta := b.Builder.buildChildObjectMeta()
objectMeta.GenerateName = ""
objectMeta.Name = b.objectName

return objectMeta
}

func (b *slurmBuilder) build(ctx context.Context) (runtime.Object, []runtime.Object, error) {
if err := b.validateGeneral(); err != nil {
return nil, nil, err
Expand All @@ -205,18 +225,12 @@ func (b *slurmBuilder) build(ctx context.Context) (runtime.Object, []runtime.Obj
return nil, nil, err
}

objectMeta := b.buildObjectMeta(template.Template.ObjectMeta)
objectMeta.GenerateName = ""
objectMeta.Name = b.objectName

job := &batchv1.Job{
TypeMeta: metav1.TypeMeta{Kind: "Job", APIVersion: "batch/v1"},
ObjectMeta: objectMeta,
ObjectMeta: b.buildObjectMeta(template.Template.ObjectMeta),
Spec: template.Template.Spec,
}
if b.maxExecutionTimeSeconds != nil {
job.Labels[constants.MaxExecTimeSecondsLabel] = fmt.Sprint(ptr.Deref(b.maxExecutionTimeSeconds, 0))
}

job.Spec.CompletionMode = ptr.To(batchv1.IndexedCompletion)
job.Spec.Template.Spec.Subdomain = b.objectName

Expand Down Expand Up @@ -435,7 +449,7 @@ func (b *slurmBuilder) build(ctx context.Context) (runtime.Object, []runtime.Obj

configMap := &corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{Kind: "ConfigMap", APIVersion: "v1"},
ObjectMeta: objectMeta,
ObjectMeta: b.buildChildObjectMeta(),
Data: map[string]string{
slurmInitEntrypointFilename: initEntrypointScript,
slurmEntrypointFilename: entrypointScript,
Expand All @@ -445,7 +459,7 @@ func (b *slurmBuilder) build(ctx context.Context) (runtime.Object, []runtime.Obj

service := &corev1.Service{
TypeMeta: metav1.TypeMeta{Kind: "Service", APIVersion: "v1"},
ObjectMeta: objectMeta,
ObjectMeta: b.buildChildObjectMeta(),
Spec: corev1.ServiceSpec{
ClusterIP: "None",
Selector: map[string]string{
Expand Down
2 changes: 0 additions & 2 deletions cmd/experimental/kjobctl/pkg/cmd/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,6 @@ export $(cat /slurm/env/$JOB_CONTAINER_INDEX/slurm.env | xargs)
}).
Profile("profile").
Mode(v1alpha1.SlurmMode).
LocalQueue("lq1").
Data(map[string]string{
"script": "#!/bin/bash\nsleep 300'",
"init-entrypoint.sh": `#!/bin/sh
Expand Down Expand Up @@ -1328,7 +1327,6 @@ export $(cat /slurm/env/$JOB_CONTAINER_INDEX/slurm.env | xargs)cd /mydir
*wrappers.MakeService("profile-slurm", metav1.NamespaceDefault).
Profile("profile").
Mode(v1alpha1.SlurmMode).
LocalQueue("lq1").
ClusterIP("None").
Selector("job-name", "profile-slurm").
WithOwnerReference(metav1.OwnerReference{
Expand Down