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

Fix task name default and validate it #76

Merged
merged 2 commits into from
Apr 9, 2019
Merged
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
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