Skip to content

Commit

Permalink
Add back max concurrent reconciles environment variable (#210)
Browse files Browse the repository at this point in the history
* MaxConcurrentReconciles can be set through env var
* Combine max reconciles into main Config struct, surface it in deployment.yaml

Co-authored-by: qibobo <[email protected]>
Signed-off-by: Art Berger <[email protected]>
  • Loading branch information
2 people authored and Art Berger committed Sep 23, 2020
1 parent cecd83a commit a10f63e
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
2 changes: 2 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: MAX_CONCURRENT_RECONCILES
value: 1
image: controller:latest
name: manager
resources:
Expand Down
4 changes: 3 additions & 1 deletion controllers/binding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
)

const (
Expand Down Expand Up @@ -81,8 +82,9 @@ type ControllerReferenceSetter func(owner, controlled metav1.Object, scheme *run

type IBMCloudInfoGetter func(logt logr.Logger, r client.Client, instance *ibmcloudv1.Service) (*ibmcloud.Info, error)

func (r *BindingReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *BindingReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&ibmcloudv1.Binding{}).
Complete(r)
}
Expand Down
12 changes: 9 additions & 3 deletions controllers/manager_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package controllers
import (
"net/http"

"github.com/ibm/cloud-operators/internal/config"
"github.com/ibm/cloud-operators/internal/ibmcloud"
"github.com/ibm/cloud-operators/internal/ibmcloud/auth"
"github.com/ibm/cloud-operators/internal/ibmcloud/cfservice"
"github.com/ibm/cloud-operators/internal/ibmcloud/iam"
"github.com/ibm/cloud-operators/internal/ibmcloud/resource"
"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

Expand All @@ -22,13 +24,17 @@ type Controllers struct {

func SetUpControllers(mgr ctrl.Manager) (*Controllers, error) {
c := setUpControllerDependencies(mgr)
if err := c.BindingReconciler.SetupWithManager(mgr); err != nil {

options := controller.Options{
MaxConcurrentReconciles: config.Get().MaxConcurrentReconciles,
}
if err := c.BindingReconciler.SetupWithManager(mgr, options); err != nil {
return nil, errors.Wrap(err, "Unable to setup binding controller")
}
if err := c.ServiceReconciler.SetupWithManager(mgr); err != nil {
if err := c.ServiceReconciler.SetupWithManager(mgr, options); err != nil {
return nil, errors.Wrap(err, "Unable to setup service controller")
}
if err := c.TokenReconciler.SetupWithManager(mgr); err != nil {
if err := c.TokenReconciler.SetupWithManager(mgr, options); err != nil {
return nil, errors.Wrap(err, "Unable to setup token controller")
}

Expand Down
4 changes: 3 additions & 1 deletion controllers/service_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"

ibmcloudv1 "github.com/ibm/cloud-operators/api/v1"
"github.com/ibm/cloud-operators/internal/config"
Expand Down Expand Up @@ -69,8 +70,9 @@ type ServiceReconciler struct {
UpdateResourceServiceInstance resource.ServiceInstanceUpdater
}

func (r *ServiceReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *ServiceReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&ibmcloudv1.Service{}).
Complete(r)
}
Expand Down
4 changes: 3 additions & 1 deletion controllers/token_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/predicate"
)
Expand Down Expand Up @@ -123,8 +124,9 @@ func (r *TokenReconciler) Reconcile(request ctrl.Request) (ctrl.Result, error) {
return ctrl.Result{RequeueAfter: 10 * time.Minute}, nil
}

func (r *TokenReconciler) SetupWithManager(mgr ctrl.Manager) error {
func (r *TokenReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(options).
For(&corev1.Secret{}).
WithEventFilter(predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool { return shouldProcessSecret(e.Meta) },
Expand Down
20 changes: 11 additions & 9 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,22 @@ var (
)

type Config struct {
APIKey string `envconfig:"bluemix_api_key"`
AccountID string `envconfig:"bluemix_account_id"`
ControllerNamespace string `envconfig:"controller_namespace"`
Org string `envconfig:"bluemix_org"`
Region string `envconfig:"bluemix_region"`
ResourceGroupName string `envconfig:"bluemix_resource_group"`
Space string `envconfig:"bluemix_space"`
SyncPeriod time.Duration `envconfig:"sync_period"`
APIKey string `envconfig:"bluemix_api_key"`
AccountID string `envconfig:"bluemix_account_id"`
ControllerNamespace string `envconfig:"controller_namespace"`
MaxConcurrentReconciles int `envconfig:"max_concurrent_reconciles"`
Org string `envconfig:"bluemix_org"`
Region string `envconfig:"bluemix_region"`
ResourceGroupName string `envconfig:"bluemix_resource_group"`
Space string `envconfig:"bluemix_space"`
SyncPeriod time.Duration `envconfig:"sync_period"`
}

func Get() Config {
loadOnce.Do(func() {
config = Config{ // default values
SyncPeriod: 150 * time.Second,
MaxConcurrentReconciles: 1,
SyncPeriod: 150 * time.Second,
}
envconfig.MustProcess("", &config)
})
Expand Down

0 comments on commit a10f63e

Please sign in to comment.