Skip to content

Commit 4c62687

Browse files
committed
issue events during ARS reconciling
On-behalf-of: @SAP [email protected]
1 parent 9a78a44 commit 4c62687

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

internal/controller/apiexport/controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func Add(
103103
// Watch for changes to PublishedResources on the local service cluster
104104
Watches(&syncagentv1alpha1.PublishedResource{}, controllerutil.EnqueueConst[ctrlruntimeclient.Object]("dummy"), builder.WithPredicates(predicateutil.ByLabels(prFilter), hasARS)).
105105
Build(reconciler)
106+
106107
return err
107108
}
108109

@@ -166,7 +167,7 @@ func (r *Reconciler) reconcile(ctx context.Context) error {
166167

167168
// reconcile an APIExport in kcp
168169
factories := []reconciling.NamedAPIExportReconcilerFactory{
169-
r.createAPIExportReconciler(arsList, claimedResources, r.agentName, r.apiExportName),
170+
r.createAPIExportReconciler(arsList, claimedResources, r.agentName, r.apiExportName, r.recorder),
170171
}
171172

172173
if err := reconciling.ReconcileAPIExports(ctx, factories, "", r.kcpClient); err != nil {

internal/controller/apiexport/reconciler.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,23 @@ import (
2525

2626
kcpdevv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/apis/v1alpha1"
2727

28+
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apimachinery/pkg/util/sets"
30+
"k8s.io/client-go/tools/record"
2931
)
3032

33+
const eventType = "Reconciling"
34+
3135
// createAPIExportReconciler creates the reconciler for the APIExport.
3236
// WARNING: The APIExport in this is NOT created by the Sync Agent, it's created
3337
// by a controller in kcp. Make sure you don't create a reconciling conflict!
34-
func (r *Reconciler) createAPIExportReconciler(availableResourceSchemas sets.Set[string], claimedResourceKinds sets.Set[string], agentName string, apiExportName string) reconciling.NamedAPIExportReconcilerFactory {
38+
func (r *Reconciler) createAPIExportReconciler(
39+
availableResourceSchemas sets.Set[string],
40+
claimedResourceKinds sets.Set[string],
41+
agentName string,
42+
apiExportName string,
43+
recorder record.EventRecorder,
44+
) reconciling.NamedAPIExportReconcilerFactory {
3545
return func() (string, reconciling.APIExportReconciler) {
3646
return apiExportName, func(existing *kcpdevv1alpha1.APIExport) (*kcpdevv1alpha1.APIExport, error) {
3747
if existing.Annotations == nil {
@@ -40,7 +50,10 @@ func (r *Reconciler) createAPIExportReconciler(availableResourceSchemas sets.Set
4050
existing.Annotations[syncagentv1alpha1.AgentNameAnnotation] = agentName
4151

4252
// combine existing schemas with new ones
43-
existing.Spec.LatestResourceSchemas = mergeResourceSchemas(existing.Spec.LatestResourceSchemas, availableResourceSchemas)
53+
newSchemas := mergeResourceSchemas(existing.Spec.LatestResourceSchemas, availableResourceSchemas)
54+
createSchemaEvents(existing, existing.Spec.LatestResourceSchemas, newSchemas, recorder)
55+
56+
existing.Spec.LatestResourceSchemas = newSchemas
4457

4558
// To allow admins to configure additional permission claims, sometimes
4659
// useful for debugging, we do not override the permission claims, but
@@ -65,6 +78,8 @@ func (r *Reconciler) createAPIExportReconciler(availableResourceSchemas sets.Set
6578
},
6679
All: true,
6780
})
81+
82+
recorder.Eventf(existing, eventType, "AddingPermissionClaim", "Added new permission claim for all %s.", claimed)
6883
}
6984

7085
// prevent reconcile loops by ensuring a stable order
@@ -113,6 +128,19 @@ func mergeResourceSchemas(existing []string, configured sets.Set[string]) []stri
113128
return result
114129
}
115130

131+
func createSchemaEvents(obj runtime.Object, oldSchemas, newSchemas []string, recorder record.EventRecorder) {
132+
oldSet := sets.New(oldSchemas...)
133+
newSet := sets.New(newSchemas...)
134+
135+
for _, s := range newSet.Difference(oldSet) {
136+
recorder.Eventf(obj, eventType, "AddingResourceSchema", "Added new resource schema %s.", s)
137+
}
138+
139+
for _, s := range oldSet.Difference(newSet) {
140+
recorder.Eventf(obj, eventType, "RemovingResourceSchema", "Removed resource schema %s.", s)
141+
}
142+
}
143+
116144
func parseResourceGroup(schema string) string {
117145
// <version>.<resource>.<group>
118146
parts := strings.SplitN(schema, ".", 2)

0 commit comments

Comments
 (0)