Skip to content

Commit 08d7616

Browse files
committed
issue events during ARS reconciling
On-behalf-of: @SAP christoph.mewes@sap.com
1 parent 9a78a44 commit 08d7616

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-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: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@ import (
2525

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

28+
corev1 "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/runtime"
2830
"k8s.io/apimachinery/pkg/util/sets"
31+
"k8s.io/client-go/tools/record"
2932
)
3033

3134
// createAPIExportReconciler creates the reconciler for the APIExport.
3235
// WARNING: The APIExport in this is NOT created by the Sync Agent, it's created
3336
// 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 {
37+
func (r *Reconciler) createAPIExportReconciler(
38+
availableResourceSchemas sets.Set[string],
39+
claimedResourceKinds sets.Set[string],
40+
agentName string,
41+
apiExportName string,
42+
recorder record.EventRecorder,
43+
) reconciling.NamedAPIExportReconcilerFactory {
3544
return func() (string, reconciling.APIExportReconciler) {
3645
return apiExportName, func(existing *kcpdevv1alpha1.APIExport) (*kcpdevv1alpha1.APIExport, error) {
3746
if existing.Annotations == nil {
@@ -40,7 +49,10 @@ func (r *Reconciler) createAPIExportReconciler(availableResourceSchemas sets.Set
4049
existing.Annotations[syncagentv1alpha1.AgentNameAnnotation] = agentName
4150

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

4557
// To allow admins to configure additional permission claims, sometimes
4658
// useful for debugging, we do not override the permission claims, but
@@ -65,6 +77,8 @@ func (r *Reconciler) createAPIExportReconciler(availableResourceSchemas sets.Set
6577
},
6678
All: true,
6779
})
80+
81+
recorder.Eventf(existing, corev1.EventTypeNormal, "AddingPermissionClaim", "Added new permission claim for all %s.", claimed)
6882
}
6983

7084
// prevent reconcile loops by ensuring a stable order
@@ -113,6 +127,19 @@ func mergeResourceSchemas(existing []string, configured sets.Set[string]) []stri
113127
return result
114128
}
115129

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

0 commit comments

Comments
 (0)