Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch - saving external IDs immediately #38

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading