-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changes from 13 commits
8a73dff
8f96da2
1df7902
b960321
e7db0d9
e0cbf5d
109e5e6
21e62fa
240e151
47e97be
d865b09
35ff870
fc01926
979b2bd
b861b54
9de65d0
6c1110b
0e175a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2018 The Operator-SDK Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package sdk | ||
|
||
// WatchOp wraps all the options for Watch(). | ||
type WatchOp struct { | ||
NumWorkers int | ||
} | ||
|
||
// NewWatchOp create a new deafult WatchOp | ||
func NewWatchOp() *WatchOp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unexport this as well: func newWatchOp() *watchOp { |
||
op := &WatchOp{} | ||
op.setDefaults() | ||
return op | ||
} | ||
|
||
func (op *WatchOp) applyOpts(opts []WatchOption) { | ||
for _, opt := range opts { | ||
opt(op) | ||
} | ||
} | ||
|
||
func (op *WatchOp) setDefaults() { | ||
if op.NumWorkers == 0 { | ||
op.NumWorkers = 1 | ||
} | ||
} | ||
|
||
// WatchOption configures WatchOp. | ||
type WatchOption func(*WatchOp) | ||
|
||
// WithWatchOptions sets the number of workers for the Watch() operation. | ||
func WithWatchOptions(numWorkers int) WatchOption { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
return func(op *WatchOp) { | ||
op.NumWorkers = numWorkers | ||
} | ||
} |
There was a problem hiding this comment.
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: