Просмотр исходного кода

containerkeys: support shorter node names (#3582)

Signed-off-by: Kyle Fazzari <kyrofa@ubuntu.com>
Co-authored-by: Warwick <warwick@automatic.systems>
Co-authored-by: Alex Meijer <ameijer@users.noreply.github.com>
Kyle Fazzari 2 месяцев назад
Родитель
Сommit
368ea28cac
2 измененных файлов с 5 добавлено и 1 удалено
  1. 2 1
      pkg/costmodel/containerkeys.go
  2. 3 0
      pkg/costmodel/costmodel_test.go

+ 2 - 1
pkg/costmodel/containerkeys.go

@@ -245,12 +245,13 @@ func NewContainerMetricFrom(result *source.ContainerMetricResult, defaultCluster
 }
 
 /*
+- contain at least 1 character
 - contain no more than 253 characters
 - contain only lowercase alphanumeric characters, '-' or '.'
 - start with an alphanumeric character
 - end with an alphanumeric character
 */
-var nodeNameRegex = regexp.MustCompile(`^[a-z0-9][a-z0-9\-\.]+[a-z0-9]$`)
+var nodeNameRegex = regexp.MustCompile(`^[a-z0-9](?:[a-z0-9\-\.]*[a-z0-9])?$`)
 
 // isValidNodeName determines if the nodeName provided is valid according to DNS subdomain
 // specifications: RFC 1123

+ 3 - 0
pkg/costmodel/costmodel_test.go

@@ -20,6 +20,9 @@ func TestIsValidNodeName(t *testing.T) {
 		"node-1",
 		"another.test.node",
 		"10-55.23-10",
+		"s21",
+		"s1",
+		"s",
 	}
 
 	for _, test := range tests {