Skip to content

Calling Builder.For() multiple times loses previous apiTypes #1173

Closed
@jim-minter

Description

@jim-minter

At https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/builder/controller.go#L74 , For latches the apiType of the For() call.

If a controller-runtime consumer calls Builder.For(foo).For(bar), then foo will be silently lost in favour of bar.

This contrasts with Owns' behaviour, where Builder.Owns(foo).Owns(bar) will append both foo and bar to an internal slice.

Judging by the code comment on For (For defines the type of Object being *reconciled*), it may not be intended for For to be called multiple times on a Builder. Nonetheless, the current behaviour can be confusing.

As a workaround, a consumer who wants to watch multiple apiTypes can use Watches(foo).Watches(bar) instead.

IMO it would be nice to make the behaviour here clearer, either:

  • by raising an error if For() is called and bldr.apiType is already set, or
  • by making apiTypes a slice and allowing For() to be called multiple times, as Owns() or Watches() is.

Metadata

Metadata

Assignees

Labels

good first issueDenotes an issue ready for a new contributor, according to the "help wanted" guidelines.help wantedDenotes an issue that needs help from a contributor. Must meet "help wanted" guidelines.kind/featureCategorizes issue or PR as related to a new feature.priority/important-longtermImportant over the long term, but may not be staffed and/or may need multiple releases to complete.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions