From 078dd53552afc55773489519a549be5a75813aea Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 11 Sep 2025 02:37:08 +1000 Subject: [PATCH 1/2] Configuration changes Signed-off-by: michaelawyu --- pkg/utils/informer/informermanager.go | 30 ++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/utils/informer/informermanager.go b/pkg/utils/informer/informermanager.go index b36e265a6..388d4bc61 100644 --- a/pkg/utils/informer/informermanager.go +++ b/pkg/utils/informer/informermanager.go @@ -22,6 +22,7 @@ import ( "sync" "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic/dynamicinformer" @@ -130,7 +131,34 @@ func (s *informerManagerImpl) AddDynamicResources(dynResources []APIResourceMeta s.apiResources[newRes.GroupVersionKind] = &newRes // TODO (rzhang): remember the ResourceEventHandlerRegistration and remove it when the resource is deleted // TODO: handle error which only happens if the informer is stopped - _, _ = s.informerFactory.ForResource(newRes.GroupVersionResource).Informer().AddEventHandler(handler) + informer := s.informerFactory.ForResource(newRes.GroupVersionResource).Informer() + err := informer.SetTransform(func(objI interface{}) (interface{}, error) { + obj, hasObjMetadata := objI.(metav1.Object) + if !hasObjMetadata { + // No need to transform; return the object as it is. + return objI, nil + } + + // Drop the following metadata fields as Fleet never reads them (or more specifically, + // they will be stripped off before placement anyway). + // + // TO-DO (chenyu1): cross-reference the logic here with the stripping-off process to make + // sure that the same fields are dropped in both places. + obj.SetManagedFields(nil) + obj.SetOwnerReferences(nil) + obj.SetUID("") + obj.SetSelfLink("") + obj.SetResourceVersion("") + obj.SetDeletionTimestamp(nil) + + return obj, nil + }) + if err != nil { + // The SetTransform func would only fail if the informer has already started. In this case, + // no further action is needed. + klog.ErrorS(err, "Failed to set transform func for informer", "gvr", newRes.GroupVersionResource) + } + _, _ = informer.AddEventHandler(handler) klog.InfoS("Added an informer for a new resource", "res", newRes) } else if !dynRes.isPresent { // we just mark it as enabled as we should not add another eventhandler to the informer as it's still From 1410354d02c06f573188b887fb86dd474f2364f8 Mon Sep 17 00:00:00 2001 From: michaelawyu Date: Thu, 11 Sep 2025 09:07:22 +1000 Subject: [PATCH 2/2] Minor fixes Signed-off-by: michaelawyu --- pkg/utils/informer/informermanager.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/utils/informer/informermanager.go b/pkg/utils/informer/informermanager.go index 388d4bc61..9c1029027 100644 --- a/pkg/utils/informer/informermanager.go +++ b/pkg/utils/informer/informermanager.go @@ -145,11 +145,12 @@ func (s *informerManagerImpl) AddDynamicResources(dynResources []APIResourceMeta // TO-DO (chenyu1): cross-reference the logic here with the stripping-off process to make // sure that the same fields are dropped in both places. obj.SetManagedFields(nil) - obj.SetOwnerReferences(nil) - obj.SetUID("") obj.SetSelfLink("") - obj.SetResourceVersion("") - obj.SetDeletionTimestamp(nil) + + // Note (chenyu1): the v1alpha1 API implementations read the following fields. + //obj.SetOwnerReferences(nil) + //obj.SetUID("") + //obj.SetResourceVersion("") return obj, nil })