@@ -42,6 +42,8 @@ import (
42
42
)
43
43
44
44
func (r * Reconciler ) reconcilePhase (_ context.Context , cluster * clusterv1.Cluster ) {
45
+ preReconcilePhase := cluster .Status .GetTypedPhase ()
46
+
45
47
if cluster .Status .Phase == "" {
46
48
cluster .Status .SetTypedPhase (clusterv1 .ClusterPhasePending )
47
49
}
@@ -61,6 +63,16 @@ func (r *Reconciler) reconcilePhase(_ context.Context, cluster *clusterv1.Cluste
61
63
if ! cluster .DeletionTimestamp .IsZero () {
62
64
cluster .Status .SetTypedPhase (clusterv1 .ClusterPhaseDeleting )
63
65
}
66
+
67
+ // Only record the event if the status has changed
68
+ if preReconcilePhase != cluster .Status .GetTypedPhase () {
69
+ // Failed clusters should get a Warning event
70
+ if cluster .Status .GetTypedPhase () == clusterv1 .ClusterPhaseFailed {
71
+ r .recorder .Eventf (cluster , corev1 .EventTypeWarning , string (cluster .Status .GetTypedPhase ()), "Cluster %s is %s: %s" , cluster .Name , string (cluster .Status .GetTypedPhase ()), pointer .StringDeref (cluster .Status .FailureMessage , "unknown" ))
72
+ } else {
73
+ r .recorder .Eventf (cluster , corev1 .EventTypeNormal , string (cluster .Status .GetTypedPhase ()), "Cluster %s is %s" , cluster .Name , string (cluster .Status .GetTypedPhase ()))
74
+ }
75
+ }
64
76
}
65
77
66
78
// reconcileExternal handles generic unstructured objects referenced by a Cluster.
@@ -163,11 +175,16 @@ func (r *Reconciler) reconcileInfrastructure(ctx context.Context, cluster *clust
163
175
}
164
176
165
177
// Determine if the infrastructure provider is ready.
178
+ preReconcileInfrastructureReady := cluster .Status .InfrastructureReady
166
179
ready , err := external .IsReady (infraConfig )
167
180
if err != nil {
168
181
return ctrl.Result {}, err
169
182
}
170
183
cluster .Status .InfrastructureReady = ready
184
+ // Only record the event if the status has changed
185
+ if preReconcileInfrastructureReady != cluster .Status .InfrastructureReady {
186
+ r .recorder .Eventf (cluster , corev1 .EventTypeNormal , "InfrastructureReady" , "Cluster %s InfrastructureReady is now %t" , cluster .Name , cluster .Status .InfrastructureReady )
187
+ }
171
188
172
189
// Report a summary of current status of the infrastructure object defined for this cluster.
173
190
conditions .SetMirror (cluster , clusterv1 .InfrastructureReadyCondition ,
@@ -225,12 +242,17 @@ func (r *Reconciler) reconcileControlPlane(ctx context.Context, cluster *cluster
225
242
return ctrl.Result {}, nil
226
243
}
227
244
245
+ preReconcileControlPlaneReady := cluster .Status .ControlPlaneReady
228
246
// Determine if the control plane provider is ready.
229
247
ready , err := external .IsReady (controlPlaneConfig )
230
248
if err != nil {
231
249
return ctrl.Result {}, err
232
250
}
233
251
cluster .Status .ControlPlaneReady = ready
252
+ // Only record the event if the status has changed
253
+ if preReconcileControlPlaneReady != cluster .Status .ControlPlaneReady {
254
+ r .recorder .Eventf (cluster , corev1 .EventTypeNormal , "ControlPlaneReady" , "Cluster %s ControlPlaneReady is now %t" , cluster .Name , cluster .Status .ControlPlaneReady )
255
+ }
234
256
235
257
// Report a summary of current status of the control plane object defined for this cluster.
236
258
conditions .SetMirror (cluster , clusterv1 .ControlPlaneReadyCondition ,
0 commit comments