Skip to content

Commit

Permalink
add clearer error message for pod name too long
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvegamyhre committed Feb 13, 2024
1 parent d985000 commit 09bc836
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/jobset/v1alpha2/jobset_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"fmt"
"math"
"strconv"
"strings"

apivalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -121,6 +122,9 @@ func (js *JobSet) ValidateCreate() (admission.Warnings, error) {
// Add 5 char suffix to the deterministic part of the pod name to validate the full pod name is compliant.
longestPodName := placement.GenPodName(js.Name, rjob.Name, maxJobIndex, maxPodIndex) + "-abcde"
for _, errMessage := range validation.IsDNS1035Label(longestPodName) {
if strings.Contains(errMessage, "must be no more than 63 characters") {
errMessage = "JobSet name must be shorter; pod names generated for this JobSet will exceed 63 characters."
}
allErrs = append(allErrs, fmt.Errorf(errMessage))
}
}
Expand Down
2 changes: 1 addition & 1 deletion api/jobset/v1alpha2/jobset_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ func TestValidateCreate(t *testing.T) {
},
},
want: errors.Join(
fmt.Errorf("must be no more than 63 characters"),
fmt.Errorf("JobSet name must be shorter; pod names generated for this JobSet will exceed 63 characters."),
),
},
}
Expand Down

0 comments on commit 09bc836

Please sign in to comment.