Skip to content

Bug 1834136: fix(queues): use a single gc queue #1513

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

Merged
merged 1 commit into from
May 17, 2020
Merged
Show file tree
Hide file tree
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
29 changes: 18 additions & 11 deletions pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,14 @@ func (a *Operator) syncObject(obj interface{}) (syncError error) {
a.requeueOwnerCSVs(metaObj)
} else {
switch metaObj.(type) {
case *rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding:
case *rbacv1.ClusterRole, *rbacv1.ClusterRoleBinding, *admissionregistrationv1.MutatingWebhookConfiguration, *admissionregistrationv1.ValidatingWebhookConfiguration:
resourceEvent := kubestate.NewResourceEvent(
kubestate.ResourceUpdated,
metaObj,
)
syncError = a.objGCQueueSet.RequeueEvent(ns, resourceEvent)
logger.Debugf("syncObject - requeued update event for %v, res=%v", resourceEvent, syncError)
if syncError = a.objGCQueueSet.RequeueEvent("", resourceEvent); syncError != nil {
logger.WithError(syncError).Warnf("failed to requeue gc event: %v", resourceEvent)
}
return
}
}
Expand Down Expand Up @@ -950,17 +951,19 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
logger.WithError(err).Warn("cannot list cluster role bindings")
}
for _, crb := range crbs {
syncError := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, crb))
logger.Debugf("handleCSVdeletion - requeued update event for %v, res=%v", crb, syncError)
if err := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, crb)); err != nil {
logger.WithError(err).Warnf("failed to requeue gc event: %v", crb)
}
}

crs, err := a.lister.RbacV1().ClusterRoleLister().List(ownerSelector)
if err != nil {
logger.WithError(err).Warn("cannot list cluster roles")
}
for _, cr := range crs {
syncError := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, cr))
logger.Debugf("handleCSVdeletion - requeued update event for %v, res=%v", cr, syncError)
if err := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, cr)); err != nil {
logger.WithError(err).Warnf("failed to requeue gc event: %v", cr)
}
}

webhookSelector := labels.SelectorFromSet(ownerutil.OwnerLabel(clusterServiceVersion, v1alpha1.ClusterServiceVersionKind)).String()
Expand All @@ -969,17 +972,21 @@ func (a *Operator) handleClusterServiceVersionDeletion(obj interface{}) {
logger.WithError(err).Warn("cannot list MutatingWebhookConfigurations")
}
for _, webhook := range mWebhooks.Items {
syncError := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, &webhook))
Copy link
Member Author

Choose a reason for hiding this comment

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

If I'm not mistaken, the value of webhook was changing underneath the pointer since it's a free variable in the loop's body.

Copy link
Member

Choose a reason for hiding this comment

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

Great catch!

logger.Debugf("handleCSVdeletion - requeued update event for %v, res=%v", webhook, syncError)
w := webhook
if err := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, &w)); err != nil {
logger.WithError(err).Warnf("failed to requeue gc event: %v", webhook)
}
}

vWebhooks, err := a.opClient.KubernetesInterface().AdmissionregistrationV1().ValidatingWebhookConfigurations().List(context.TODO(), metav1.ListOptions{LabelSelector: webhookSelector})
if err != nil {
logger.WithError(err).Warn("cannot list ValidatingWebhookConfigurations")
}
for _, webhook := range vWebhooks.Items {
syncError := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, &webhook))
logger.Debugf("handleCSVdeletion - requeued update event for %v, res=%v", webhook, syncError)
w := webhook
if err := a.objGCQueueSet.RequeueEvent("", kubestate.NewResourceEvent(kubestate.ResourceUpdated, &w)); err != nil {
logger.WithError(err).Warnf("failed to requeue gc event: %v", webhook)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/lib/queueinformer/resourcequeue.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func (r *ResourceQueueSet) RequeueEvent(namespace string, resourceEvent kubestat
r.mutex.RLock()
defer r.mutex.RUnlock()

if queue, ok := r.queueSet[metav1.NamespaceAll]; len(r.queueSet) == 1 && ok {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? if "" is passed as the namespace, the following block will requeue in the "allnamespace" queue

Copy link
Member Author

Choose a reason for hiding this comment

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

because we also want all of the requeues that specifically mention a namespace to go to the all-namespace queue as well.

queue.AddRateLimited(resourceEvent)
return nil
}

if queue, ok := r.queueSet[namespace]; ok {
queue.AddRateLimited(resourceEvent)
return nil
Expand Down