Skip to content

Commit

Permalink
Merge pull request kubernetes#90172 from nak3/add-IsDNS1123Label
Browse files Browse the repository at this point in the history
Add DNS1123Label validation to IsFullyQualifiedDomainName() func
  • Loading branch information
k8s-ci-robot committed Jun 28, 2020
2 parents 9238fb1 + 18856da commit aadaa5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ func IsFullyQualifiedDomainName(fldPath *field.Path, name string) field.ErrorLis
if len(strings.Split(name, ".")) < 2 {
return append(allErrors, field.Invalid(fldPath, name, "should be a domain with at least two segments separated by dots"))
}
for _, label := range strings.Split(name, ".") {
if errs := IsDNS1123Label(label); len(errs) > 0 {
return append(allErrors, field.Invalid(fldPath, label, strings.Join(errs, ",")))
}
}
return allErrors
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ func TestIsFullyQualifiedDomainName(t *testing.T) {
"bbc.co.uk",
"10.0.0.1", // DNS labels can start with numbers and there is no requirement for letters.
"hyphens-are-good.k8s.io",
strings.Repeat("a", 246) + ".k8s.io",
strings.Repeat("a", 63) + ".k8s.io",
strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + strings.Repeat("c", 63) + "." + strings.Repeat("d", 54) + ".k8s.io",
}
for _, val := range goodValues {
if err := IsFullyQualifiedDomainName(field.NewPath(""), val).ToAggregate(); err != nil {
Expand All @@ -579,7 +580,8 @@ func TestIsFullyQualifiedDomainName(t *testing.T) {
"underscores_are_bad.k8s.io",
"foo@bar.example.com",
"http://foo.example.com",
strings.Repeat("a", 247) + ".k8s.io",
strings.Repeat("a", 64) + ".k8s.io",
strings.Repeat("a", 63) + "." + strings.Repeat("b", 63) + "." + strings.Repeat("c", 63) + "." + strings.Repeat("d", 55) + ".k8s.io",
}
for _, val := range badValues {
if err := IsFullyQualifiedDomainName(field.NewPath(""), val).ToAggregate(); err == nil {
Expand Down

0 comments on commit aadaa5d

Please sign in to comment.