Skip to content

Commit

Permalink
addressed the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cchen-vertica committed Nov 12, 2024
1 parent ac15c70 commit 23aaaee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
11 changes: 10 additions & 1 deletion cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"log"
"os"
"time"

// Allows us to pull in things generated from `go generate`
_ "embed"
Expand All @@ -33,8 +34,10 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/manager"

Expand Down Expand Up @@ -89,13 +92,19 @@ func addReconcilersToManager(mgr manager.Manager, restCfg *rest.Config) {
return
}

// Create a custom option with our own rate limiter
rateLimiter := workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond,
time.Duration(opcfg.GetVdbMaxBackoffDuration())*time.Millisecond)
options := controller.Options{
RateLimiter: rateLimiter,
}
if err := (&vdb.VerticaDBReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("VerticaDB"),
Scheme: mgr.GetScheme(),
Cfg: restCfg,
EVRec: mgr.GetEventRecorderFor(vmeta.OperatorName),
}).SetupWithManager(mgr); err != nil {
}).SetupWithManager(mgr, options); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "VerticaDB")
os.Exit(1)
}
Expand Down
9 changes: 2 additions & 7 deletions pkg/controllers/vdb/verticadb_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand All @@ -41,7 +40,6 @@ import (
"github.com/vertica/vertica-kubernetes/pkg/events"
vmeta "github.com/vertica/vertica-kubernetes/pkg/meta"
"github.com/vertica/vertica-kubernetes/pkg/metrics"
"github.com/vertica/vertica-kubernetes/pkg/opcfg"
"github.com/vertica/vertica-kubernetes/pkg/podfacts"
"github.com/vertica/vertica-kubernetes/pkg/vadmin"
"github.com/vertica/vertica-kubernetes/pkg/vk8s"
Expand Down Expand Up @@ -75,12 +73,9 @@ type VerticaDBReconciler struct {
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch

// SetupWithManager sets up the controller with the Manager.
func (r *VerticaDBReconciler) SetupWithManager(mgr ctrl.Manager) error {
rateLimiter := workqueue.NewItemExponentialFailureRateLimiter(1*time.Millisecond,
time.Duration(opcfg.GetVdbMaxBackoffDuration())*time.Millisecond)

func (r *VerticaDBReconciler) SetupWithManager(mgr ctrl.Manager, options controller.Options) error {
return ctrl.NewControllerManagedBy(mgr).
WithOptions(controller.Options{RateLimiter: rateLimiter}).
WithOptions(options).
For(&vapi.VerticaDB{}).
Owns(&corev1.ServiceAccount{}).
Owns(&rbacv1.Role{}).
Expand Down
11 changes: 8 additions & 3 deletions pkg/opcfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,15 @@ func getStackTrace() zap.Option {

// GetVdbMaxBackoffDuration returns maximum backoff requeue duration in milliseconds for vdb controller
func GetVdbMaxBackoffDuration() int {
duration := lookupIntEnvVar("VDB_MAX_BACKOFF_DURATION", envCanNotExist)
if duration == 0 {
const envName = "VDB_MAX_BACKOFF_DURATION"
duration := lookupStringEnvVar(envName, envCanNotExist)
if duration == "" {
// Default value is 1000ms
return 1000
}
return duration
valInt, err := strconv.Atoi(duration)
if err != nil || valInt < 0 {
dieIfNotValid(envName)
}
return valInt
}

0 comments on commit 23aaaee

Please sign in to comment.