@@ -17,6 +17,7 @@ limitations under the License.
1717package apiexport
1818
1919import (
20+ "fmt"
2021 "slices"
2122 "strings"
2223
@@ -36,7 +37,7 @@ import (
3637// by a controller in kcp. Make sure you don't create a reconciling conflict!
3738func (r * Reconciler ) createAPIExportReconciler (
3839 availableResourceSchemas sets.Set [string ],
39- claimedResourceKinds sets.Set [string ],
40+ claimedResourceKinds sets.Set [kcpdevv1alpha1. GroupResource ],
4041 agentName string ,
4142 apiExportName string ,
4243 recorder record.EventRecorder ,
@@ -59,28 +60,38 @@ func (r *Reconciler) createAPIExportReconciler(
5960 // only ensure the ones originating from the published resources;
6061 // step 1 is to collect all existing claims with the same properties
6162 // as ours.
62- existingClaims := sets .New [string ]()
63+ existingClaims := sets .New [kcpdevv1alpha1. GroupResource ]()
6364 for _ , claim := range existing .Spec .PermissionClaims {
64- if claim .All && claim . Group == "" && len (claim .ResourceSelector ) == 0 {
65- existingClaims .Insert (claim .Resource )
65+ if claim .All && len (claim .ResourceSelector ) == 0 {
66+ existingClaims .Insert (claim .GroupResource )
6667 }
6768 }
6869
6970 missingClaims := claimedResourceKinds .Difference (existingClaims )
7071
72+ claimsToAdd := missingClaims .UnsortedList ()
73+ slices .SortStableFunc (claimsToAdd , func (a , b kcpdevv1alpha1.GroupResource ) int {
74+ if a .Group != b .Group {
75+ return strings .Compare (a .Group , b .Group )
76+ }
77+
78+ return strings .Compare (a .Resource , b .Resource )
79+ })
80+
7181 // add our missing claims
72- for _ , claimed := range sets . List ( missingClaims ) {
82+ for _ , claimed := range claimsToAdd {
7383 existing .Spec .PermissionClaims = append (existing .Spec .PermissionClaims , kcpdevv1alpha1.PermissionClaim {
74- GroupResource : kcpdevv1alpha1.GroupResource {
75- Group : "" ,
76- Resource : claimed ,
77- },
78- All : true ,
84+ GroupResource : claimed ,
85+ All : true ,
7986 })
8087 }
8188
8289 if missingClaims .Len () > 0 {
83- recorder .Eventf (existing , corev1 .EventTypeNormal , "AddingPermissionClaims" , "Added new permission claim(s) for all %s." , strings .Join (sets .List (missingClaims ), ", " ))
90+ claims := make ([]string , 0 , len (claimsToAdd ))
91+ for _ , claimed := range claimsToAdd {
92+ claims = append (claims , groupResourceToString (claimed ))
93+ }
94+ recorder .Eventf (existing , corev1 .EventTypeNormal , "AddingPermissionClaims" , "Added new permission claim(s) for all %s." , strings .Join (claims , ", " ))
8495 }
8596
8697 // prevent reconcile loops by ensuring a stable order
@@ -101,6 +112,14 @@ func (r *Reconciler) createAPIExportReconciler(
101112 }
102113}
103114
115+ func groupResourceToString (gr kcpdevv1alpha1.GroupResource ) string {
116+ if gr .Group == "" {
117+ return gr .Resource
118+ }
119+
120+ return fmt .Sprintf ("%s/%s" , gr .Group , gr .Resource )
121+ }
122+
104123func mergeResourceSchemas (existing []string , configured sets.Set [string ]) []string {
105124 var result []string
106125
0 commit comments