@@ -12,12 +12,37 @@ const (
1212 ClusterRoleNamesAnnotation = "clusterrolenames.capsule.clastix.io"
1313)
1414
15- func (in OwnerSpec ) GetRoles (tenant Tenant ) []string {
15+ // GetRoles read the annotation available in the Tenant specification and if it matches the pattern
16+ // clusterrolenames.capsule.clastix.io/${KIND}.${NAME} returns the associated roles.
17+ // Kubernetes annotations and labels must respect RFC 1123 about DNS names and this could be cumbersome in two cases:
18+ // 1. identifying users based on their email address
19+ // 2. the overall length of the annotation key that is exceeding 63 characters
20+ // For emails, the symbol @ can be replaced with the placeholder __AT__.
21+ // For the latter one, the index of the owner can be used to force the retrieval.
22+ func (in OwnerSpec ) GetRoles (tenant Tenant , index int ) []string {
1623 for key , value := range tenant .GetAnnotations () {
17- if key == fmt .Sprintf ("%s/%s.%s" , ClusterRoleNamesAnnotation , strings .ToLower (in .Kind .String ()), strings .ToLower (in .Name )) {
24+ if ! strings .HasPrefix (key , fmt .Sprintf ("%s/" , ClusterRoleNamesAnnotation )) {
25+ continue
26+ }
27+
28+ for symbol , replace := range in .convertMap () {
29+ key = strings .ReplaceAll (key , symbol , replace )
30+ }
31+
32+ nameBased := key == fmt .Sprintf ("%s/%s.%s" , ClusterRoleNamesAnnotation , strings .ToLower (in .Kind .String ()), strings .ToLower (in .Name ))
33+
34+ indexBased := key == fmt .Sprintf ("%s/%d" , ClusterRoleNamesAnnotation , index )
35+
36+ if nameBased || indexBased {
1837 return strings .Split (value , "," )
1938 }
2039 }
2140
2241 return []string {"admin" , "capsule-namespace-deleter" }
2342}
43+
44+ func (in OwnerSpec ) convertMap () map [string ]string {
45+ return map [string ]string {
46+ "__AT__" : "@" ,
47+ }
48+ }
0 commit comments