Skip to content

Commit

Permalink
different increased requeue times for different Gardener operation
Browse files Browse the repository at this point in the history
  • Loading branch information
koala7659 committed Nov 25, 2024
1 parent 06bfa9a commit 12cd166
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 45 deletions.
40 changes: 21 additions & 19 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,17 @@ func init() {

// Default values for the Runtime controller configuration
const (
defaultControlPlaneRequeueDuration = 10 * time.Second
defaultRuntimeCtrlGardenerRequestTimeout = 1 * time.Second
defaultRuntimeCtrlGardenerRateLimiterQps = 5
defaultRuntimeCtrlGardenerRateLimiterBurst = 5
)

// Default values for the Gardener Cluster controller configuration
const (
defaultControlPlaneRequeueDuration = 10 * time.Second
defaultGardenerRequestTimeout = 3 * time.Second
defaultGardenerRateLimiterQps = 5
defaultGardenerRateLimiterBurst = 5
defaultMinimalRotationTimeRatio = 0.6
defaultExpirationTime = 24 * time.Hour
defaultGardenerReconciliationTimeout = 60 * time.Second
defaultGardenerRequeueDuration = 15 * time.Second
defaultShootCreateRequeueDuration = 60 * time.Second
defaultShootDeleteRequeueDuration = 90 * time.Second
defaultShootReconcileRequeueDuration = 30 * time.Second
)

func main() {
Expand Down Expand Up @@ -109,9 +108,9 @@ func main() {
flag.Float64Var(&minimalRotationTimeRatio, "minimal-rotation-time", defaultMinimalRotationTimeRatio, "The ratio determines what is the minimal time that needs to pass to rotate certificate.")
flag.DurationVar(&expirationTime, "kubeconfig-expiration-time", defaultExpirationTime, "Dynamic kubeconfig expiration time")
flag.DurationVar(&gardenerCtrlReconciliationTimeout, "gardener-ctrl-reconcilation-timeout", defaultGardenerReconciliationTimeout, "Timeout duration for reconlication for Gardener Cluster Controller")
flag.DurationVar(&runtimeCtrlGardenerRequestTimeout, "runtime-ctrl-gardener-request-timeout", defaultRuntimeCtrlGardenerRequestTimeout, "Timeout duration for Gardener client for Runtime Controller")
flag.IntVar(&runtimeCtrlGardenerRateLimiterQps, "runtime-ctrl-gardener-ratelimiter-qps", defaultRuntimeCtrlGardenerRateLimiterQps, "Gardener client rate limiter QPS for Runtime Controller")
flag.IntVar(&runtimeCtrlGardenerRateLimiterBurst, "runtime-ctrl-gardener-ratelimiter-burst", defaultRuntimeCtrlGardenerRateLimiterBurst, "Gardener client rate limiter burst for Runtime Controller")
flag.DurationVar(&runtimeCtrlGardenerRequestTimeout, "gardener-request-timeout", defaultGardenerRequestTimeout, "Timeout duration for Gardener client for Runtime Controller")
flag.IntVar(&runtimeCtrlGardenerRateLimiterQps, "gardener-ratelimiter-qps", defaultGardenerRateLimiterQps, "Gardener client rate limiter QPS for Runtime Controller")
flag.IntVar(&runtimeCtrlGardenerRateLimiterBurst, "gardener-ratelimiter-burst", defaultGardenerRateLimiterBurst, "Gardener client rate limiter burst for Runtime Controller")
flag.StringVar(&converterConfigFilepath, "converter-config-filepath", "/converter-config/converter_config.json", "A file path to the gardener shoot converter configuration.")
flag.BoolVar(&shootSpecDumpEnabled, "shoot-spec-dump-enabled", false, "Feature flag to allow persisting specs of created shoots")
flag.BoolVar(&auditLogMandatory, "audit-log-mandatory", true, "Feature flag to enable strict mode for audit log configuration")
Expand Down Expand Up @@ -205,14 +204,17 @@ func main() {
}

cfg := fsm.RCCfg{
GardenerRequeueDuration: defaultGardenerRequeueDuration,
ControlPlaneRequeueDuration: defaultControlPlaneRequeueDuration,
Finalizer: infrastructuremanagerv1.Finalizer,
ShootNamesapace: gardenerNamespace,
Config: config,
AuditLogMandatory: auditLogMandatory,
Metrics: metrics,
AuditLogging: auditLogDataMap,
GardenerRequeueDuration: defaultGardenerRequeueDuration,
RequeueDurationShootCreate: defaultShootCreateRequeueDuration,
RequeueDurationShootDelete: defaultShootDeleteRequeueDuration,
RequeueDurationShootReconcile: defaultShootReconcileRequeueDuration,
ControlPlaneRequeueDuration: defaultControlPlaneRequeueDuration,
Finalizer: infrastructuremanagerv1.Finalizer,
ShootNamesapace: gardenerNamespace,
Config: config,
AuditLogMandatory: auditLogMandatory,
Metrics: metrics,
AuditLogging: auditLogDataMap,
}
if shootSpecDumpEnabled {
cfg.PVCPath = "/testdata/kim"
Expand Down
19 changes: 11 additions & 8 deletions internal/controller/runtime/fsm/runtime_fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,17 @@ type writerGetter = func(filePath string) (io.Writer, error)

// runtime reconciler specific configuration
type RCCfg struct {
GardenerRequeueDuration time.Duration
ControlPlaneRequeueDuration time.Duration
Finalizer string
PVCPath string
ShootNamesapace string
AuditLogMandatory bool
Metrics metrics.Metrics
AuditLogging auditlogs.Configuration
GardenerRequeueDuration time.Duration
RequeueDurationShootCreate time.Duration
RequeueDurationShootDelete time.Duration
RequeueDurationShootReconcile time.Duration
ControlPlaneRequeueDuration time.Duration
Finalizer string
PVCPath string
ShootNamesapace string
AuditLogMandatory bool
Metrics metrics.Metrics
AuditLogging auditlogs.Configuration
config.Config
}

Expand Down
10 changes: 2 additions & 8 deletions internal/controller/runtime/fsm/runtime_fsm_delete_shoot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ package fsm

import (
"context"
"time"

gardener "github.com/gardener/gardener/pkg/apis/core/v1beta1"
imv1 "github.com/kyma-project/infrastructure-manager/api/v1"
"k8s.io/utils/ptr"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
deletionRequeueTime = 2 * time.Minute
)

func sFnDeleteShoot(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) {
m.log.Info("delete shoot state")

// wait section
if !s.shoot.GetDeletionTimestamp().IsZero() {
m.log.Info("Waiting for shoot to be deleted", "Name", s.shoot.Name, "Namespace", s.shoot.Namespace)
return requeueAfter(deletionRequeueTime)
return requeueAfter(m.RCCfg.RequeueDurationShootDelete)
}

// action section
Expand Down Expand Up @@ -63,7 +57,7 @@ func sFnDeleteShoot(ctx context.Context, m *fsm, s *systemState) (stateFn, *ctrl
}

// out section
return updateStatusAndRequeueAfter(deletionRequeueTime)
return updateStatusAndRequeueAfter(m.RCCfg.RequeueDurationShootDelete)
}

// workaround
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func sFnWaitForShootReconcile(_ context.Context, m *fsm, s *systemState) (stateF
"Unknown",
"Shoot update is in progress")

return updateStatusAndRequeueAfter(m.RCCfg.GardenerRequeueDuration)
return updateStatusAndRequeueAfter(m.RCCfg.RequeueDurationShootReconcile)

case gardener.LastOperationStateFailed:
lastErrors := s.shoot.Status.LastErrors
Expand All @@ -36,7 +36,7 @@ func sFnWaitForShootReconcile(_ context.Context, m *fsm, s *systemState) (stateF
imv1.ConditionReasonShootCreationPending,
"Unknown",
"Retryable gardener errors during cluster reconcile")
return updateStatusAndRequeueAfter(m.RCCfg.GardenerRequeueDuration)
return updateStatusAndRequeueAfter(m.RCCfg.RequeueDurationShootReconcile)
}

msg := fmt.Sprintf("error during cluster processing: reconcilation failed for shoot %s, reason: %s, exiting with no retry", s.shoot.Name, reason)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func sFnWaitForShootCreation(_ context.Context, m *fsm, s *systemState) (stateFn
"Unknown",
"Shoot creation in progress")

return updateStatusAndRequeueAfter(m.RCCfg.GardenerRequeueDuration)
return updateStatusAndRequeueAfter(m.RCCfg.RequeueDurationShootCreate)

case gardener.LastOperationStateFailed:
lastErrors := s.shoot.Status.LastErrors
Expand All @@ -52,7 +52,7 @@ func sFnWaitForShootCreation(_ context.Context, m *fsm, s *systemState) (stateFn
imv1.ConditionReasonShootCreationPending,
"Unknown",
"Retryable gardener errors during cluster provisioning")
return updateStatusAndRequeueAfter(m.RCCfg.GardenerRequeueDuration)
return updateStatusAndRequeueAfter(m.RCCfg.RequeueDurationShootCreate)
}

msg := fmt.Sprintf("Provisioning failed for shoot: %s ! Last state: %s, Description: %s", s.shoot.Name, s.shoot.Status.LastOperation.State, s.shoot.Status.LastOperation.Description)
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/runtime/fsm/utilz_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ type fakeFSMOpt func(*fsm) error

const defaultControlPlaneRequeueDuration = 10 * time.Second
const defaultGardenerRequeueDuration = 15 * time.Second
const defaultRequeueDurationShootCreate = 15 * time.Second
const defaultRequeueDurationShootDelete = 15 * time.Second

var (
errFailedToCreateFakeFSM = fmt.Errorf("failed to create fake FSM")
Expand Down
2 changes: 2 additions & 0 deletions internal/controller/runtime/runtime_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ var requCounter = 0 // nolint:gochecknoglobals
func (r *RuntimeReconciler) Reconcile(ctx context.Context, request ctrl.Request) (ctrl.Result, error) {
r.Log.Info(request.String())

// n\]

var runtime imv1.Runtime
if err := r.Get(ctx, request.NamespacedName, &runtime); err != nil {
return ctrl.Result{
Expand Down
15 changes: 9 additions & 6 deletions internal/controller/runtime/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,15 @@ var _ = BeforeSuite(func() {
mm.On("CleanUpRuntimeGauge", mock.Anything, mock.Anything).Return()

fsmCfg := fsm.RCCfg{
Finalizer: imv1.Finalizer,
Config: convConfig,
Metrics: mm,
AuditLogging: map[string]map[string]auditlogs.AuditLogData{},
GardenerRequeueDuration: 3 * time.Second,
ControlPlaneRequeueDuration: 3 * time.Second,
Finalizer: imv1.Finalizer,
Config: convConfig,
Metrics: mm,
AuditLogging: map[string]map[string]auditlogs.AuditLogData{},
GardenerRequeueDuration: 3 * time.Second,
ControlPlaneRequeueDuration: 3 * time.Second,
RequeueDurationShootReconcile: 3 * time.Second,
RequeueDurationShootCreate: 3 * time.Second,
RequeueDurationShootDelete: 3 * time.Second,
}

runtimeReconciler = NewRuntimeReconciler(mgr, gardenerTestClient, logger, fsmCfg)
Expand Down

0 comments on commit 12cd166

Please sign in to comment.