Skip to content

Commit

Permalink
Rate limit (#207)
Browse files Browse the repository at this point in the history
* improve rate limit
  • Loading branch information
kerenlahav authored Oct 9, 2022
1 parent 070d59d commit 3bf21c2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion controllers/servicebinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import (
"fmt"
"time"

"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"

servicesv1 "github.com/SAP/sap-btp-service-operator/api/v1"

"github.com/SAP/sap-btp-service-operator/api"
Expand Down Expand Up @@ -292,7 +295,6 @@ func (r *ServiceBindingReconciler) delete(ctx context.Context, smClient sm.Clien
log.Info(fmt.Sprintf("Deleting binding with id %v from SM", serviceBinding.Status.BindingID))
operationURL, unbindErr := smClient.Unbind(serviceBinding.Status.BindingID, nil, buildUserInfo(ctx, serviceBinding.Spec.UserInfo))
if unbindErr != nil {
log.Error(unbindErr, "failed to delete binding")
// delete will proceed anyway
return r.markAsNonTransientError(ctx, smTypes.DELETE, unbindErr, serviceBinding)
}
Expand Down Expand Up @@ -439,6 +441,7 @@ func (r *ServiceBindingReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&servicesv1.ServiceBinding{}).
Owns(&corev1.Secret{}).
WithOptions(controller.Options{RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(r.Config.RetryBaseDelay, r.Config.RetryMaxDelay)}).
Complete(r)
}

Expand Down
4 changes: 4 additions & 0 deletions controllers/serviceinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"encoding/json"
"fmt"

"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"

servicesv1 "github.com/SAP/sap-btp-service-operator/api/v1"

"github.com/SAP/sap-btp-service-operator/api"
Expand Down Expand Up @@ -442,6 +445,7 @@ func getOfferingTags(smClient sm.Client, planID string) ([]string, error) {
func (r *ServiceInstanceReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&servicesv1.ServiceInstance{}).
WithOptions(controller.Options{RateLimiter: workqueue.NewItemExponentialFailureRateLimiter(r.Config.RetryBaseDelay, r.Config.RetryMaxDelay)}).
Complete(r)
}

Expand Down
4 changes: 3 additions & 1 deletion controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ var _ = BeforeSuite(func(done Done) {
Expect(err).ToNot(HaveOccurred())

fakeClient = &smfakes.FakeClient{}
testConfig := config.Config{SyncPeriod: syncPeriod, PollInterval: pollInterval}
testConfig := config.Get()
testConfig.SyncPeriod = syncPeriod
testConfig.PollInterval = pollInterval
err = (&ServiceInstanceReconciler{
BaseReconciler: &BaseReconciler{
Client: k8sManager.GetClient(),
Expand Down
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Config struct {
AllowedNamespaces []string `envconfig:"allowed_namespaces"`
EnableNamespaceSecrets bool `envconfig:"enable_namespace_secrets"`
ClusterID string `envconfig:"cluster_id"`
RetryBaseDelay time.Duration `envconfig:"retry_base_delay"`
RetryMaxDelay time.Duration `envconfig:"retry_max_delay"`
}

func Get() Config {
Expand All @@ -33,6 +35,8 @@ func Get() Config {
EnableNamespaceSecrets: true,
AllowedNamespaces: []string{},
AllowClusterAccess: true,
RetryBaseDelay: 10 * time.Second,
RetryMaxDelay: time.Hour,
}
envconfig.MustProcess("", &config)
})
Expand Down

0 comments on commit 3bf21c2

Please sign in to comment.