Skip to content
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

Adds --max-workers flag to the exec-entrypoint helm command #2607

Merged
merged 4 commits into from
Mar 6, 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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
- On `generate csv`, populate a CSV manifest’s `spec.icon`, `spec.keywords`, and `spec.mantainers` fields with empty values to better inform users how to add data. ([#2521](https://github.com/operator-framework/operator-sdk/pull/2521))
- Scaffold code in `cmd/manager/main.go` for Go operators and add logic to Ansible/Helm operators to handle [multinamespace caching](https://godoc.org/github.com/kubernetes-sigs/controller-runtime/pkg/cache#MultiNamespacedCacheBuilder) if `WATCH_NAMESPACE` contains multiple namespaces. ([#2522](https://github.com/operator-framework/operator-sdk/pull/2522))
- Add a new flag option (`--skip-cleanup-error`) to the test framework to allow skip the function which will remove all artefacts when an error be faced to perform this operation. ([#2512](https://github.com/operator-framework/operator-sdk/pull/2512))
- Add event stats output to the operator logs for Ansible based-operators. ([2580](https://github.com/operator-framework/operator-sdk/pull/2580))
- Improve Ansible logs by allowing output the full Ansible result for Ansible based-operators configurable by environment variable. ([2589](https://github.com/operator-framework/operator-sdk/pull/2589))
- Add event stats output to the operator logs for Ansible based-operators. ([2580](https://github.com/operator-framework/operator-sdk/pull/2580))
- Improve Ansible logs by allowing output the full Ansible result for Ansible based-operators configurable by environment variable. ([2589](https://github.com/operator-framework/operator-sdk/pull/2589))
Comment on lines +12 to +13
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think my editor just stripped out some white spaces from these lines.

- Add the --max-workers flag to the commands operator-sdk exec-entrypoint and operator-sdk run --local for Helm based-operators with the purpose of controling the number of concurrent reconcile workers. ([2607](https://github.com/operator-framework/operator-sdk/pull/2607))

### Changed
- Ansible scaffolding has been rewritten to be simpler and make use of newer features of Ansible and Molecule.
Expand Down
11 changes: 11 additions & 0 deletions doc/helm/user-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,17 @@ Events:
```


## Changing the concurrent worker count

Depending on the number of CRs of the same type, a single reconciling worker may have issues keeping up. You can increase the number of workers by passing `--max-workers <number of workers>`.

For example:

```sh
$ operator-sdk exec-entrypoint helm --max-workers 10
```


[operator-scope]:./../operator-scope.md
[install-guide]: ../user/install-operator-sdk.md
[layout-doc]:./project_layout.md
Expand Down
6 changes: 5 additions & 1 deletion pkg/helm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type WatchOptions struct {
ReconcilePeriod time.Duration
WatchDependentResources bool
OverrideValues map[string]string
MaxWorkers int
}

// Add creates a new helm operator controller and adds it to the manager
Expand All @@ -69,7 +70,10 @@ func Add(mgr manager.Manager, options WatchOptions) error {
mgr.GetScheme().AddKnownTypeWithName(options.GVK, &unstructured.Unstructured{})
metav1.AddToGroupVersion(mgr.GetScheme(), options.GVK.GroupVersion())

c, err := controller.New(controllerName, mgr, controller.Options{Reconciler: r})
c, err := controller.New(controllerName, mgr, controller.Options{
Reconciler: r,
MaxConcurrentReconciles: options.MaxWorkers,
Copy link
Contributor

Choose a reason for hiding this comment

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

The name is the same used in Ansible. So it shows great 👍

})
if err != nil {
return err
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/helm/flags/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package flags

import (
"strings"

"github.com/operator-framework/operator-sdk/internal/flags/watch"
"github.com/operator-framework/operator-sdk/pkg/log/zap"
"github.com/spf13/pflag"
Expand All @@ -23,6 +25,7 @@ import (
// HelmOperatorFlags - Options to be used by a helm operator
type HelmOperatorFlags struct {
watch.WatchFlags
MaxWorkers int
}

// AddTo - Add the helm operator flags to the the flagset
Expand All @@ -31,5 +34,12 @@ func AddTo(flagSet *pflag.FlagSet, helpTextPrefix ...string) *HelmOperatorFlags
hof := &HelmOperatorFlags{}
hof.WatchFlags.AddTo(flagSet, helpTextPrefix...)
flagSet.AddFlagSet(zap.FlagSet())
flagSet.IntVar(&hof.MaxWorkers,
"max-workers",
1,
strings.Join(append(helpTextPrefix,
"Maximum number of workers to use."),
" "),
)
return hof
}
1 change: 1 addition & 0 deletions pkg/helm/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func Run(flags *hoflags.HelmOperatorFlags) error {
ReconcilePeriod: flags.ReconcilePeriod,
WatchDependentResources: w.WatchDependentResources,
OverrideValues: w.OverrideValues,
MaxWorkers: flags.MaxWorkers,
})
if err != nil {
log.Error(err, "Failed to add manager factory to controller.")
Expand Down