Skip to content

Commit 40c4a0d

Browse files
authored
refactor: update status if not equal (#900)
Signed-off-by: drivebyer <yang.wu@daocloud.io>
1 parent f5028bd commit 40c4a0d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

k8sutils/status.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ package k8sutils
22

33
import (
44
"context"
5+
"reflect"
56

6-
status "github.com/OT-CONTAINER-KIT/redis-operator/api/status"
7+
"github.com/OT-CONTAINER-KIT/redis-operator/api/status"
78
redisv1beta2 "github.com/OT-CONTAINER-KIT/redis-operator/api/v1beta2"
89
"github.com/go-logr/logr"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -20,13 +21,18 @@ func statusLogger(namespace string, name string) logr.Logger {
2021
}
2122

2223
// UpdateRedisClusterStatus will update the status of the RedisCluster
23-
func UpdateRedisClusterStatus(cr *redisv1beta2.RedisCluster, status status.RedisClusterState, resaon string, readyLeaderReplicas, readyFollowerReplicas int32, dcl dynamic.Interface) error {
24+
func UpdateRedisClusterStatus(cr *redisv1beta2.RedisCluster, state status.RedisClusterState, reason string, readyLeaderReplicas, readyFollowerReplicas int32, dcl dynamic.Interface) error {
2425
logger := statusLogger(cr.Namespace, cr.Name)
25-
cr.Status.State = status
26-
cr.Status.Reason = resaon
27-
cr.Status.ReadyLeaderReplicas = readyLeaderReplicas
28-
cr.Status.ReadyFollowerReplicas = readyFollowerReplicas
29-
26+
newStatus := redisv1beta2.RedisClusterStatus{
27+
State: state,
28+
Reason: reason,
29+
ReadyLeaderReplicas: readyLeaderReplicas,
30+
ReadyFollowerReplicas: readyFollowerReplicas,
31+
}
32+
if reflect.DeepEqual(cr.Status, newStatus) {
33+
return nil
34+
}
35+
cr.Status = newStatus
3036
gvr := schema.GroupVersionResource{
3137
Group: "redis.redis.opstreelabs.in",
3238
Version: "v1beta2",

0 commit comments

Comments
 (0)