Skip to content

Commit ae49fab

Browse files
committed
update event reasons of podopslifecycle
1 parent 4544135 commit ae49fab

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

apis/apps/v1alpha1/well_known_vars.go

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ const (
2727
ProtectFinalizer = "finalizer.operating.kusionstack.io/protected"
2828
)
2929

30+
// well known event reasons
31+
const (
32+
PodDeletionEvent = "PodDeletion"
33+
ServiceReadyEvent = "ServiceReady"
34+
)
35+
3036
// well known variables
3137
const (
3238
PodOpsLifecyclePreCheckStage = "PreCheck"

pkg/controllers/poddeletion/lifecycle_adapter.go

-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,5 @@ func (a *PodDeleteOpsLifecycleAdapter) WhenBegin(obj client.Object) (bool, error
5252

5353
// WhenFinish will be executed when finish a lifecycle
5454
func (a *PodDeleteOpsLifecycleAdapter) WhenFinish(_ client.Object) (bool, error) {
55-
5655
return false, nil
5756
}

pkg/controllers/poddeletion/poddeletion_controller.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3030
"sigs.k8s.io/controller-runtime/pkg/source"
3131

32+
"kusionstack.io/operating/apis/apps/v1alpha1"
3233
appsv1alpha1 "kusionstack.io/operating/apis/apps/v1alpha1"
3334
"kusionstack.io/operating/pkg/controllers/collaset/pvccontrol"
3435
"kusionstack.io/operating/pkg/controllers/utils/expectations"
@@ -123,14 +124,16 @@ func (r *PodDeletionReconciler) Reconcile(ctx context.Context, req ctrl.Request)
123124
}
124125
}
125126

126-
// if Pod is allow to operate, delete it
127+
// if Pod is allowed to operate, delete it
127128
if _, allowed := podopslifecycle.AllowOps(OpsLifecycleAdapter, 0, instance); allowed {
128129
logger.Info("try to delete Pod with deletion indication")
129130
if err := r.Client.Delete(context.TODO(), instance); err != nil {
130131
return ctrl.Result{}, fmt.Errorf("fail to delete Pod %s with deletion indication: %s", req, err)
131132
} else {
133+
r.Recorder.Eventf(instance, corev1.EventTypeNormal, v1alpha1.PodDeletionEvent, "Deleted pod")
134+
132135
if err := activeExpectations.ExpectDelete(instance, expectations.Pod, instance.Name); err != nil {
133-
return ctrl.Result{}, fmt.Errorf("fail to expect Pod %s deleted: %s", req, err)
136+
return ctrl.Result{}, fmt.Errorf("fail to expect Pod %s to be deleted: %s", req, err)
134137
}
135138
}
136139
// if this pod in replaced update, delete pvcs

pkg/controllers/podopslifecycle/podopslifecycle_controller.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,23 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
126126
return reconcile.Result{}, err
127127
}
128128

129-
// If all lifecycle is finished, or the is no lifecycle begined
129+
// All lifecycles are finished, or no lifecycle begined
130130
if len(idToLabelsMap) == 0 {
131131
updated, err := r.addServiceAvailable(pod)
132-
if updated {
133-
r.Recorder.Eventf(pod, corev1.EventTypeNormal, "ServiceAvailable", "Label pod as service available, error: %v", err)
132+
if err != nil {
134133
return reconcile.Result{}, err
135134
}
135+
if updated {
136+
return reconcile.Result{}, nil
137+
}
136138

137139
updated, err = r.updateServiceReadiness(ctx, pod, true)
138-
if updated {
139-
r.Recorder.Eventf(pod, corev1.EventTypeNormal, "ReadinessGate", "Set service ready readiness gate to true, error: %v", err)
140+
if err != nil {
140141
return reconcile.Result{}, err
141142
}
143+
if updated {
144+
return reconcile.Result{}, nil
145+
}
142146
}
143147

144148
// Get the state of pod managed by TransitionRule
@@ -181,7 +185,6 @@ func (r *ReconcilePodOpsLifecycle) Reconcile(ctx context.Context, request reconc
181185
return reconcile.Result{}, err // Only need set once
182186
}
183187
if updated {
184-
r.Recorder.Eventf(pod, corev1.EventTypeNormal, "ReadinessGate", "Set service ready readiness gate to %v", v)
185188
return reconcile.Result{}, nil
186189
}
187190
}
@@ -325,6 +328,9 @@ func (r *ReconcilePodOpsLifecycle) updateServiceReadiness(ctx context.Context, p
325328

326329
return false, err
327330
}
331+
332+
r.Recorder.Eventf(pod, corev1.EventTypeNormal, v1alpha1.ServiceReadyEvent, "Set ReadinessGate service-ready to %v", isReady)
333+
328334
return true, nil
329335
}
330336

@@ -436,7 +442,6 @@ func (r *ReconcilePodOpsLifecycle) addLabels(ctx context.Context, pod *corev1.Po
436442
r.Logger.Error(err, "failed to update pod with labels", "pod", utils.ObjectKeyString(pod), "labels", labels)
437443
r.expectation.DeleteExpectations(key)
438444
}
439-
r.Recorder.Eventf(pod, corev1.EventTypeNormal, "UpdatePod", "Succeed to update labels: %v", labels)
440445

441446
return err
442447
}

0 commit comments

Comments
 (0)