Skip to content

Commit 84e5064

Browse files
author
Klaus Ma
authored
Merge pull request volcano-sh#76 from volcano-sh/task-name
2 parents 4b38e1e + 083428a commit 84e5064

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/admission/admit_job.go

+7
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ import (
2626

2727
"k8s.io/api/admission/v1beta1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/util/validation"
2930

3031
v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
3132
)
3233

3334
// job admit.
3435
func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {
36+
3537
glog.V(3).Infof("admitting jobs -- %s", ar.Request.Operation)
3638

3739
job, err := DecodeJob(ar.Request.Object, ar.Request.Resource)
@@ -83,6 +85,11 @@ func validateJobSpec(jobSpec v1alpha1.JobSpec, reviewResponse *v1beta1.Admission
8385
// count replicas
8486
totalReplicas = totalReplicas + task.Replicas
8587

88+
// validate task name
89+
if errMsgs := validation.IsDNS1123Label(task.Name); len(errMsgs) > 0 {
90+
msg = msg + fmt.Sprintf(" %v;", errMsgs)
91+
}
92+
8693
// duplicate task name
8794
if _, found := taskNames[task.Name]; found {
8895
msg = msg + fmt.Sprintf(" duplicated task name %s;", task.Name)

pkg/admission/mutate_job.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"encoding/json"
2121
"fmt"
2222
"math/rand"
23+
"strconv"
2324
"time"
2425

2526
"github.com/golang/glog"
@@ -83,7 +84,7 @@ func mutateSpec(tasks []v1alpha1.TaskSpec, basePath string) (patch []patchOperat
8384
// add default task name
8485
taskName := tasks[index].Name
8586
if len(taskName) == 0 {
86-
tasks[index].Name = v1alpha1.DefaultTaskSpec
87+
tasks[index].Name = v1alpha1.DefaultTaskSpec + strconv.Itoa(index)
8788
}
8889
}
8990
patch = append(patch, patchOperation{

0 commit comments

Comments
 (0)