Skip to content

Commit 416cc2c

Browse files
authored
Use latest transition time to adjust reconcile interval (#680)
* Use latest transition time to adjust reconcile interval and add options to adjust reconcililation configurations * Updates to typos and checks for reconcile interval * Fix lastestTransitionTime
1 parent 7510264 commit 416cc2c

13 files changed

Lines changed: 164 additions & 136 deletions

File tree

api/v1/runtimecomponent_types.go

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,6 @@ type StatusCondition struct {
443443
Message string `json:"message,omitempty"`
444444
Status corev1.ConditionStatus `json:"status,omitempty"`
445445
Type StatusConditionType `json:"type,omitempty"`
446-
447-
// The count of the number of reconciles the condition status type has not changed.
448-
UnchangedConditionCount *int32 `json:"unchangedConditionCount,omitempty"`
449446
}
450447

451448
// Defines the type of status condition.
@@ -1112,6 +1109,19 @@ func (c *StatusCondition) SetLastTransitionTime(t *metav1.Time) {
11121109
c.LastTransitionTime = t
11131110
}
11141111

1112+
// GetLatestTransitionTime returns latest time of status change
1113+
func (s *RuntimeComponentStatus) GetLatestTransitionTime() *metav1.Time {
1114+
var latestTime *metav1.Time
1115+
for i := range s.Conditions {
1116+
t := s.Conditions[i].GetLastTransitionTime()
1117+
// If latestTime is not set or condition's time is before latestTime
1118+
if latestTime == nil || latestTime.Before(t) {
1119+
latestTime = t
1120+
}
1121+
}
1122+
return latestTime
1123+
}
1124+
11151125
// GetMessage returns condition's message
11161126
func (c *StatusCondition) GetMessage() string {
11171127
return c.Message
@@ -1188,15 +1198,14 @@ func (s *RuntimeComponentStatus) SetCondition(c common.StatusCondition) {
11881198
}
11891199
}
11901200

1191-
if condition.GetStatus() != c.GetStatus() || condition.GetMessage() != c.GetMessage() {
1201+
if condition.GetStatus() != c.GetStatus() || condition.GetMessage() != c.GetMessage() || condition.GetReason() != c.GetReason() {
11921202
condition.SetLastTransitionTime(&metav1.Time{Time: time.Now()})
11931203
}
11941204

11951205
condition.SetReason(c.GetReason())
11961206
condition.SetMessage(c.GetMessage())
11971207
condition.SetStatus(c.GetStatus())
11981208
condition.SetType(c.GetType())
1199-
condition.SetUnchangedConditionCount(c.GetUnchangedConditionCount())
12001209
if !found {
12011210
s.Conditions = append(s.Conditions, *condition)
12021211
}
@@ -1237,31 +1246,17 @@ func (s *RuntimeComponentStatus) SetReconcileInterval(interval *int32) {
12371246
s.ReconcileInterval = interval
12381247
}
12391248

1249+
func (s *RuntimeComponentStatus) UnsetReconcileInterval() {
1250+
s.ReconcileInterval = nil
1251+
}
1252+
12401253
func (s *RuntimeComponentStatus) SetReference(name string, value string) {
12411254
if s.References == nil {
12421255
s.References = make(common.StatusReferences)
12431256
}
12441257
s.References[name] = value
12451258
}
12461259

1247-
func (sc *StatusCondition) GetUnchangedConditionCount() *int32 {
1248-
return sc.UnchangedConditionCount
1249-
}
1250-
1251-
func (sc *StatusCondition) SetUnchangedConditionCount(count *int32) {
1252-
sc.UnchangedConditionCount = count
1253-
}
1254-
1255-
func (s *RuntimeComponentStatus) UnsetUnchangedConditionCount(conditionType common.StatusConditionType) {
1256-
// Reset unchanged count for other status conditions
1257-
var emptyCount *int32
1258-
for i := range s.Conditions {
1259-
if s.Conditions[i].GetType() != conditionType && s.Conditions[i].GetUnchangedConditionCount() != nil {
1260-
s.Conditions[i].SetUnchangedConditionCount(emptyCount)
1261-
}
1262-
}
1263-
}
1264-
12651260
func convertToCommonStatusConditionType(c StatusConditionType) common.StatusConditionType {
12661261
switch c {
12671262
case StatusConditionTypeReconciled:

api/v1/zz_generated.deepcopy.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1beta2/runtimecomponent_types.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -389,15 +389,7 @@ func (s *RuntimeComponentStatus) SetReconcileInterval(interval *int32) {
389389
return
390390
}
391391

392-
func (s *StatusCondition) GetUnchangedConditionCount() *int32 {
393-
return nil
394-
}
395-
396-
func (s *StatusCondition) SetUnchangedConditionCount(count *int32) {
397-
return
398-
}
399-
400-
func (s *RuntimeComponentStatus) UnsetUnchangedConditionCount(conditionType common.StatusConditionType) {
392+
func (s *RuntimeComponentStatus) UnsetReconcileInterval() {
401393
return
402394
}
403395

@@ -917,6 +909,10 @@ func (c *StatusCondition) SetLastTransitionTime(t *metav1.Time) {
917909
c.LastTransitionTime = t
918910
}
919911

912+
func (s *RuntimeComponentStatus) GetLatestTransitionTime() *metav1.Time {
913+
return nil
914+
}
915+
920916
// GetMessage return condition's message
921917
func (c *StatusCondition) GetMessage() string {
922918
return c.Message

bundle/manifests/rc.app.stacks_runtimecomponents.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8101,11 +8101,6 @@ spec:
81018101
type:
81028102
description: Defines the type of status condition.
81038103
type: string
8104-
unchangedConditionCount:
8105-
description: The count of the number of reconciles the condition
8106-
status type has not changed.
8107-
format: int32
8108-
type: integer
81098104
type: object
81108105
type: array
81118106
x-kubernetes-list-type: atomic

common/config.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ const (
5050
// OpConfigReconcileIntervalPercentage default reconciliation interval increase, represented as a percentage (100 equaling to 100%)
5151
// When the reconciliation interval needs to increase, it will increase by the given percentage
5252
OpConfigReconcileIntervalPercentage = "reconcileIntervalIncreasePercentage"
53+
54+
// OpConfigReconcileIntervalFailureMaximum default max reconcile interval for repeated failures
55+
OpConfigReconcileIntervalFailureMaximum = "reconcileIntervalFailureMaximum"
56+
57+
// OpConfigReconcileIntervalSuccessMaximum default max reconcile interval for repeated successful reconciled and application ready status
58+
OpConfigReconcileIntervalSuccessMaximum = "reconcileIntervalSuccessMaximum"
59+
60+
// OpConfigShowReconcileInterval default whether reconcile interval will be visible in the instance's status field
61+
OpConfigShowReconcileInterval = "showReconcileInterval"
5362
)
5463

5564
// Config stores operator configuration
@@ -102,21 +111,34 @@ func LoadFromConfig(oc *sync.Map, key string) string {
102111
func CheckValidValue(oc *sync.Map, key string, OperatorName string) error {
103112
value := LoadFromConfig(oc, key)
104113

105-
intValue, err := strconv.Atoi(value)
114+
floatValue, err := strconv.ParseFloat(value, 64)
106115
if err != nil {
107116
SetConfigMapDefaultValue(oc, key)
108117
return errors.New(key + " in ConfigMap: " + OperatorName + " has an invalid syntax, error: " + err.Error())
109-
} else if key == OpConfigReconcileIntervalMinimum && intValue <= 0 {
118+
} else if key == OpConfigReconcileIntervalMinimum && floatValue <= 0 {
110119
SetConfigMapDefaultValue(oc, key)
111120
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
112-
} else if key == OpConfigReconcileIntervalPercentage && intValue < 0 {
121+
} else if key == OpConfigReconcileIntervalPercentage && floatValue < 0 {
113122
SetConfigMapDefaultValue(oc, key)
114123
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than or equal to 0.")
124+
} else if key == OpConfigReconcileIntervalFailureMaximum && floatValue <= 0 {
125+
SetConfigMapDefaultValue(oc, key)
126+
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
127+
} else if key == OpConfigReconcileIntervalSuccessMaximum && floatValue <= 0 {
128+
SetConfigMapDefaultValue(oc, key)
129+
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
115130
}
116-
117131
return nil
118132
}
119133

134+
func UpdateReconcileIntervalPercentage(oc *sync.Map, OperatorName string) {
135+
intervalIncreasePercentage, _ := strconv.ParseFloat(LoadFromConfig(oc, OpConfigReconcileIntervalPercentage), 64)
136+
if intervalIncreasePercentage == 100 {
137+
intervalIncreasePercentageStr := strconv.FormatFloat(50, 'f', -1, 64)
138+
oc.Store(OpConfigReconcileIntervalPercentage, intervalIncreasePercentageStr)
139+
}
140+
}
141+
120142
// SetConfigMapDefaultValue sets default value for specified key
121143
func SetConfigMapDefaultValue(oc *sync.Map, key string) {
122144
cm := DefaultOpConfig()
@@ -159,6 +181,9 @@ func DefaultOpConfig() *sync.Map {
159181
cfg.Store(OpConfigCMCertDuration, "2160h")
160182
cfg.Store(OpConfigLogLevel, logLevelInfo)
161183
cfg.Store(OpConfigReconcileIntervalMinimum, "5")
162-
cfg.Store(OpConfigReconcileIntervalPercentage, "100")
184+
cfg.Store(OpConfigReconcileIntervalPercentage, "50")
185+
cfg.Store(OpConfigReconcileIntervalFailureMaximum, "240")
186+
cfg.Store(OpConfigReconcileIntervalSuccessMaximum, "120")
187+
cfg.Store(OpConfigShowReconcileInterval, "false")
163188
return cfg
164189
}

common/types.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ type StatusCondition interface {
4141
GetType() StatusConditionType
4242
SetType(StatusConditionType)
4343

44-
GetUnchangedConditionCount() *int32
45-
SetUnchangedConditionCount(*int32)
46-
4744
SetConditionFields(string, string, corev1.ConditionStatus) StatusCondition
4845
}
4946

@@ -89,8 +86,9 @@ type BaseComponentStatus interface {
8986

9087
GetReconcileInterval() *int32
9188
SetReconcileInterval(*int32)
89+
UnsetReconcileInterval()
9290

93-
UnsetUnchangedConditionCount(conditionType StatusConditionType)
91+
GetLatestTransitionTime() *metav1.Time
9492
}
9593

9694
const (

config/crd/bases/rc.app.stacks_runtimecomponents.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8097,11 +8097,6 @@ spec:
80978097
type:
80988098
description: Defines the type of status condition.
80998099
type: string
8100-
unchangedConditionCount:
8101-
description: The count of the number of reconciles the condition
8102-
status type has not changed.
8103-
format: int32
8104-
type: integer
81058100
type: object
81068101
type: array
81078102
x-kubernetes-list-type: atomic

internal/controller/runtimecomponent_controller.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,26 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
132132
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
133133
}
134134

135+
if err = common.CheckValidValue(common.Config, common.OpConfigReconcileIntervalFailureMaximum, OperatorName); err != nil {
136+
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
137+
}
138+
139+
if err = common.CheckValidValue(common.Config, common.OpConfigReconcileIntervalSuccessMaximum, OperatorName); err != nil {
140+
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
141+
}
142+
143+
if instance.Status.Versions.Reconciled == "1.4.1" {
144+
common.UpdateReconcileIntervalPercentage(common.Config, OperatorName)
145+
err = r.CreateOrUpdate(configMap, instance, func() error {
146+
appstacksutils.UpdateConfigMap(configMap, common.OpConfigReconcileIntervalPercentage)
147+
return nil
148+
})
149+
if err != nil {
150+
reqLogger.Error(err, "Failed to reconcile ConfigMap")
151+
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
152+
}
153+
}
154+
135155
isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
136156
if err != nil {
137157
r.ManageError(err, common.StatusConditionTypeReconciled, instance)

internal/deploy/kubectl/runtime-component-crd.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8100,11 +8100,6 @@ spec:
81008100
type:
81018101
description: Defines the type of status condition.
81028102
type: string
8103-
unchangedConditionCount:
8104-
description: The count of the number of reconciles the condition
8105-
status type has not changed.
8106-
format: int32
8107-
type: integer
81088103
type: object
81098104
type: array
81108105
x-kubernetes-list-type: atomic

internal/deploy/kustomize/daily/base/runtime-component-crd.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8100,11 +8100,6 @@ spec:
81008100
type:
81018101
description: Defines the type of status condition.
81028102
type: string
8103-
unchangedConditionCount:
8104-
description: The count of the number of reconciles the condition
8105-
status type has not changed.
8106-
format: int32
8107-
type: integer
81088103
type: object
81098104
type: array
81108105
x-kubernetes-list-type: atomic

0 commit comments

Comments
 (0)