Skip to content

Commit

Permalink
[CHORE] recreating alert if not found in remote (#111) (#115)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas Takashi <nicolas.takashi@coralogix.com>
  • Loading branch information
nicolastakashi authored Jul 29, 2024
1 parent d102285 commit d832ea1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
18 changes: 8 additions & 10 deletions controllers/alphacontrollers/alert_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ type AlertReconciler struct {

func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
var (
resultError ctrl.Result = ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}
resultOk ctrl.Result = ctrl.Result{RequeueAfter: defaultRequeuePeriod}
err error
err error
)

log := log.FromContext(ctx).WithValues(
Expand All @@ -88,34 +86,34 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
// Return and don't requeue
return ctrl.Result{}, nil
}
return resultError, err
return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err
}

if ptr.Deref(alert.Status.ID, "") == "" {
err = r.create(ctx, log, alert)
if err != nil {
log.Error(err, "Error on creating alert")
return resultError, err
return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err
}
return resultOk, nil
return ctrl.Result{}, nil
}

if !alert.ObjectMeta.DeletionTimestamp.IsZero() {
err = r.delete(ctx, log, alert)
if err != nil {
log.Error(err, "Error on deleting alert")
return resultError, err
return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err
}
return resultOk, nil
return ctrl.Result{}, nil
}

err = r.update(ctx, log, alert)
if err != nil {
log.Error(err, "Error on updating alert")
return resultError, err
return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err
}

return resultOk, nil
return ctrl.Result{}, nil
}

func (r *AlertReconciler) update(ctx context.Context,
Expand Down
3 changes: 0 additions & 3 deletions controllers/alphacontrollers/alert_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ func TestAlertCreation(t *testing.T) {
assert.Equal(t, defaultErrRequeuePeriod, result.RequeueAfter)
} else {
assert.NoError(t, err)
assert.Equal(t, defaultRequeuePeriod, result.RequeueAfter)
}
})
}
Expand Down Expand Up @@ -504,7 +503,6 @@ func TestAlertUpdate(t *testing.T) {
assert.Equal(t, defaultErrRequeuePeriod, result.RequeueAfter)
} else {
assert.NoError(t, err)
assert.Equal(t, defaultRequeuePeriod, result.RequeueAfter)
}
})
}
Expand Down Expand Up @@ -715,7 +713,6 @@ func TestAlertDelete(t *testing.T) {
assert.Equal(t, defaultErrRequeuePeriod, result.RequeueAfter)
} else {
assert.NoError(t, err)
assert.Equal(t, defaultRequeuePeriod, result.RequeueAfter)
}
})
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/alphacontrollers/rulegroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (r *RuleGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
if err := r.Status().Update(ctx, ruleGroupCRD); err != nil {
log.V(1).Error(err, "updating crd")
}
return ctrl.Result{RequeueAfter: defaultRequeuePeriod}, nil
return ctrl.Result{}, nil
} else {
log.Error(err, "Received an error while creating a Rule-Group", "ruleGroup", createRuleGroupReq)
return ctrl.Result{RequeueAfter: defaultErrRequeuePeriod}, err
Expand All @@ -202,7 +202,7 @@ func (r *RuleGroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
log.V(1).Info("Rule-Group was updated", "ruleGroup", jstr)
}

return ctrl.Result{RequeueAfter: defaultRequeuePeriod}, nil
return ctrl.Result{}, nil
}

func flattenRuleGroup(ruleGroup *rulesgroups.RuleGroup) (*coralogixv1alpha1.RuleGroupStatus, error) {
Expand Down
2 changes: 0 additions & 2 deletions controllers/alphacontrollers/rulegroup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ func TestRuleGroupReconciler_Reconcile(t *testing.T) {

result, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})
assert.NoError(t, err)
assert.Equal(t, defaultRequeuePeriod, result.RequeueAfter)

namespacedName := types.NamespacedName{Namespace: "default", Name: "test"}
actualRuleGroupCRD := &coralogixv1alpha1.RuleGroup{}
Expand Down Expand Up @@ -270,7 +269,6 @@ func TestRuleGroupReconciler_Reconcile_5XX_StatusError(t *testing.T) {

result, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}})
assert.NoError(t, err)
assert.Equal(t, defaultRequeuePeriod, result.RequeueAfter)

namespacedName := types.NamespacedName{Namespace: "default", Name: "test"}
actualRuleGroupCRD := &coralogixv1alpha1.RuleGroup{}
Expand Down
3 changes: 1 addition & 2 deletions controllers/alphacontrollers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ import (
)

const (
defaultRequeuePeriod = 30 * time.Second
defaultErrRequeuePeriod = 20 * time.Second
defaultErrRequeuePeriod = 30 * time.Second
)

0 comments on commit d832ea1

Please sign in to comment.