Skip to content

Commit

Permalink
Rename reconcileIntervalSeconds to reconcileIntervalMinimum (#673)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Christy Jesuraj <[email protected]>
  • Loading branch information
leochr authored Dec 8, 2024
1 parent 9f84d9a commit 762c4a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const (
// zapcore.Level is defined as int8, so this logs everything
zLevelDebugMax zapcore.Level = -127

// OpConfigReconcileIntervalSeconds default reconciliation interval in seconds
OpConfigReconcileIntervalSeconds = "reconcileIntervalSeconds"
// OpConfigReconcileIntervalMinimum default reconciliation interval in seconds
OpConfigReconcileIntervalMinimum = "reconcileIntervalMinimum"

// OpConfigReconcileIntervalPercentage default reconciliation interval increase, represented as a percentage (100 equaling to 100%)
// When the reconciliation interval needs to increase, it will increase by the given percentage
Expand Down Expand Up @@ -106,7 +106,7 @@ func CheckValidValue(oc *sync.Map, key string, OperatorName string) error {
if err != nil {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " has an invalid syntax, error: " + err.Error())
} else if key == OpConfigReconcileIntervalSeconds && intValue <= 0 {
} else if key == OpConfigReconcileIntervalMinimum && intValue <= 0 {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
} else if key == OpConfigReconcileIntervalPercentage && intValue < 0 {
Expand Down Expand Up @@ -158,7 +158,7 @@ func DefaultOpConfig() *sync.Map {
cfg.Store(OpConfigCMCADuration, "8766h")
cfg.Store(OpConfigCMCertDuration, "2160h")
cfg.Store(OpConfigLogLevel, logLevelInfo)
cfg.Store(OpConfigReconcileIntervalSeconds, "5")
cfg.Store(OpConfigReconcileIntervalMinimum, "5")
cfg.Store(OpConfigReconcileIntervalPercentage, "100")
return cfg
}
2 changes: 1 addition & 1 deletion internal/controller/runtimecomponent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
return reconcile.Result{}, err
}

if err = common.CheckValidValue(common.Config, common.OpConfigReconcileIntervalSeconds, OperatorName); err != nil {
if err = common.CheckValidValue(common.Config, common.OpConfigReconcileIntervalMinimum, OperatorName); err != nil {
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
}

Expand Down
6 changes: 3 additions & 3 deletions utils/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func addStatusWarnings(ba common.BaseComponent) {
}

func getBaseReconcileInterval(s common.BaseComponentStatus) int32 {
baseIntervalInt, _ := strconv.Atoi(common.LoadFromConfig(common.Config, common.OpConfigReconcileIntervalSeconds))
baseIntervalInt, _ := strconv.Atoi(common.LoadFromConfig(common.Config, common.OpConfigReconcileIntervalMinimum))
baseInterval := int32(baseIntervalInt)
s.SetReconcileInterval(&baseInterval)

Expand All @@ -213,7 +213,7 @@ func resetReconcileInterval(newCondition common.StatusCondition, s common.BaseCo
return time.Duration(baseInterval) * time.Second
}

// Precondition: Operator config values for common.OpConfigReconcileIntervalSeconds and common.OpConfigReconcileIntervalPercentage must be integers
// Precondition: Operator config values for common.OpConfigReconcileIntervalMinimum and common.OpConfigReconcileIntervalPercentage must be integers
func updateReconcileInterval(maxSeconds int, oldCondition common.StatusCondition, newCondition common.StatusCondition, s common.BaseComponentStatus) time.Duration {
var oldReconcileInterval int32

Expand All @@ -238,7 +238,7 @@ func updateReconcileInterval(maxSeconds int, oldCondition common.StatusCondition
exp := float64(newCount / 2)
increase := math.Pow(1+(intervalIncreasePercentage/100), exp)

baseInterval, _ := strconv.ParseFloat(common.LoadFromConfig(common.Config, common.OpConfigReconcileIntervalSeconds), 64)
baseInterval, _ := strconv.ParseFloat(common.LoadFromConfig(common.Config, common.OpConfigReconcileIntervalMinimum), 64)
newInterval := int32(baseInterval * increase)

// Only increase to the maximum interval
Expand Down

0 comments on commit 762c4a3

Please sign in to comment.