Skip to content

Commit

Permalink
Adds status to DRClusterConfig
Browse files Browse the repository at this point in the history
Adds a basic status to DRClusterConfig reflecting success or
failure of reconciliation

Signed-off-by: raaizik <[email protected]>
  • Loading branch information
raaizik committed Dec 10, 2024
1 parent 3c9fe8a commit 8fc0b7c
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
13 changes: 13 additions & 0 deletions api/v1alpha1/drclusterconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@ type DRClusterConfigSpec struct {
// TODO: PeerClusters []ClusterID; to decide if we really need this!
}

type DRClusterConfigState string

const (
DRClusterConfigFailed = DRClusterConfigState("Failed")
DRClusterConfigReady = DRClusterConfigState("Ready")
)

// DRClusterConfigStatus defines the observed state of DRClusterConfig
type DRClusterConfigStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file

// TODO: handle no status for this resource, and remove required RBAC/kubebuilder artifacts for the same

Phase DRClusterConfigState `json:"phase,omitempty"`

// ObservedGeneration is the last generation change the operator has dealt with
//+optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
8 changes: 8 additions & 0 deletions config/crd/bases/ramendr.openshift.io_drclusterconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ spec:
type: object
status:
description: DRClusterConfigStatus defines the observed state of DRClusterConfig
properties:
observedGeneration:
description: ObservedGeneration is the last generation change the
operator has dealt with
format: int64
type: integer
phase:
type: string
type: object
type: object
served: true
Expand Down
24 changes: 22 additions & 2 deletions internal/controller/drclusterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,22 @@ func (r *DRClusterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

var res reconcile.Result
var err error

if util.ResourceIsDeleted(drCConfig) {
return r.processDeletion(ctx, log, drCConfig)
res, err = r.processDeletion(ctx, log, drCConfig)
} else {
res, err = r.processCreateOrUpdate(ctx, log, drCConfig)
}

// Apply status changes to the DRClusterConfig
statusError := r.Client.Status().Update(ctx, drCConfig)
if statusError != nil {
log.Error(statusError, "Failed to update DRClusterConfig status.")
}

return r.processCreateOrUpdate(ctx, log, drCConfig)
return res, err
}

func (r *DRClusterConfigReconciler) GetDRClusterConfig(ctx context.Context) (*ramen.DRClusterConfig, error) {
Expand Down Expand Up @@ -110,6 +121,7 @@ func (r *DRClusterConfigReconciler) processDeletion(
) (ctrl.Result, error) {
if err := r.pruneClusterClaims(ctx, log, []string{}); err != nil {
log.Info("Reconcile error", "error", err)
drCConfig.Status.Phase = ramen.DRClusterConfigFailed

return ctrl.Result{Requeue: true}, err
}
Expand All @@ -118,11 +130,13 @@ func (r *DRClusterConfigReconciler) processDeletion(
RemoveFinalizer(drCConfigFinalizerName).
Update(ctx, r.Client); err != nil {
log.Info("Reconcile error", "error", err)
drCConfig.Status.Phase = ramen.DRClusterConfigFailed

return ctrl.Result{Requeue: true},
fmt.Errorf("failed to remove finalizer for DRClusterConfig resource, %w", err)
}

drCConfig.Status.Phase = ramen.DRClusterConfigReady
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -168,23 +182,29 @@ func (r *DRClusterConfigReconciler) processCreateOrUpdate(
AddFinalizer(drCConfigFinalizerName).
Update(ctx, r.Client); err != nil {
log.Info("Reconcile error", "error", err)
drCConfig.Status.Phase = ramen.DRClusterConfigFailed

return ctrl.Result{Requeue: true}, fmt.Errorf("failed to add finalizer for DRClusterConfig resource, %w", err)
}

allSurvivors, err := r.CreateClassClaims(ctx, log)
if err != nil {
drCConfig.Status.Phase = ramen.DRClusterConfigFailed
log.Info("Reconcile error", "error", err)

return ctrl.Result{Requeue: true}, err
}

if err := r.pruneClusterClaims(ctx, log, allSurvivors); err != nil {
drCConfig.Status.Phase = ramen.DRClusterConfigFailed
log.Info("Reconcile error", "error", err)

return ctrl.Result{Requeue: true}, err
}

drCConfig.Status.Phase = ramen.DRClusterConfigReady
drCConfig.Status.ObservedGeneration = drCConfig.Generation

return ctrl.Result{}, nil
}

Expand Down

0 comments on commit 8fc0b7c

Please sign in to comment.