@@ -10,7 +10,6 @@ import (
10
10
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11
11
rbacclientv1 "k8s.io/client-go/kubernetes/typed/rbac/v1"
12
12
"k8s.io/klog/v2"
13
- "k8s.io/utils/ptr"
14
13
)
15
14
16
15
// ApplyClusterRoleBindingv1 applies the required clusterrolebinding to the cluster.
@@ -29,13 +28,20 @@ func ApplyClusterRoleBindingv1(ctx context.Context, client rbacclientv1.ClusterR
29
28
return nil , false , nil
30
29
}
31
30
32
- modified := ptr .To (false )
33
- resourcemerge .EnsureClusterRoleBinding (modified , existing , * required )
34
- if ! * modified {
31
+ var original rbacv1.ClusterRoleBinding
32
+ existing .DeepCopyInto (& original )
33
+
34
+ modified := resourcemerge .EnsureClusterRoleBinding (existing , * required )
35
+ if ! modified {
35
36
return existing , false , nil
36
37
}
38
+
37
39
if reconciling {
38
- klog .V (2 ).Infof ("Updating ClusterRoleBinding %s due to diff: %v" , required .Name , cmp .Diff (existing , required ))
40
+ if diff := cmp .Diff (& original , existing ); diff != "" {
41
+ klog .V (2 ).Infof ("Updating ClusterRoleBinding %s due to diff: %v" , required .Name , diff )
42
+ } else {
43
+ klog .V (2 ).Infof ("Updating ClusterRoleBinding %s with empty diff: possible hotloop after wrong comparison" , required .Name )
44
+ }
39
45
}
40
46
41
47
actual , err := client .ClusterRoleBindings ().Update (ctx , existing , metav1.UpdateOptions {})
@@ -58,13 +64,20 @@ func ApplyClusterRolev1(ctx context.Context, client rbacclientv1.ClusterRolesGet
58
64
return nil , false , nil
59
65
}
60
66
61
- modified := ptr .To (false )
62
- resourcemerge .EnsureClusterRole (modified , existing , * required )
63
- if ! * modified {
67
+ var original rbacv1.ClusterRole
68
+ existing .DeepCopyInto (& original )
69
+
70
+ modified := resourcemerge .EnsureClusterRole (existing , * required )
71
+ if ! modified {
64
72
return existing , false , nil
65
73
}
74
+
66
75
if reconciling {
67
- klog .V (2 ).Infof ("Updating ClusterRole %s due to diff: %v" , required .Name , cmp .Diff (existing , required ))
76
+ if diff := cmp .Diff (& original , existing ); diff != "" {
77
+ klog .V (2 ).Infof ("Updating ClusterRole %s due to diff: %v" , required .Name , diff )
78
+ } else {
79
+ klog .V (2 ).Infof ("Updating ClusterRole %s with empty diff: possible hotloop after wrong comparison" , required .Name )
80
+ }
68
81
}
69
82
70
83
actual , err := client .ClusterRoles ().Update (ctx , existing , metav1.UpdateOptions {})
@@ -87,13 +100,20 @@ func ApplyRoleBindingv1(ctx context.Context, client rbacclientv1.RoleBindingsGet
87
100
return nil , false , nil
88
101
}
89
102
90
- modified := ptr .To (false )
91
- resourcemerge .EnsureRoleBinding (modified , existing , * required )
92
- if ! * modified {
103
+ var original rbacv1.RoleBinding
104
+ existing .DeepCopyInto (& original )
105
+
106
+ modified := resourcemerge .EnsureRoleBinding (existing , * required )
107
+ if ! modified {
93
108
return existing , false , nil
94
109
}
110
+
95
111
if reconciling {
96
- klog .V (2 ).Infof ("Updating RoleBinding %s/%s due to diff: %v" , required .Namespace , required .Name , cmp .Diff (existing , required ))
112
+ if diff := cmp .Diff (& original , existing ); diff != "" {
113
+ klog .V (2 ).Infof ("Updating RoleBinding %s due to diff: %v" , required .Name , diff )
114
+ } else {
115
+ klog .V (2 ).Infof ("Updating RoleBinding %s with empty diff: possible hotloop after wrong comparison" , required .Name )
116
+ }
97
117
}
98
118
99
119
actual , err := client .RoleBindings (required .Namespace ).Update (ctx , existing , metav1.UpdateOptions {})
@@ -116,13 +136,20 @@ func ApplyRolev1(ctx context.Context, client rbacclientv1.RolesGetter, required
116
136
return nil , false , nil
117
137
}
118
138
119
- modified := ptr .To (false )
120
- resourcemerge .EnsureRole (modified , existing , * required )
121
- if ! * modified {
139
+ var original rbacv1.Role
140
+ original .DeepCopyInto (& original )
141
+
142
+ modified := resourcemerge .EnsureRole (existing , * required )
143
+ if ! modified {
122
144
return existing , false , nil
123
145
}
146
+
124
147
if reconciling {
125
- klog .V (2 ).Infof ("Updating Role %s/%s due to diff: %v" , required .Namespace , required .Name , cmp .Diff (existing , required ))
148
+ if diff := cmp .Diff (& original , existing ); diff != "" {
149
+ klog .V (2 ).Infof ("Updating Role %s due to diff: %v" , required .Name , diff )
150
+ } else {
151
+ klog .V (2 ).Infof ("Updating Role %s with empty diff: possible hotloop after wrong comparison" , required .Name )
152
+ }
126
153
}
127
154
128
155
actual , err := client .Roles (required .Namespace ).Update (ctx , existing , metav1.UpdateOptions {})
0 commit comments