Skip to content

Commit e91b010

Browse files
authored
fix(reconcile): fixing the reconcile logs and events (#428)
Signed-off-by: Shubham Chaudhary <[email protected]> Signed-off-by: Shubham Chaudhary <[email protected]>
1 parent 9efec74 commit e91b010

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

controllers/chaosengine_controller.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ func engineRunnerPod(runnerPod *podEngineRunner) error {
266266
if err := runnerPod.r.Client.Get(context.TODO(), types.NamespacedName{Name: runnerPod.engineRunner.Name, Namespace: runnerPod.engineRunner.Namespace}, runnerPod.pod); err != nil && k8serrors.IsNotFound(err) {
267267
runnerPod.reqLogger.Info("Creating a new engineRunner Pod", "Pod.Namespace", runnerPod.engineRunner.Namespace, "Pod.Name", runnerPod.engineRunner.Name)
268268
if err = runnerPod.r.Client.Create(context.TODO(), runnerPod.engineRunner); err != nil {
269+
if k8serrors.IsAlreadyExists(err) {
270+
runnerPod.reqLogger.Info("Skip reconcile: engineRunner Pod already exists", "Pod.Namespace", runnerPod.pod.Namespace, "Pod.Name", runnerPod.pod.Name)
271+
return nil
272+
}
269273
return err
270274
}
271275

@@ -595,7 +599,7 @@ func (r *ChaosEngineReconciler) initEngine(engine *chaosTypes.EngineInfo) error
595599

596600
// reconcileForCreationAndRunning reconciles for Chaos execution of Chaos Engine
597601
func (r *ChaosEngineReconciler) reconcileForCreationAndRunning(engine *chaosTypes.EngineInfo, reqLogger logr.Logger) (reconcile.Result, error) {
598-
if err := r.validateAnnontatedApplication(engine); err != nil {
602+
if err := r.validateAnnotatedApplication(engine); err != nil {
599603
if stopEngineWithAnnotationErrorMessage := r.updateEngineState(engine, litmuschaosv1alpha1.EngineStateStop); stopEngineWithAnnotationErrorMessage != nil {
600604
r.Recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "(chaos stop) Unable to update chaosengine")
601605
return reconcile.Result{}, fmt.Errorf("unable to Update Engine State: %v", err)
@@ -611,6 +615,9 @@ func (r *ChaosEngineReconciler) reconcileForCreationAndRunning(engine *chaosType
611615

612616
isCompleted, err := r.checkRunnerContainerCompletedStatus(engine)
613617
if err != nil {
618+
if k8serrors.IsNotFound(err) {
619+
return reconcile.Result{Requeue: true}, nil
620+
}
614621
r.Recorder.Eventf(engine.Instance, corev1.EventTypeWarning, "ChaosResourcesOperationFailed", "(chaos running) Unable to check chaos status")
615622
return reconcile.Result{}, err
616623
}
@@ -643,7 +650,7 @@ func startReqLogger(request reconcile.Request) logr.Logger {
643650
return reqLogger
644651
}
645652

646-
func (r *ChaosEngineReconciler) validateAnnontatedApplication(engine *chaosTypes.EngineInfo) error {
653+
func (r *ChaosEngineReconciler) validateAnnotatedApplication(engine *chaosTypes.EngineInfo) error {
647654
// Get the image for runner pod from chaosengine spec,operator env or default values.
648655
setChaosResourceImage(engine)
649656

@@ -746,6 +753,9 @@ func (r *ChaosEngineReconciler) updateChaosResult(engine *chaosTypes.EngineInfo,
746753

747754
for _, result := range chaosresultList.Items {
748755
if result.Labels["chaosUID"] == string(engine.Instance.UID) {
756+
if len(result.ObjectMeta.Annotations) == 0 {
757+
return nil
758+
}
749759
targetsList, annotations := getChaosStatus(result)
750760
result.Status.History.Targets = targetsList
751761
result.ObjectMeta.Annotations = annotations

controllers/chaosengine_controller_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func TestValidateAnnontatedApplication(t *testing.T) {
423423
if err != nil {
424424
fmt.Printf("Unable to create engine: %v", err)
425425
}
426-
err = r.validateAnnontatedApplication(&mock.engine)
426+
err = r.validateAnnotatedApplication(&mock.engine)
427427
if mock.isErr && err == nil {
428428
t.Fatalf("Test %q failed: expected error not to be nil", name)
429429
}

0 commit comments

Comments
 (0)