diff --git a/apis/coralogix/v1alpha1/alert_types.go b/apis/coralogix/v1alpha1/alert_types.go index 616b3a2..1316810 100644 --- a/apis/coralogix/v1alpha1/alert_types.go +++ b/apis/coralogix/v1alpha1/alert_types.go @@ -1660,12 +1660,12 @@ func (in *AlertType) DeepEqual(actualAlert AlertType) (bool, utils.Diff) { } if tracing := in.Tracing; tracing != nil { - if actulTracing := actualAlert.Tracing; actulTracing == nil { + if actualTracing := actualAlert.Tracing; actualTracing == nil { return false, utils.Diff{ Name: "Type", Actual: "Tracing", } - } else if equal, diff := tracing.DeepEqual(*actulTracing); !equal { + } else if equal, diff := tracing.DeepEqual(*actualTracing); !equal { return false, utils.Diff{ Name: fmt.Sprintf("Tracing.%s", diff.Name), Desired: diff.Desired, diff --git a/controllers/alphacontrollers/alert_controller.go b/controllers/alphacontrollers/alert_controller.go index cb92bfd..4ee7336 100644 --- a/controllers/alphacontrollers/alert_controller.go +++ b/controllers/alphacontrollers/alert_controller.go @@ -183,10 +183,19 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl if createAlertResp, err := alertsClient.CreateAlert(ctx, createAlertReq); err == nil { jstr, _ = jsm.MarshalToString(createAlertResp) log.V(1).Info("Alert was created", "alert", jstr) + + //To avoid a situation of the operator falling between the creation of the alert in coralogix and being saved in the cluster (something that would cause it to be created again and again), its id will be saved ASAP. + id := createAlertResp.GetAlert().GetId().GetValue() + alertCRD.Status = coralogixv1alpha1.AlertStatus{ID: &id} + if err := r.Status().Update(ctx, alertCRD); err != nil { + log.Error(err, "Error on updating alert status", "Name", alertCRD.Name, "Namespace", alertCRD.Namespace) + return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err + } + actualState, flattenErr = flattenAlert(ctx, createAlertResp.GetAlert(), alertCRD.Spec) alertCRD.Status = *actualState if err := r.Status().Update(ctx, alertCRD); err != nil { - log.Error(err, "Error on updating alert", "Name", alertCRD.Name, "Namespace", alertCRD.Namespace) + log.Error(err, "Error on updating alert status", "Name", alertCRD.Name, "Namespace", alertCRD.Namespace) return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err } return ctrl.Result{RequeueAfter: defaultRequeuePeriod}, nil diff --git a/controllers/alphacontrollers/recordingrulegroupset_controller.go b/controllers/alphacontrollers/recordingrulegroupset_controller.go index b5c038f..e8a6a3a 100644 --- a/controllers/alphacontrollers/recordingrulegroupset_controller.go +++ b/controllers/alphacontrollers/recordingrulegroupset_controller.go @@ -144,6 +144,15 @@ func (r *RecordingRuleGroupSetReconciler) Reconcile(ctx context.Context, req ctr if createRRGResp, err := rRGClient.CreateRecordingRuleGroupSet(ctx, createRuleGroupReq); err == nil { jstr, _ := jsm.MarshalToString(createRRGResp) log.V(1).Info("RecordingRuleGroupSet was updated", "RecordingRuleGroupSet", jstr) + + //To avoid a situation of the operator falling between the creation of the ruleGroup in coralogix and being saved in the cluster (something that would cause it to be created again and again), its id will be saved ASAP. + id := createRRGResp.Id + ruleGroupSetCRD.Status = coralogixv1alpha1.RecordingRuleGroupSetStatus{ID: &id} + if err := r.Status().Update(ctx, ruleGroupSetCRD); err != nil { + log.Error(err, "Error on updating RecordingRuleGroupSet status", "Name", ruleGroupSetCRD.Name, "Namespace", ruleGroupSetCRD.Namespace) + return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err + } + getRuleGroupReq := &rrg.FetchRuleGroupSet{Id: createRRGResp.Id} var getRRGResp *rrg.OutRuleGroupSet if getRRGResp, err = rRGClient.GetRecordingRuleGroupSet(ctx, getRuleGroupReq); err != nil || ruleGroupSetCRD == nil { diff --git a/controllers/alphacontrollers/rulegroup_controller.go b/controllers/alphacontrollers/rulegroup_controller.go index 04fa5a0..2a3b3c1 100644 --- a/controllers/alphacontrollers/rulegroup_controller.go +++ b/controllers/alphacontrollers/rulegroup_controller.go @@ -144,6 +144,15 @@ func (r *RuleGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( if createRuleGroupResp, err := rulesGroupsClient.CreateRuleGroup(ctx, createRuleGroupReq); err == nil { jstr, _ := jsm.MarshalToString(createRuleGroupResp) log.V(1).Info("Rule-Group was updated", "ruleGroup", jstr) + + //To avoid a situation of the operator falling between the creation of the ruleGroup in coralogix and being saved in the cluster (something that would cause it to be created again and again), its id will be saved ASAP. + id := createRuleGroupResp.GetRuleGroup().GetId().GetValue() + ruleGroupCRD.Status = coralogixv1alpha1.RuleGroupStatus{ID: &id} + if err := r.Status().Update(ctx, ruleGroupCRD); err != nil { + log.Error(err, "Error on updating RecordingRuleGroupSet status", "Name", ruleGroupCRD.Name, "Namespace", ruleGroupCRD.Namespace) + return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err + } + ruleGroupCRD.Status = *flattenRuleGroup(createRuleGroupResp.GetRuleGroup()) if err := r.Status().Update(ctx, ruleGroupCRD); err != nil { log.V(1).Error(err, "updating crd")