Skip to content

Commit

Permalink
patch - saving external IDs immediately (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
OrNovo authored Aug 1, 2023
1 parent 5d08b66 commit 28ff2cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apis/coralogix/v1alpha1/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 10 additions & 1 deletion controllers/alphacontrollers/alert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions controllers/alphacontrollers/rulegroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 28ff2cd

Please sign in to comment.