Skip to content

Commit

Permalink
Update frequency of reconcile and parameterize the reconcile settings (
Browse files Browse the repository at this point in the history
  • Loading branch information
halim-lee authored Nov 18, 2024
1 parent e22638e commit 2340c1c
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 39 deletions.
33 changes: 33 additions & 0 deletions api/v1/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ type RuntimeComponentStatus struct {

// The generation identifier of this RuntimeComponent instance completely reconciled by the Operator.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// The reconciliation interval in seconds.
ReconcileInterval *int32 `json:"reconcileInterval,omitempty"`
}

// Defines possible status conditions.
Expand All @@ -440,6 +443,9 @@ 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 @@ -1190,6 +1196,7 @@ func (s *RuntimeComponentStatus) SetCondition(c common.StatusCondition) {
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 @@ -1222,13 +1229,39 @@ func (s *RuntimeComponentStatus) SetReferences(refs common.StatusReferences) {
s.References = refs
}

func (s *RuntimeComponentStatus) GetReconcileInterval() *int32 {
return s.ReconcileInterval
}

func (s *RuntimeComponentStatus) SetReconcileInterval(interval *int32) {
s.ReconcileInterval = interval
}

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
10 changes: 10 additions & 0 deletions api/v1/zz_generated.deepcopy.go

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

20 changes: 20 additions & 0 deletions api/v1beta2/runtimecomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@ func (in *RuntimeComponentStatus) SetReference(s string, s2 string) {
return
}

func (s *RuntimeComponentStatus) GetReconcileInterval() *int32 {
return nil
}

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) {
return
}

// Defines possible status conditions.
type StatusCondition struct {
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions bundle/manifests/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7829,6 +7829,11 @@ 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 All @@ -7855,6 +7860,10 @@ spec:
completely reconciled by the Operator.
format: int64
type: integer
reconcileInterval:
description: The reconciliation interval in seconds.
format: int32
type: integer
references:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ metadata:
categories: Application Runtime
certified: "true"
containerImage: icr.io/appcafe/runtime-component-operator:daily
createdAt: "2024-09-20T18:58:02Z"
createdAt: "2024-11-15T15:49:28Z"
description: Deploys any runtime component with dynamic and auto-tuning configuration
features.operators.openshift.io/disconnected: "true"
features.operators.openshift.io/fips-compliant: "true"
Expand Down
35 changes: 35 additions & 0 deletions common/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package common

import (
"errors"
"strconv"

corev1 "k8s.io/api/core/v1"
)

Expand All @@ -17,6 +20,13 @@ const (

// OpConfigCMCADuration default duration for cert-manager issued service certificate
OpConfigCMCertDuration = "certManagerCertDuration"

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

// 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"
)

// Config stores operator configuration
Expand All @@ -32,12 +42,37 @@ func (oc OpConfig) LoadFromConfigMap(cm *corev1.ConfigMap) {
oc[k] = v
}
}
func (oc OpConfig) CheckValidValue(key string, OperatorName string) error {
value := oc[key]

intValue, err := strconv.Atoi(value)
if err != nil {
oc.SetConfigMapDefaultValue(key)
return errors.New(key + " in ConfigMap: " + OperatorName + " has an invalid syntax, error: " + err.Error())
} else if key == OpConfigReconcileIntervalSeconds && intValue <= 0 {
oc.SetConfigMapDefaultValue(key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than 0.")
} else if key == OpConfigReconcileIntervalPercentage && intValue < 0 {
oc.SetConfigMapDefaultValue(key)
return errors.New(key + " in ConfigMap: " + OperatorName + " is set to " + value + ". It must be greater than or equal to 0.")
}

return nil
}

// SetConfigMapDefaultValue sets default value for specified key
func (oc OpConfig) SetConfigMapDefaultValue(key string) {
cm := DefaultOpConfig()
oc[key] = cm[key]
}

// DefaultOpConfig returns default configuration
func DefaultOpConfig() OpConfig {
cfg := OpConfig{}
cfg[OpConfigDefaultHostname] = ""
cfg[OpConfigCMCADuration] = "8766h"
cfg[OpConfigCMCertDuration] = "2160h"
cfg[OpConfigReconcileIntervalSeconds] = "15"
cfg[OpConfigReconcileIntervalPercentage] = "100"
return cfg
}
8 changes: 8 additions & 0 deletions common/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type StatusCondition interface {
GetType() StatusConditionType
SetType(StatusConditionType)

GetUnchangedConditionCount() *int32
SetUnchangedConditionCount(*int32)

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

Expand Down Expand Up @@ -83,6 +86,11 @@ type BaseComponentStatus interface {
GetReferences() StatusReferences
SetReferences(StatusReferences)
SetReference(string, string)

GetReconcileInterval() *int32
SetReconcileInterval(*int32)

UnsetUnchangedConditionCount(conditionType StatusConditionType)
}

const (
Expand Down
9 changes: 9 additions & 0 deletions config/crd/bases/rc.app.stacks_runtimecomponents.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7825,6 +7825,11 @@ 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 All @@ -7851,6 +7856,10 @@ spec:
completely reconciled by the Operator.
format: int64
type: integer
reconcileInterval:
description: The reconciliation interval in seconds.
format: int32
type: integer
references:
additionalProperties:
type: string
Expand Down
8 changes: 8 additions & 0 deletions internal/controller/runtimecomponent_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ func (r *RuntimeComponentReconciler) Reconcile(ctx context.Context, req ctrl.Req
return reconcile.Result{}, err
}

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

if err = common.Config.CheckValidValue(common.OpConfigReconcileIntervalPercentage, OperatorName); err != nil {
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
9 changes: 9 additions & 0 deletions internal/deploy/kubectl/runtime-component-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7828,6 +7828,11 @@ 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 All @@ -7854,6 +7859,10 @@ spec:
completely reconciled by the Operator.
format: int64
type: integer
reconcileInterval:
description: The reconciliation interval in seconds.
format: int32
type: integer
references:
additionalProperties:
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7828,6 +7828,11 @@ 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 All @@ -7854,6 +7859,10 @@ spec:
completely reconciled by the Operator.
format: int64
type: integer
reconcileInterval:
description: The reconciliation interval in seconds.
format: int32
type: integer
references:
additionalProperties:
type: string
Expand Down
Loading

0 comments on commit 2340c1c

Please sign in to comment.