Skip to content

Commit

Permalink
Merge pull request #76 from volcano-sh/task-name
Browse files Browse the repository at this point in the history
Fix task name default and validate it
  • Loading branch information
Klaus Ma committed Apr 9, 2019
2 parents c22aacc + 5c2dda3 commit e92c859
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions pkg/admission/admit_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (

"k8s.io/api/admission/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/validation"

v1alpha1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

// job admit.
func AdmitJobs(ar v1beta1.AdmissionReview) *v1beta1.AdmissionResponse {

glog.V(3).Infof("admitting jobs -- %s", ar.Request.Operation)

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

// validate task name
if errMsgs := validation.IsDNS1123Label(task.Name); len(errMsgs) > 0 {
msg = msg + fmt.Sprintf(" %v;", errMsgs)
}

// duplicate task name
if _, found := taskNames[task.Name]; found {
msg = msg + fmt.Sprintf(" duplicated task name %s;", task.Name)
Expand Down
3 changes: 2 additions & 1 deletion pkg/admission/mutate_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"encoding/json"
"fmt"
"math/rand"
"strconv"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -83,7 +84,7 @@ func mutateSpec(tasks []v1alpha1.TaskSpec, basePath string) (patch []patchOperat
// add default task name
taskName := tasks[index].Name
if len(taskName) == 0 {
tasks[index].Name = v1alpha1.DefaultTaskSpec
tasks[index].Name = v1alpha1.DefaultTaskSpec + strconv.Itoa(index)
}
}
patch = append(patch, patchOperation{
Expand Down

0 comments on commit e92c859

Please sign in to comment.