Merge pull request #58 from Tova-Rozovsky/valid_DNS

This commit is contained in:
Pasha Sviderski
2025-05-07 16:02:55 +10:00
committed by GitHub
+10 -1
View File
@@ -31,6 +31,7 @@ const (
)
var serviceIDRegexp = regexp.MustCompile("^[0-9a-f]{32}$")
var dnsLabelRegexp = regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`)
func ValidateServiceID(id string) bool {
return serviceIDRegexp.MatchString(id)
@@ -104,7 +105,14 @@ func (s *ServiceSpec) Validate() error {
return fmt.Errorf("invalid mode: %q", s.Mode)
}
// TODO: validate the service name is a valid DNS label.
if s.Name != "" {
if len(s.Name) > 63 {
return fmt.Errorf("service name too long (max 63 characters): %q", s.Name)
}
if !dnsLabelRegexp.MatchString(s.Name) {
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)
}
}
for _, p := range s.Ports {
if (p.Mode == "" || p.Mode == PortModeIngress) &&
@@ -138,6 +146,7 @@ func (s *ServiceSpec) Validate() error {
return nil
}
func (s *ServiceSpec) Clone() ServiceSpec {
spec := *s