Skip to content

Commit 11c2e64

Browse files
authored
Merge pull request #58 from Tova-Rozovsky/valid_DNS
2 parents f7b079c + bb97537 commit 11c2e64

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/api/service.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ const (
3131
)
3232

3333
var serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
34+
var dnsLabelRegexp = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
3435

3536
func ValidateServiceID(id string) bool {
3637
return serviceIDRegexp.MatchString(id)
@@ -103,8 +104,15 @@ func (s *ServiceSpec) Validate() error {
103104
default:
104105
return fmt.Errorf("invalid mode: %q", s.Mode)
105106
}
106-
107-
// TODO: validate the service name is a valid DNS label.
107+
108+
if s.Name != "" {
109+
if len(s.Name) > 63 {
110+
return fmt.Errorf("service name too long (max 63 characters): %q", s.Name)
111+
}
112+
if !dnsLabelRegexp.MatchString(s.Name) {
113+
return fmt.Errorf("invalid service name: %q. must be 1-63 characters, lowercase letters, numbers, and dashes only; must start and end with a letter or number", s.Name)
114+
}
115+
}
108116

109117
for _, p := range s.Ports {
110118
if (p.Mode == "" || p.Mode == PortModeIngress) &&
@@ -138,6 +146,7 @@ func (s *ServiceSpec) Validate() error {
138146
return nil
139147
}
140148

149+
141150
func (s *ServiceSpec) Clone() ServiceSpec {
142151
spec := *s
143152

0 commit comments

Comments
 (0)