Skip to content

Commit

Permalink
fix: delete lastUpdateTime in status to fix resourceVersion frequent …
Browse files Browse the repository at this point in the history
…updates

Signed-off-by: Rory Z <[email protected]>
  • Loading branch information
Rory-Z committed Sep 20, 2023
1 parent 0b7ba61 commit 4fe61de
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 38 deletions.
4 changes: 2 additions & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Release Note 🍻

EMQX Operator 1.2.7-ecp.3 is released.
EMQX Operator 1.2.7-ecp.4 is released.

### Supported EMQX version

Expand All @@ -10,4 +10,4 @@ EMQX Operator 1.2.7-ecp.3 is released.

### Fixes 🛠

- Fixed the bug where the service port disappears when a node in the EMQX cluster crashes.
- Fixed the bug where the `resourceVersion` of the EMQX customer resource always changes.
28 changes: 7 additions & 21 deletions apis/apps/v1beta3/status_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1beta3

import (
"sort"
"time"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -17,11 +16,8 @@ type Condition struct {
Type ConditionType `json:"type"`
// Status of the condition, one of True, False, Unknown.
Status corev1.ConditionStatus `json:"status"`
// The last time this condition was updated.
LastUpdateTime string `json:"lastUpdateTime,omitempty"`
LastUpdateAt metav1.Time `json:"-"`
// Last time the condition transitioned from one status to another.
LastTransitionTime string `json:"lastTransitionTime,omitempty"`
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// The reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
// A human readable message indicating details about the transition.
Expand All @@ -36,7 +32,7 @@ const (
ConditionRunning ConditionType = "Running"
)

//+kubebuilder:object:generate=false
// +kubebuilder:object:generate=false
type EmqxStatus interface {
IsRunning() bool
IsPluginInitialized() bool
Expand Down Expand Up @@ -69,14 +65,10 @@ type Status struct {
}

func NewCondition(condType ConditionType, status corev1.ConditionStatus, reason, message string) *Condition {
now := metav1.Now()
nowString := now.Format(time.RFC3339)
return &Condition{
Type: condType,
Status: status,
LastUpdateTime: nowString,
LastUpdateAt: now,
LastTransitionTime: nowString,
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
}
Expand Down Expand Up @@ -109,17 +101,11 @@ func (s *Status) GetConditions() []Condition {

func (s *Status) SetCondition(c Condition) {
pos, cp := getCondition(s, c.Type)
if cp != nil &&
cp.Status == c.Status && cp.Reason == c.Reason && cp.Message == c.Message {
now := metav1.Now()
nowString := now.Format(time.RFC3339)
s.Conditions[pos].LastUpdateAt = now
s.Conditions[pos].LastUpdateTime = nowString
s.sortConditions(s.Conditions)
return
}

if cp != nil {
if cp.Status == c.Status && cp.Reason == c.Reason && cp.Message == c.Message {
return
}
s.Conditions[pos] = c
} else {
s.Conditions = append(s.Conditions, c)
Expand All @@ -138,7 +124,7 @@ func (s *Status) ClearCondition(t ConditionType) {

func (s *Status) sortConditions(conditions []Condition) {
sort.Slice(conditions, func(i, j int) bool {
return s.Conditions[j].LastUpdateAt.Before(&s.Conditions[i].LastUpdateAt)
return s.Conditions[j].LastTransitionTime.Before(&s.Conditions[i].LastTransitionTime)
})
}

Expand Down
2 changes: 1 addition & 1 deletion apis/apps/v1beta3/zz_generated.deepcopy.go

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

4 changes: 1 addition & 3 deletions config/crd/bases/apps.emqx.io_emqxbrokers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6329,9 +6329,7 @@ spec:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
Expand Down
4 changes: 1 addition & 3 deletions config/crd/bases/apps.emqx.io_emqxenterprises.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6355,9 +6355,7 @@ spec:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
Expand Down
4 changes: 2 additions & 2 deletions deploy/charts/emqx-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.11-ecp.2
version: 1.0.11-ecp.4

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
appVersion: 1.2.7-ecp.3
appVersion: 1.2.7-ecp.4
4 changes: 1 addition & 3 deletions deploy/charts/emqx-operator/templates/crd-emqx-brokers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6341,9 +6341,7 @@ spec:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6367,9 +6367,7 @@ spec:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another.
type: string
lastUpdateTime:
description: The last time this condition was updated.
format: date-time
type: string
message:
description: A human readable message indicating details about
Expand Down

0 comments on commit 4fe61de

Please sign in to comment.