3131 arangodPrefixes = []string {"CRDN-" , "PRMR-" , "AGNT-" , "SNGL-" }
3232)
3333
34+ const (
35+ qualifiedNameMaxLength int = 63
36+ )
37+
3438// StripArangodPrefix removes well know arangod ID prefixes from the given id.
3539func StripArangodPrefix (id string ) string {
3640 for _ , prefix := range arangodPrefixes {
@@ -43,13 +47,11 @@ func StripArangodPrefix(id string) string {
4347
4448// FixupResourceName ensures that the given name
4549// complies with kubernetes name requirements.
46- // If the name is to long or contains invalid characters,
47- // if will be adjusted and a hash with be added.
50+ // If the name is too long or contains invalid characters,
51+ // it will be adjusted and a hash will be added.
4852func FixupResourceName (name string ) string {
49- maxLen := 63
50-
5153 sb := strings.Builder {}
52- needHash := len (name ) > maxLen
54+ needHash := len (name ) > qualifiedNameMaxLength
5355 for _ , ch := range name {
5456 if unicode .IsDigit (ch ) || unicode .IsLower (ch ) || ch == '-' {
5557 sb .WriteRune (ch )
@@ -64,8 +66,8 @@ func FixupResourceName(name string) string {
6466 if needHash {
6567 hash := sha1 .Sum ([]byte (name ))
6668 h := fmt .Sprintf ("-%0x" , hash [:3 ])
67- if len (result )+ len (h ) > maxLen {
68- result = result [:maxLen - (len (h ))]
69+ if len (result )+ len (h ) > qualifiedNameMaxLength {
70+ result = result [:qualifiedNameMaxLength - (len (h ))]
6971 }
7072 result = result + h
7173 }
@@ -75,7 +77,13 @@ func FixupResourceName(name string) string {
7577// CreatePodHostName returns the hostname of the pod for a member with
7678// a given id in a deployment with a given name.
7779func CreatePodHostName (deploymentName , role , id string ) string {
78- return deploymentName + "-" + role + "-" + StripArangodPrefix (id )
80+ suffix := "-" + role + "-" + StripArangodPrefix (id )
81+ maxDeplNameLen := qualifiedNameMaxLength - len (suffix )
82+ // shorten deployment name part if resulting name is too big:
83+ if maxDeplNameLen > 1 && len (deploymentName ) > maxDeplNameLen {
84+ deploymentName = deploymentName [:maxDeplNameLen - 1 ]
85+ }
86+ return deploymentName + suffix
7987}
8088
8189// CreatePersistentVolumeClaimName returns the name of the persistent volume claim for a member with
0 commit comments