@@ -15,7 +15,7 @@ import (
15
15
)
16
16
17
17
const (
18
- uuidLength = 6
18
+ uuidLength = 8
19
19
)
20
20
21
21
// minInt returns the smaller one of two integers.
@@ -27,7 +27,7 @@ func minInt(a, b int) int {
27
27
}
28
28
29
29
// NewClusterResourceBindingName returns a unique name for a cluster resource binding in the
30
- // format of DNS subdomain names (RFC 1123).
30
+ // format of DNS label names (RFC 1123). It will be used as a label on the work resource .
31
31
//
32
32
// The name is generated using the following format:
33
33
// * [CRP-NAME] - [TARGET-CLUSTER-NAME] - [RANDOM-SUFFIX]
@@ -38,20 +38,20 @@ func minInt(a, b int) int {
38
38
// of name collisions are extremely low.
39
39
//
40
40
// In addition, note that this function assumes that both the CRP name and the cluster name
41
- // are valid DNS subdomain names (RFC 1123).
41
+ // are valid DNS label names (RFC 1123).
42
42
func NewClusterResourceBindingName (CRPName string , clusterName string ) (string , error ) {
43
- reservedSlots := 2 + uuidLength // 2 dashs + 6 character UUID string
43
+ reservedSlots := 2 + uuidLength // 2 dashs + 8 character UUID string
44
44
45
- slotsPerSeg := (validation .DNS1123SubdomainMaxLength - reservedSlots ) / 2
45
+ slotsPerSeg := (validation .DNS1123LabelMaxLength - reservedSlots ) / 2
46
46
uniqueName := fmt .Sprintf ("%s-%s-%s" ,
47
47
CRPName [:minInt (slotsPerSeg , len (CRPName ))],
48
- clusterName [:minInt (slotsPerSeg , len (clusterName ))],
48
+ clusterName [:minInt (slotsPerSeg + 1 , len (clusterName ))],
49
49
uuid .NewUUID ()[:uuidLength ],
50
50
)
51
51
52
- if errs := validation .IsDNS1123Subdomain (uniqueName ); len (errs ) != 0 {
52
+ if errs := validation .IsDNS1123Label (uniqueName ); len (errs ) != 0 {
53
53
// Do a sanity check here; normally this would not occur.
54
- return "" , fmt .Errorf ("failed to format a unique RFC 1123 DNS subdomain name with namespace %s, name %s: %v" , CRPName , clusterName , errs )
54
+ return "" , fmt .Errorf ("failed to format a unique RFC 1123 label name with CRP name %s, cluster name %s: %v" , CRPName , clusterName , errs )
55
55
}
56
56
return uniqueName , nil
57
57
}
0 commit comments