Skip to content

Commit

Permalink
Use consistent naming for the manager
Browse files Browse the repository at this point in the history
  • Loading branch information
ialidzhikov committed Mar 27, 2024
1 parent 2717e89 commit 9b25d78
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
14 changes: 7 additions & 7 deletions cmd/gardener-custom-metrics/main.go
Expand Up @@ -14,7 +14,7 @@ import (
"k8s.io/component-base/version"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
kmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/gardener/gardener-custom-metrics/pkg/app"
"github.com/gardener/gardener-custom-metrics/pkg/ha"
Expand Down Expand Up @@ -71,7 +71,7 @@ func getRootCommand() *cobra.Command {
// completeAppCLIOptions completes initialisation based on application-level CLI options.
// Upon error, any of the returned Logger, Manager, and HAService may be nil.
func completeAppCLIOptions(
ctx context.Context, appOptions *app.CLIOptions) (*logr.Logger, kmgr.Manager, *ha.HAService, error) {
ctx context.Context, appOptions *app.CLIOptions) (*logr.Logger, manager.Manager, *ha.HAService, error) {

if err := appOptions.Complete(); err != nil {
return nil, nil, nil, fmt.Errorf("completing application level CLI options: %w", err)
Expand All @@ -87,7 +87,7 @@ func completeAppCLIOptions(
return &log, nil, nil, fmt.Errorf("create client set: %w", err)
}
log.V(app.VerbosityVerbose).Info("Creating controller manager")
mgr, err := kmgr.New(appOptions.RestOptions.Completed().Config, appOptions.Completed().ManagerOptions())
mgr, err := manager.New(appOptions.RestOptions.Completed().Config, appOptions.Completed().ManagerOptions())
if err != nil {
return &log, nil, nil, fmt.Errorf("creating controller manager: %w", err)
}
Expand All @@ -109,20 +109,20 @@ func completeInputServiceCLIOptions(options *input.CLIOptions, log logr.Logger)
}

// completeMetircsProviderServiceCLIOptions completes initialisation based on CLI options related to metrics serving.
// It returns a [kmgr.Runnable] which can be executed under the supervision of a controller manager.
// It returns a [manager.Runnable] which can be executed under the supervision of a controller manager.
//
// The onFailedFunc parameter is a function which will be called by the [kmgr.Runnable] if it fails.
// The onFailedFunc parameter is a function which will be called by the [manager.Runnable] if it fails.
func completeMetircsProviderServiceCLIOptions(
metricsService *metrics_provider.MetricsProviderService,
inputService input.InputDataService,
log logr.Logger,
onFailedFunc context.CancelFunc) (kmgr.RunnableFunc, error) {
onFailedFunc context.CancelFunc) (manager.RunnableFunc, error) {

if err := metricsService.CompleteCLIConfiguration(inputService.DataSource(), log); err != nil {
return nil, fmt.Errorf("configure metrics adapter based on command line arguments: %w", err)
}

var metricsProviderRunnable kmgr.RunnableFunc = func(ctx context.Context) error {
var metricsProviderRunnable manager.RunnableFunc = func(ctx context.Context) error {
if err := metricsService.Run(ctx.Done()); err != nil {
log.V(app.VerbosityError).Error(err, "Failed to run custom metrics adapter")
onFailedFunc()
Expand Down
10 changes: 5 additions & 5 deletions pkg/input/controller/pod/add.go
Expand Up @@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"
kmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/gardener/gardener-custom-metrics/pkg/app"
Expand All @@ -34,12 +34,12 @@ import (
// dataRegistry is a concurrency-safe data repository where the controller finds data it needs, and stores
// the data it produces.
func AddToManagerWithOptions(
manager kmgr.Manager,
mgr manager.Manager,
dataRegistry scrape_target_registry.InputDataRegistry,
controllerOptions *controller.Options,
log logr.Logger) error {

return gcmctl.NewControllerFactory().AddNewControllerToManager(manager, gcmctl.AddArgs{
return gcmctl.NewControllerFactory().AddNewControllerToManager(mgr, gcmctl.AddArgs{
Actuator: NewActuator(dataRegistry, log.WithName("pod-controller")),
ControllerName: app.Name + "-pod-controller",
ControllerOptions: *controllerOptions,
Expand All @@ -49,9 +49,9 @@ func AddToManagerWithOptions(
}

// AddToManager adds a new pod controller to the specified manager, using default option values.
func AddToManager(manager kmgr.Manager, dataRegistry scrape_target_registry.InputDataRegistry, log logr.Logger) error {
func AddToManager(mgr manager.Manager, dataRegistry scrape_target_registry.InputDataRegistry, log logr.Logger) error {
return AddToManagerWithOptions(
manager,
mgr,
dataRegistry,
&controller.Options{
RateLimiter: workqueue.NewMaxOfRateLimiter(
Expand Down
10 changes: 5 additions & 5 deletions pkg/input/controller/secret/add.go
Expand Up @@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"
kmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/predicate"

"github.com/gardener/gardener-custom-metrics/pkg/app"
Expand All @@ -34,12 +34,12 @@ import (
// dataRegistry is a concurrency-safe data repository where the controller finds data it needs, and stores
// the data it produces.
func AddToManagerWithOptions(
manager kmgr.Manager,
mgr manager.Manager,
dataRegistry scrape_target_registry.InputDataRegistry,
controllerOptions *controller.Options,
log logr.Logger) error {

return gcmctl.NewControllerFactory().AddNewControllerToManager(manager, gcmctl.AddArgs{
return gcmctl.NewControllerFactory().AddNewControllerToManager(mgr, gcmctl.AddArgs{
Actuator: NewActuator(dataRegistry, log.WithName("secret-controller")),
ControllerName: app.Name + "-secret-controller",
ControllerOptions: *controllerOptions,
Expand All @@ -49,9 +49,9 @@ func AddToManagerWithOptions(
}

// AddToManager adds a new secret controller to the specified manager, using default option values.
func AddToManager(manager kmgr.Manager, dataRegistry scrape_target_registry.InputDataRegistry, log logr.Logger) error {
func AddToManager(mgr manager.Manager, dataRegistry scrape_target_registry.InputDataRegistry, log logr.Logger) error {
return AddToManagerWithOptions(
manager,
mgr,
dataRegistry,
&controller.Options{
RateLimiter: workqueue.NewMaxOfRateLimiter(
Expand Down
14 changes: 7 additions & 7 deletions pkg/input/input_data_service.go
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
kmgr "sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/gardener/gardener-custom-metrics/pkg/app"
podctl "github.com/gardener/gardener-custom-metrics/pkg/input/controller/pod"
Expand Down Expand Up @@ -43,7 +43,7 @@ type InputDataService interface {
// DataSource returns an interface for consuming metrics provided by the InputDataService
DataSource() input_data_registry.InputDataSource
// AddToManager adds all of InputDataService's underlying data gathering activities to the specified manager.
AddToManager(manager kmgr.Manager) error
AddToManager(mgr manager.Manager) error
}

type inputDataService struct {
Expand Down Expand Up @@ -76,7 +76,7 @@ func (ids *inputDataService) DataSource() input_data_registry.InputDataSource {
return ids.inputDataRegistry.DataSource()
}

func (ids *inputDataService) AddToManager(manager kmgr.Manager) error {
func (ids *inputDataService) AddToManager(mgr manager.Manager) error {
ids.log.V(app.VerbosityInfo).Info("Creating scraper")
scraper := ids.testIsolation.NewScraper(
ids.inputDataRegistry,
Expand All @@ -86,20 +86,20 @@ func (ids *inputDataService) AddToManager(manager kmgr.Manager) error {

ids.log.V(app.VerbosityVerbose).Info("Updating manager schemes")
builder := runtime.NewSchemeBuilder(scheme.AddToScheme)
if err := builder.AddToScheme(manager.GetScheme()); err != nil {
if err := builder.AddToScheme(mgr.GetScheme()); err != nil {
return fmt.Errorf("add input data service scheme to manager: %w", err)
}

ids.log.V(app.VerbosityVerbose).Info("Adding controllers to manager")
if err := podctl.AddToManager(manager, ids.inputDataRegistry, ids.log.V(1)); err != nil {
if err := podctl.AddToManager(mgr, ids.inputDataRegistry, ids.log.V(1)); err != nil {
return fmt.Errorf("add pod controller to manager: %w", err)
}
if err := secretctl.AddToManager(manager, ids.inputDataRegistry, ids.log.V(1)); err != nil {
if err := secretctl.AddToManager(mgr, ids.inputDataRegistry, ids.log.V(1)); err != nil {
return fmt.Errorf("add secret controller to manager: %w", err)
}

ids.log.V(app.VerbosityVerbose).Info("Adding scraper to manager")
if err := manager.Add(scraper); err != nil {
if err := mgr.Add(scraper); err != nil {
return fmt.Errorf("add scraper to controller manager: %w", err)
}

Expand Down

0 comments on commit 9b25d78

Please sign in to comment.