Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 crdcleanup: strongly type enqueue params #2573

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions pkg/reconciler/apis/crdcleanup/crdcleanup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,33 +80,29 @@ func NewController(

crdInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
crd, ok := obj.(*apiextensionsv1.CustomResourceDefinition)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is a regression in behavior but I think in practice it's the more correct thing to do anyway?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but it's better to panic to indicate programmer error I'd say.

if !ok {
return false
}

crd := obj.(*apiextensionsv1.CustomResourceDefinition)
return logicalcluster.From(crd) == apibinding.SystemBoundCRDsClusterName
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueCRD(obj)
c.enqueueCRD(obj.(*apiextensionsv1.CustomResourceDefinition))
},
UpdateFunc: func(_, newObj interface{}) {
c.enqueueCRD(newObj)
UpdateFunc: func(_, obj interface{}) {
c.enqueueCRD(obj.(*apiextensionsv1.CustomResourceDefinition))
},
DeleteFunc: func(obj interface{}) {
c.enqueueCRD(obj)
c.enqueueCRD(obj.(*apiextensionsv1.CustomResourceDefinition))
},
},
})

apiBindingInformer.Informer().AddEventHandler(
cache.ResourceEventHandlerFuncs{
UpdateFunc: func(oldObj, newObj interface{}) {
c.enqueueFromAPIBinding(oldObj, newObj)
c.enqueueFromAPIBinding(oldObj.(*apisv1alpha1.APIBinding), newObj.(*apisv1alpha1.APIBinding))
},
DeleteFunc: func(obj interface{}) {
c.enqueueFromAPIBinding(nil, obj)
c.enqueueFromAPIBinding(nil, obj.(*apisv1alpha1.APIBinding))
},
},
)
Expand All @@ -124,8 +120,8 @@ type controller struct {
}

// enqueueCRD enqueues a CRD.
func (c *controller) enqueueCRD(obj interface{}) {
key, err := kcpcache.DeletionHandlingMetaClusterNamespaceKeyFunc(obj)
func (c *controller) enqueueCRD(crd *apiextensionsv1.CustomResourceDefinition) {
key, err := kcpcache.DeletionHandlingMetaClusterNamespaceKeyFunc(crd)
if err != nil {
runtime.HandleError(err)
return
Expand All @@ -136,12 +132,7 @@ func (c *controller) enqueueCRD(obj interface{}) {
c.queue.Add(key)
}

func (c *controller) enqueueFromAPIBinding(oldObj, newObj interface{}) {
newBinding, ok := newObj.(*apisv1alpha1.APIBinding)
if !ok {
return
}

func (c *controller) enqueueFromAPIBinding(oldBinding, newBinding *apisv1alpha1.APIBinding) {
logger := logging.WithObject(logging.WithReconciler(klog.Background(), ControllerName), newBinding)

// Looking at old and new versions in case a schema gets removed from an APIExport.
Expand All @@ -150,12 +141,7 @@ func (c *controller) enqueueFromAPIBinding(oldObj, newObj interface{}) {

uidSet := sets.String{}

if oldObj != nil {
oldBinding, ok := oldObj.(*apisv1alpha1.APIBinding)
if !ok {
return
}

if oldBinding != nil {
for _, boundResource := range oldBinding.Status.BoundResources {
uidSet.Insert(boundResource.Schema.UID)
}
Expand Down