Skip to content

Commit

Permalink
fix: disable runner
Browse files Browse the repository at this point in the history
  • Loading branch information
bavarianbidi committed Jan 10, 2024
1 parent 9f11e74 commit a8dd8d4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 34 deletions.
36 changes: 19 additions & 17 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 17 additions & 17 deletions internal/controller/pool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions pkg/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ const (
DefaultEnterpriseConcurrency = 1
DefaultOrganizationConcurrency = 5
DefaultPoolConcurrency = 10

// default values for controller reconciliation configuration
DefaultRunnerReconciliation = false
)
2 changes: 2 additions & 0 deletions pkg/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit a8dd8d4

Please sign in to comment.