From a8dd8d4825d8518c28ac2f3e85eb5a92e00b4a62 Mon Sep 17 00:00:00 2001 From: Mario Constanti Date: Wed, 10 Jan 2024 10:34:52 +0100 Subject: [PATCH] fix: disable runner --- cmd/main.go | 36 ++++++++++++++------------ internal/controller/pool_controller.go | 34 ++++++++++++------------ pkg/config/config.go | 1 + pkg/defaults/defaults.go | 3 +++ pkg/flags/flags.go | 2 ++ 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index d3ee6c4a..9dee6ddd 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -187,25 +187,27 @@ func run() error { return fmt.Errorf("unable to create controller Repository: %w", err) } - eventChan := make(chan event.GenericEvent) - runnerReconciler := &garmcontroller.RunnerReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - } + if config.Config.Operator.RunnerReconciliation { + eventChan := make(chan event.GenericEvent) + runnerReconciler := &garmcontroller.RunnerReconciler{ + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + } - // setup controller so it can reconcile if events from eventChan are queued - if err = runnerReconciler.SetupWithManager(mgr, eventChan, - controller.Options{ - MaxConcurrentReconciles: config.Config.Operator.RunnerConcurrency, - }, - ); err != nil { - return fmt.Errorf("unable to create controller Runner: %w", err) - } + // setup controller so it can reconcile if events from eventChan are queued + if err = runnerReconciler.SetupWithManager(mgr, eventChan, + controller.Options{ + MaxConcurrentReconciles: config.Config.Operator.RunnerConcurrency, + }, + ); err != nil { + return fmt.Errorf("unable to create controller Runner: %w", err) + } - // fetch runner instances periodically and enqueue reconcile events for runner ctrl if external system has changed - ctx, cancel := context.WithCancel(ctx) - go runnerReconciler.PollRunnerInstances(ctx, eventChan) - defer cancel() + // fetch runner instances periodically and enqueue reconcile events for runner ctrl if external system has changed + ctx, cancel := context.WithCancel(ctx) + go runnerReconciler.PollRunnerInstances(ctx, eventChan) + defer cancel() + } //+kubebuilder:scaffold:builder diff --git a/internal/controller/pool_controller.go b/internal/controller/pool_controller.go index 2f6703b4..bda1f7e1 100644 --- a/internal/controller/pool_controller.go +++ b/internal/controller/pool_controller.go @@ -153,16 +153,16 @@ func (r *PoolReconciler) reconcileUpdate(ctx context.Context, garmClient garmCli WithName("reconcileUpdate") log.Info("pool on garm side found", "id", pool.Status.ID, "name", pool.Name) - poolNeedsUpdate, runners, err := r.comparePoolSpecs(ctx, pool, garmClient) + poolNeedsUpdate, _, err := r.comparePoolSpecs(ctx, pool, garmClient) if err != nil { log.Error(err, "error comparing pool specs") return r.handleUpdateError(ctx, pool, err) } - idleRunners, err := poolUtil.ExtractIdleRunners(ctx, runners) - if err != nil { - return r.handleUpdateError(ctx, pool, err) - } + // idleRunners, err := poolUtil.ExtractIdleRunners(ctx, runners) + // if err != nil { + // return r.handleUpdateError(ctx, pool, err) + // } if !poolNeedsUpdate { log.Info("pool CR differs from pool on garm side. Trigger a garm pool update") @@ -180,21 +180,21 @@ func (r *PoolReconciler) reconcileUpdate(ctx context.Context, garmClient garmCli } // update pool idle runners count in status - pool.Status.IdleRunners = uint(len(idleRunners)) - pool.Status.Runners = uint(len(runners)) - if err := r.updatePoolCRStatus(ctx, pool); err != nil { - return ctrl.Result{}, err - } + // pool.Status.IdleRunners = uint(len(idleRunners)) + // pool.Status.Runners = uint(len(runners)) + // if err := r.updatePoolCRStatus(ctx, pool); err != nil { + // return ctrl.Result{}, err + // } // If there are more idle Runners than minIdleRunners are defined in // the spec, we force a runner deletion. - if pool.Status.IdleRunners > pool.Spec.MinIdleRunners { - log.Info("Scaling pool", "pool", pool.Name) - event.Scaling(r.Recorder, pool, fmt.Sprintf("scale idle runners down to %d", pool.Spec.MinIdleRunners)) - if err := poolUtil.AlignIdleRunners(ctx, pool, idleRunners, instanceClient); err != nil { - return ctrl.Result{}, err - } - } + // if pool.Status.IdleRunners > pool.Spec.MinIdleRunners { + // log.Info("Scaling pool", "pool", pool.Name) + // event.Scaling(r.Recorder, pool, fmt.Sprintf("scale idle runners down to %d", pool.Spec.MinIdleRunners)) + // if err := poolUtil.AlignIdleRunners(ctx, pool, idleRunners, instanceClient); err != nil { + // return ctrl.Result{}, err + // } + // } return ctrl.Result{}, nil } diff --git a/pkg/config/config.go b/pkg/config/config.go index 1245d8f0..b1bb52c2 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -36,6 +36,7 @@ type OperatorConfig struct { EnterpriseConcurrency int `koanf:"enterprise_concurrency" validate:"gte=1"` OrganizationConcurrency int `koanf:"organization_concurrency" validate:"gte=1"` PoolConcurrency int `koanf:"pool_concurrency" validate:"gte=1"` + RunnerReconciliation bool `koanf:"runner_reconciliation"` } type AppConfig struct { diff --git a/pkg/defaults/defaults.go b/pkg/defaults/defaults.go index ac5d5b75..59017d9e 100644 --- a/pkg/defaults/defaults.go +++ b/pkg/defaults/defaults.go @@ -23,4 +23,7 @@ const ( DefaultEnterpriseConcurrency = 1 DefaultOrganizationConcurrency = 5 DefaultPoolConcurrency = 10 + + // default values for controller reconciliation configuration + DefaultRunnerReconciliation = false ) diff --git a/pkg/flags/flags.go b/pkg/flags/flags.go index 6763d765..7aa32889 100644 --- a/pkg/flags/flags.go +++ b/pkg/flags/flags.go @@ -33,6 +33,8 @@ func InitiateFlags() *pflag.FlagSet { f.Int("operator-organization-concurrency", defaults.DefaultOrganizationConcurrency, "Specifies the maximum number of concurrent organizations that can be reconciled simultaneously") f.Int("operator-pool-concurrency", defaults.DefaultPoolConcurrency, "Specifies the maximum number of concurrent pools that can be reconciled simultaneously") + f.Bool("operator-runner-reconciliation", defaults.DefaultRunnerReconciliation, "Specifies if runner reconciliation should be enabled") + f.String("garm-server", "", "The address of the GARM server") f.String("garm-username", "", "The username for the GARM server") f.String("garm-password", "", "The password for the GARM server")