diff --git a/operator/cmd/main.go b/operator/cmd/main.go index f655f1a..3207f45 100644 --- a/operator/cmd/main.go +++ b/operator/cmd/main.go @@ -175,20 +175,19 @@ func mainWithError() error { informerManager.Start() // Set up the ElastiService controller - reconciler := &controller.ElastiServiceReconciler{ + if err = (&controller.ElastiServiceReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), Logger: zapLogger, InformerManager: informerManager, - } - if err = reconciler.SetupWithManager(mgr); err != nil { + }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "ElastiService") sentry.CaptureException(err) return fmt.Errorf("main: %w", err) } // Start the elasti server - eServer := elastiserver.NewServer(zapLogger, mgr.GetConfig(), 30*time.Second, reconciler) + eServer := elastiserver.NewServer(zapLogger, mgr.GetConfig(), 30*time.Second) errChan := make(chan error, 1) go func() { if err := eServer.Start(elastiServerPort); err != nil { diff --git a/operator/internal/elastiserver/elastiServer.go b/operator/internal/elastiserver/elastiServer.go index ceab36a..55330b5 100644 --- a/operator/internal/elastiserver/elastiServer.go +++ b/operator/internal/elastiserver/elastiServer.go @@ -14,14 +14,11 @@ import ( sentryhttp "github.com/getsentry/sentry-go/http" - "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/rest" "truefoundry/elasti/operator/internal/crddirectory" "truefoundry/elasti/operator/internal/prom" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/truefoundry/elasti/pkg/k8shelper" "github.com/truefoundry/elasti/pkg/messages" @@ -42,11 +39,10 @@ type ( scaleLocks sync.Map // rescaleDuration is the duration to wait before checking to rescaling the target rescaleDuration time.Duration - reconciler reconcile.Reconciler } ) -func NewServer(logger *zap.Logger, config *rest.Config, rescaleDuration time.Duration, reconciler reconcile.Reconciler) *Server { +func NewServer(logger *zap.Logger, config *rest.Config, rescaleDuration time.Duration) *Server { // Get Ops client k8sUtil := k8shelper.NewOps(logger, config) return &Server{ @@ -54,7 +50,6 @@ func NewServer(logger *zap.Logger, config *rest.Config, rescaleDuration time.Dur k8shelper: k8sUtil, // rescaleDuration is the duration to wait before checking to rescaling the target rescaleDuration: rescaleDuration, - reconciler: reconciler, } } @@ -153,7 +148,7 @@ func (s *Server) resolverReqHandler(w http.ResponseWriter, req *http.Request) { zap.String("namespace", body.Namespace)) } -func (s *Server) scaleTargetForService(ctx context.Context, serviceName, namespace string) error { +func (s *Server) scaleTargetForService(_ context.Context, serviceName, namespace string) error { scaleMutex, loaded := s.getMutexForServiceScale(serviceName) if loaded { s.logger.Debug("Scale target lock already exists", zap.String("service", serviceName)) @@ -162,26 +157,10 @@ func (s *Server) scaleTargetForService(ctx context.Context, serviceName, namespa scaleMutex.Lock() defer s.logger.Debug("Scale target lock released", zap.String("service", serviceName)) s.logger.Debug("Scale target lock taken", zap.String("service", serviceName)) - crd, found := crddirectory.CRDDirectory.GetCRD(serviceName) if !found { - s.logger.Debug("Failed to get CRD details from directory, running reconcile") - _, err := s.reconciler.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Name: serviceName, - Namespace: namespace, - }, - }) - if err != nil { - s.releaseMutexForServiceScale(serviceName) - return fmt.Errorf("scaleTargetForService - error: reconcile failed, serviceName: %s, %w", serviceName, err) - } - - crd, found = crddirectory.CRDDirectory.GetCRD(serviceName) - if !found { - s.releaseMutexForServiceScale(serviceName) - return fmt.Errorf("scaleTargetForService - error: failed to get CRD details from directory even after reconcile, serviceName: %s", serviceName) - } + s.releaseMutexForServiceScale(serviceName) + return fmt.Errorf("scaleTargetForService - error: failed to get CRD details from directory, serviceName: %s", serviceName) } if err := s.k8shelper.ScaleTargetWhenAtZero(namespace, crd.Spec.ScaleTargetRef.Name, crd.Spec.ScaleTargetRef.Kind, crd.Spec.MinTargetReplicas); err != nil {