Skip to content

Commit

Permalink
Ignore service object delete events
Browse files Browse the repository at this point in the history
  • Loading branch information
aalexand committed Oct 3, 2023
1 parent cc3078c commit 9945a94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/api/registry/v1alpha1/servicemetadatawatcher_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,24 @@ type ObjectReference struct {
Kind string `json:"kind"`
}

func (o *ObjectReference) String() string {
return o.Name + "/" + o.APIVersion + "/" + o.Kind
}

type WatchedField struct {
Source string `json:"src"`
Destination string `json:"dst"`
}

type WatchedServiceObjectStatus struct {
LastUpdated metav1.Time `json:"lastUpdated"`
ObjectReference ObjectReference `json:"objectReference"`
Errors []string `json:"errors"`
}

// ServiceMetadataWatcherStatus defines the observed state of ServiceMetadataWatcher
type ServiceMetadataWatcherStatus struct {
WatchedServiceObjects []WatchedServiceObjectStatus `json:"watchedServiceObjects"`
}

//+kubebuilder:object:root=true
Expand Down
16 changes: 15 additions & 1 deletion pkg/client/controllers/servicemetadatawatcher_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (r *ServiceMetadataWatcherReconciler) Reconcile(ctx context.Context, req ct
gv, err := schema.ParseGroupVersion(wso.ObjectReference.APIVersion)
if err != nil {
log.Error(err, "cannot parse APIVersion", "apiVersion", wso.ObjectReference.APIVersion)
// TODO: update status with error
return requeueIfError(err)
}

Expand All @@ -100,6 +101,7 @@ func (r *ServiceMetadataWatcherReconciler) Reconcile(ctx context.Context, req ct
// check if gvk is allowed
if !r.isAllowedGVK(gvk) {
log.Info("watched object GVK is not allowed, skipping", "gvk", gvk.String())
// TODO: update status with error
return noRequeue()
}

Expand Down Expand Up @@ -134,6 +136,7 @@ func (r *ServiceMetadataWatcherReconciler) Reconcile(ctx context.Context, req ct

if !found {
log.Error(err, "field not found", "field", field.Source)
// TODO: update status with error
continue
}

Expand Down Expand Up @@ -161,7 +164,18 @@ func (r *ServiceMetadataWatcherReconciler) SetupWithManager(ctx context.Context,
for _, gvk := range r.WatchedGVKs {
obj := new(unstructured.Unstructured)
obj.SetGroupVersionKind(gvk)
b.Watches(obj, handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsFromMapFunc(gvk)))
b.Watches(obj, handler.EnqueueRequestsFromMapFunc(r.enqueueRequestsFromMapFunc(gvk)), builder.WithPredicates(predicate.Funcs{
CreateFunc: func(e crevent.CreateEvent) bool {
return true
},
UpdateFunc: func(e crevent.UpdateEvent) bool {
return true
},
DeleteFunc: func(e crevent.DeleteEvent) bool {
// not interested in ServiceObject delete events (for now)
return false
},
}))
}
err := b.WithOptions(options).Complete(r)
return err
Expand Down

0 comments on commit 9945a94

Please sign in to comment.