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

KO-341: Add controller event flow for BackupService, Backup and Restore controllers #322

Closed
wants to merge 1 commit into from
Closed
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
29 changes: 29 additions & 0 deletions internal/controller/backup-service/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func (r *SingleBackupServiceReconciler) Reconcile() (result ctrl.Result, recErr
}()

if !r.aeroBackupService.ObjectMeta.DeletionTimestamp.IsZero() {
r.Log.Info("Deleted AerospikeBackupService")
r.Recorder.Eventf(
r.aeroBackupService, corev1.EventTypeNormal, "Deleted",
"Deleted AerospikeBackupService %s/%s", r.aeroBackupService.Namespace,
r.aeroBackupService.Name,
)
// Stop reconciliation as the Aerospike Backup service is being deleted
return reconcile.Result{}, nil
}
Expand All @@ -73,21 +79,44 @@ func (r *SingleBackupServiceReconciler) Reconcile() (result ctrl.Result, recErr
}

if err := r.reconcileConfigMap(); err != nil {
r.Log.Error(err, "Failed to reconcile config map")
r.Recorder.Eventf(r.aeroBackupService, corev1.EventTypeWarning,
"ConfigMapReconcileFailed", "Failed to reconcile config map %s/%s",
r.aeroBackupService.Namespace, r.aeroBackupService.Name)

recErr = err

return ctrl.Result{}, err
}

if err := r.reconcileDeployment(); err != nil {
r.Log.Error(err, "Failed to reconcile deployment")
r.Recorder.Eventf(r.aeroBackupService, corev1.EventTypeWarning,
"DeploymentReconcileFailed", "Failed to reconcile deployment %s/%s",
r.aeroBackupService.Namespace, r.aeroBackupService.Name)

recErr = err

return ctrl.Result{}, err
}

if err := r.reconcileService(); err != nil {
r.Log.Error(err, "Failed to reconcile service")
r.Recorder.Eventf(r.aeroBackupService, corev1.EventTypeWarning,
"ServiceReconcileFailed", "Failed to reconcile service %s/%s",
r.aeroBackupService.Namespace, r.aeroBackupService.Name)

recErr = err

return ctrl.Result{}, err
}

if err := r.updateStatus(); err != nil {
r.Log.Error(err, "Failed to update status")
r.Recorder.Eventf(r.aeroBackupService, corev1.EventTypeWarning,
"StatusUpdateFailed", "Failed to update AerospikeBackupService status %s/%s",
r.aeroBackupService.Namespace, r.aeroBackupService.Name)

return ctrl.Result{}, err
}

Expand Down
20 changes: 19 additions & 1 deletion internal/controller/backup/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (r *SingleBackupReconciler) Reconcile() (result ctrl.Result, recErr error)
return reconcile.Result{}, err
}

r.Log.Info("Deleted AerospikeBackup")
r.Recorder.Eventf(
r.aeroBackup, corev1.EventTypeNormal, "Deleted",
"Deleted AerospikeBackup %s/%s", r.aeroBackup.Namespace,
r.aeroBackup.Name,
)
// Stop reconciliation as the backup is being deleted
return reconcile.Result{}, nil
}
Expand All @@ -54,16 +60,28 @@ func (r *SingleBackupReconciler) Reconcile() (result ctrl.Result, recErr error)

if err := r.reconcileConfigMap(); err != nil {
r.Log.Error(err, "Failed to reconcile config map")
r.Recorder.Eventf(r.aeroBackup, corev1.EventTypeWarning,
"ConfigMapReconcileFailed", "Failed to reconcile config map %s/%s",
r.aeroBackup.Namespace, r.aeroBackup.Name)

return reconcile.Result{}, err
}

if err := r.reconcileBackup(); err != nil {
r.Log.Error(err, "Failed to reconcile backup")
r.Recorder.Eventf(r.aeroBackup, corev1.EventTypeWarning,
"BackupReconcileFailed", "Failed to reconcile backup %s/%s",
r.aeroBackup.Namespace, r.aeroBackup.Name)

return reconcile.Result{}, err
}

if err := r.updateStatus(); err != nil {
r.Log.Error(err, "Failed to update status")
r.Recorder.Eventf(r.aeroBackup, corev1.EventTypeWarning,
"StatusUpdateFailed", "Failed to update AerospikeBackup status %s/%s",
r.aeroBackup.Namespace, r.aeroBackup.Name)

return reconcile.Result{}, err
}

Expand Down Expand Up @@ -309,7 +327,7 @@ func (r *SingleBackupReconciler) scheduleOnDemandBackup() error {
r.Log.Info("Scheduled on-demand backup", "ID", r.aeroBackup.Spec.OnDemandBackups[0].ID,
"routine", r.aeroBackup.Spec.OnDemandBackups[0].RoutineName)

r.Log.Info("Reconciled scheduled backup")
r.Log.Info("Reconciled on-demand backup")

return nil
}
Expand Down
15 changes: 15 additions & 0 deletions internal/controller/restore/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"

"github.com/go-logr/logr"
corev1 "k8s.io/api/core/v1"
k8sRuntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
Expand All @@ -31,6 +32,12 @@ type SingleRestoreReconciler struct {

func (r *SingleRestoreReconciler) Reconcile() (result ctrl.Result, recErr error) {
if !r.aeroRestore.ObjectMeta.DeletionTimestamp.IsZero() {
r.Log.Info("Deleted AerospikeRestore")
r.Recorder.Eventf(
r.aeroRestore, corev1.EventTypeNormal, "Deleted",
"Deleted AerospikeRestore %s/%s", r.aeroRestore.Namespace,
r.aeroRestore.Name,
)
// Stop reconciliation as the Aerospike restore is being deleted
return reconcile.Result{}, nil
}
Expand All @@ -41,13 +48,21 @@ func (r *SingleRestoreReconciler) Reconcile() (result ctrl.Result, recErr error)

if res := r.reconcileRestore(); !res.IsSuccess {
if res.Err != nil {
r.Log.Error(res.Err, "Failed to reconcile restore")
r.Recorder.Eventf(r.aeroRestore, corev1.EventTypeWarning, "RestoreReconcileFailed",
"Failed to reconcile restore %s/%s", r.aeroRestore.Namespace, r.aeroRestore.Name)

return res.Result, res.Err
}

return res.Result, nil
}

if err := r.checkRestoreStatus(); err != nil {
r.Log.Error(err, "Failed to check restore status")
r.Recorder.Eventf(r.aeroRestore, corev1.EventTypeWarning, "CheckStatusFailed",
"Failed to check restore status %s/%s", r.aeroRestore.Namespace, r.aeroRestore.Name)

return ctrl.Result{}, err
}

Expand Down
Loading