github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/cmn/k8s/util.go (about) 1 // Package k8s: initialization, client, and misc. helpers 2 /* 3 * Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. 4 */ 5 package k8s 6 7 import ( 8 "fmt" 9 "strings" 10 ) 11 12 // POD name (K8s doesn't allow `_` and uppercase) 13 func CleanName(name string) string { return strings.ReplaceAll(strings.ToLower(name), "_", "-") } 14 15 const ( 16 shortNameETL = 6 17 longNameETL = 32 18 ) 19 20 func ValidateEtlName(name string) error { 21 const prefix = "ETL name %q " 22 l := len(name) 23 if l < shortNameETL { 24 return fmt.Errorf(prefix+"is too short", name) 25 } 26 if l > longNameETL { 27 return fmt.Errorf(prefix+"is too long", name) 28 } 29 for _, c := range name { 30 if (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '-' { 31 continue 32 } 33 return fmt.Errorf(prefix+"is invalid: can only contain [a-z0-9-]", name) 34 } 35 return nil 36 }