Skip to content

pkg/sdk: Make number of workers configurable #418

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 18 commits into from
Aug 24, 2018

Conversation

theishshah
Copy link
Member

@theishshah theishshah commented Aug 17, 2018

The informer struct now has a field for numWorkers which is populated in main.go of a generated operator. Currently defaults to 1

Issue #140

@theishshah theishshah requested a review from hasbro17 August 17, 2018 16:29
logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
sdk.Watch(resource, kind, namespace, resyncPeriod)
sdk.Watch(resource, kind, namespace, resyncPeriod, numWorkers)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make sdk.Watch to accept optional arguments like the Get API:
func Watch(apiVersion, kind, namespace string, resyncPeriod int, opts ...WatchOption)
Then one of the WatchOption can be:
func WithNumberOfWorkers(int numWorkers) WatchOption.

In that way, we don't break the backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

I would also like to understand how this might change with regards to controller runtime. Especially, before making a backward incompatible change and then maybe needing to do another after the controller runtime refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

@shawn-hurley
I would also like to understand how this might change with regards to controller runtime
Currently, we are not sure how controller runtime affects the overall API change. we will deal with it when it comes.

Copy link
Contributor

Choose a reason for hiding this comment

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

@shawn-hurley The controller-runtime supports configuring the number of workers out of the box via the controller options:
https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/controller/controller.go#L32-L34

So this feature should be supported eventually once we use the controller-runtime.
But in the meantime if we can still support this without breaking backwards compatibility then it's worth adding right now since this has been requested for quite some time.

@theishshah
Copy link
Member Author

Now follows the functional options pattern

type WatchOption func(*WatchOp)

// WithWatchOptions sets the number of workers for the Watch() operation.
func WithWatchOptions(numWorkers int) WatchOption {
Copy link
Contributor

@fanminshi fanminshi Aug 21, 2018

Choose a reason for hiding this comment

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

You can name this function to match the meaning of the wanted option for readability. for example,
func WithNumOfWorks(numWorkers int) WatchOption is probably more intuitive.

@fanminshi
Copy link
Contributor

lgtm defer @hasbro17

@hasbro17
Copy link
Contributor

We need to document the usage of this Watch Option and what it does. Ideally we could have a separate doc for it in doc/user/watch-api.md that explains the usage of Watch.
But we haven't had a consistent way of documenting the APIs(e.g for the client).

For now @theishshah can you just make a small note of this option in the user guide section for Watch.

@CSdread
Copy link
Contributor

CSdread commented Aug 22, 2018

can this code change with the functional options be used to pass labels to the watch? I know that the goal is to have the controller-runtime do that nested watching but it seems we are far off from that refactor and I think some of us are blocked on things like finalizers without them. Can we have a ticketed (issue) conversation about using this?

@hasbro17
Copy link
Contributor

@CSdread Can you please open up a separate issue for that. If I understand correctly, your use case for passing labels to sdk.Watch() is to filter out events for that label selector. That would be done with predicates in the controller-runtime in the future. But like you pointed out, that refactor will still take some time. Lets discuss this in a separate issue to see if we can do something else in the meanwhile.

sdk.Handle(stub.NewHandler())
sdk.Run(context.TODO())
}
```
Copy link
Contributor

Choose a reason for hiding this comment

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

Note: You can configure the number of concurrent informer workers with an additional Watch option:

sdk.Watch("cache.example.com/v1alpha1", "Memcached", "default", 5, sdk.WithNumWorkers(n))

Copy link
Contributor

Choose a reason for hiding this comment

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

Also mention that the default is 1 over here.

@@ -58,11 +58,20 @@ By default, the memcached-operator watches `Memcached` resource events as shown

```Go
func main() {
// Default number of worker to 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this. And mention it in the note below.

package sdk

// WatchOp wraps all the options for Watch().
type WatchOp struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

In the past we've needlessly exported structs and utility functions when they aren't meant to be exposed outside the sdk pkg, e.g we do this with the query and action options with NewQueryOps() etc.

But for this PR let's keep that to a minimum. We only need to export WithNumWorkers(). Everything else is internal to the pkg. So keep this unexported:

type watchOp struct {

}

// NewWatchOp create a new deafult WatchOp
func NewWatchOp() *WatchOp {
Copy link
Contributor

Choose a reason for hiding this comment

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

unexport this as well:

func newWatchOp() *watchOp {

@hasbro17
Copy link
Contributor

LGTM

1 similar comment
@shawn-hurley
Copy link
Member

LGTM

@theishshah theishshah merged commit b3413a6 into operator-framework:master Aug 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants