Skip to content

IndexField() unintentionally blocks until informer is synced #3422

@sunziping2016

Description

@sunziping2016

Hi, I'm writing a controller reconciled based on a CRD. I'd like to setup an IndexField() based on the Pod annotation. I found this function will block until the informer is synced, which delay the startup of the controller.

I dug into the cause, find that in IndexField(), it calls GetInformer() with default option blockUntilSync=true.

func (ic *informerCache) IndexField(ctx context.Context, obj client.Object, field string, extractValue client.IndexerFunc) error {
informer, err := ic.GetInformer(ctx, obj)
if err != nil {
return err
}
return indexByField(informer, field, extractValue)
}

// GetOptions provides configuration to customize the behavior when
// getting an informer.
type GetOptions struct {
// BlockUntilSynced controls if the informer retrieval will block until the informer is synced. Defaults to `true`.
BlockUntilSynced *bool
}

I'd like to know

  1. Is this an expected behavior?
  2. Where should I put the IndexField(), taking controller-runtime/examples/crd/main.go as an example?

It's NOT an urgent issue, as the delayed startup won't cause too much trouble. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions