Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 18 additions & 23 deletions api/v1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,6 @@ type StatusCondition struct {
Message string `json:"message,omitempty"`
Status corev1.ConditionStatus `json:"status,omitempty"`
Type StatusConditionType `json:"type,omitempty"`

// The count of the number of reconciles the condition status type has not changed.
UnchangedConditionCount *int32 `json:"unchangedConditionCount,omitempty"`
}

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

// GetLatestTransitionTime returns latest time of status change
func (s *RuntimeComponentStatus) GetLatestTransitionTime() *metav1.Time {
var latestTime *metav1.Time
for i := range s.Conditions {
t := s.Conditions[i].GetLastTransitionTime()
// If latestTime is not set or condition's time is before latestTime
if latestTime == nil || latestTime.Before(t) {
latestTime = t
}
}
return latestTime
}

// GetMessage returns condition's message
func (c *StatusCondition) GetMessage() string {
return c.Message
Expand Down Expand Up @@ -1188,15 +1198,14 @@ func (s *RuntimeComponentStatus) SetCondition(c common.StatusCondition) {
}
}

if condition.GetStatus() != c.GetStatus() || condition.GetMessage() != c.GetMessage() {
if condition.GetStatus() != c.GetStatus() || condition.GetMessage() != c.GetMessage() || condition.GetReason() != c.GetReason() {
condition.SetLastTransitionTime(&metav1.Time{Time: time.Now()})
}

condition.SetReason(c.GetReason())
condition.SetMessage(c.GetMessage())
condition.SetStatus(c.GetStatus())
condition.SetType(c.GetType())
condition.SetUnchangedConditionCount(c.GetUnchangedConditionCount())
if !found {
s.Conditions = append(s.Conditions, *condition)
}
Expand Down Expand Up @@ -1237,31 +1246,17 @@ func (s *RuntimeComponentStatus) SetReconcileInterval(interval *int32) {
s.ReconcileInterval = interval
}

func (s *RuntimeComponentStatus) UnsetReconcileInterval() {
s.ReconcileInterval = nil
}

func (s *RuntimeComponentStatus) SetReference(name string, value string) {
if s.References == nil {
s.References = make(common.StatusReferences)
}
s.References[name] = value
}

func (sc *StatusCondition) GetUnchangedConditionCount() *int32 {
return sc.UnchangedConditionCount
}

func (sc *StatusCondition) SetUnchangedConditionCount(count *int32) {
sc.UnchangedConditionCount = count
}

func (s *RuntimeComponentStatus) UnsetUnchangedConditionCount(conditionType common.StatusConditionType) {
// Reset unchanged count for other status conditions
var emptyCount *int32
for i := range s.Conditions {
if s.Conditions[i].GetType() != conditionType && s.Conditions[i].GetUnchangedConditionCount() != nil {
s.Conditions[i].SetUnchangedConditionCount(emptyCount)
}
}
}

func convertToCommonStatusConditionType(c StatusConditionType) common.StatusConditionType {
switch c {
case StatusConditionTypeReconciled:
Expand Down
5 changes: 0 additions & 5 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions api/v1beta2/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,7 @@ func (s *RuntimeComponentStatus) SetReconcileInterval(interval *int32) {
return
}

func (s *StatusCondition) GetUnchangedConditionCount() *int32 {
return nil
}

func (s *StatusCondition) SetUnchangedConditionCount(count *int32) {
return
}

func (s *RuntimeComponentStatus) UnsetUnchangedConditionCount(conditionType common.StatusConditionType) {
func (s *RuntimeComponentStatus) UnsetReconcileInterval() {
return
}

Expand Down Expand Up @@ -917,6 +909,10 @@ func (c *StatusCondition) SetLastTransitionTime(t *metav1.Time) {
c.LastTransitionTime = t
}

func (s *RuntimeComponentStatus) GetLatestTransitionTime() *metav1.Time {
return nil
}

// GetMessage return condition's message
func (c *StatusCondition) GetMessage() string {
return c.Message
Expand Down
5 changes: 0 additions & 5 deletions bundle/manifests/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8101,11 +8101,6 @@ spec:
type:
description: Defines the type of status condition.
type: string
unchangedConditionCount:
description: The count of the number of reconciles the condition
status type has not changed.
format: int32
type: integer
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
35 changes: 30 additions & 5 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ const (
// 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
OpConfigReconcileIntervalPercentage = "reconcileIntervalIncreasePercentage"

// OpConfigReconcileIntervalFailureMaximum default max reconcile interval for repeated failures
OpConfigReconcileIntervalFailureMaximum = "reconcileIntervalFailureMaximum"

// OpConfigReconcileIntervalSuccessMaximum default max reconcile interval for repeated successful reconciled and application ready status
OpConfigReconcileIntervalSuccessMaximum = "reconcileIntervalSuccessMaximum"

// OpConfigShowReconcileInterval default whether reconcile interval will be visible in the instance's status field
OpConfigShowReconcileInterval = "showReconcileInterval"
)

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

intValue, err := strconv.Atoi(value)
floatValue, err := strconv.ParseFloat(value, 64)
if err != nil {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " has an invalid syntax, error: " + err.Error())
} else if key == OpConfigReconcileIntervalMinimum && intValue <= 0 {
} else if key == OpConfigReconcileIntervalMinimum && floatValue <= 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 {
} else if key == OpConfigReconcileIntervalPercentage && floatValue < 0 {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than or equal to 0.")
} else if key == OpConfigReconcileIntervalFailureMaximum && floatValue <= 0 {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
} else if key == OpConfigReconcileIntervalSuccessMaximum && floatValue <= 0 {
SetConfigMapDefaultValue(oc, key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
}

return nil
}

func UpdateReconcileIntervalPercentage(oc *sync.Map, OperatorName string) {
intervalIncreasePercentage, _ := strconv.ParseFloat(LoadFromConfig(oc, OpConfigReconcileIntervalPercentage), 64)
if intervalIncreasePercentage == 100 {
intervalIncreasePercentageStr := strconv.FormatFloat(50, 'f', -1, 64)
oc.Store(OpConfigReconcileIntervalPercentage, intervalIncreasePercentageStr)
}
}

// SetConfigMapDefaultValue sets default value for specified key
func SetConfigMapDefaultValue(oc *sync.Map, key string) {
cm := DefaultOpConfig()
Expand Down Expand Up @@ -159,6 +181,9 @@ func DefaultOpConfig() *sync.Map {
cfg.Store(OpConfigCMCertDuration, "2160h")
cfg.Store(OpConfigLogLevel, logLevelInfo)
cfg.Store(OpConfigReconcileIntervalMinimum, "5")
cfg.Store(OpConfigReconcileIntervalPercentage, "100")
cfg.Store(OpConfigReconcileIntervalPercentage, "50")
cfg.Store(OpConfigReconcileIntervalFailureMaximum, "240")
cfg.Store(OpConfigReconcileIntervalSuccessMaximum, "120")
cfg.Store(OpConfigShowReconcileInterval, "false")
return cfg
}
6 changes: 2 additions & 4 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ type StatusCondition interface {
GetType() StatusConditionType
SetType(StatusConditionType)

GetUnchangedConditionCount() *int32
SetUnchangedConditionCount(*int32)

SetConditionFields(string, string, corev1.ConditionStatus) StatusCondition
}

Expand Down Expand Up @@ -89,8 +86,9 @@ type BaseComponentStatus interface {

GetReconcileInterval() *int32
SetReconcileInterval(*int32)
UnsetReconcileInterval()

UnsetUnchangedConditionCount(conditionType StatusConditionType)
GetLatestTransitionTime() *metav1.Time
}

const (
Expand Down
5 changes: 0 additions & 5 deletions config/crd/bases/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8097,11 +8097,6 @@ spec:
type:
description: Defines the type of status condition.
type: string
unchangedConditionCount:
description: The count of the number of reconciles the condition
status type has not changed.
format: int32
type: integer
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
20 changes: 20 additions & 0 deletions internal/controller/runtimecomponent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,26 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
}

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

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

if instance.Status.Versions.Reconciled == "1.4.1" {
common.UpdateReconcileIntervalPercentage(common.Config, OperatorName)
err = r.CreateOrUpdate(configMap, instance, func() error {
appstacksutils.UpdateConfigMap(configMap, common.OpConfigReconcileIntervalPercentage)
return nil
})
if err != nil {
reqLogger.Error(err, "Failed to reconcile ConfigMap")
return r.ManageError(err, common.StatusConditionTypeReconciled, instance)
}
}

isKnativeSupported, err := r.IsGroupVersionSupported(servingv1.SchemeGroupVersion.String(), "Service")
if err != nil {
r.ManageError(err, common.StatusConditionTypeReconciled, instance)
Expand Down
5 changes: 0 additions & 5 deletions internal/deploy/kubectl/runtime-component-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8100,11 +8100,6 @@ spec:
type:
description: Defines the type of status condition.
type: string
unchangedConditionCount:
description: The count of the number of reconciles the condition
status type has not changed.
format: int32
type: integer
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8100,11 +8100,6 @@ spec:
type:
description: Defines the type of status condition.
type: string
unchangedConditionCount:
description: The count of the number of reconciles the condition
status type has not changed.
format: int32
type: integer
type: object
type: array
x-kubernetes-list-type: atomic
Expand Down
Loading