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 17, 2024
1 parent ee018ee commit a11c518
Show file tree
Hide file tree
Showing 3 changed files with 51 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 @@ -67,6 +67,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
32 changes: 30 additions & 2 deletions internal/controller/drclusterconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,24 @@ func (r *DRClusterConfigReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

var (
res reconcile.Result
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 @@ -111,6 +124,8 @@ func (r *DRClusterConfigReconciler) processDeletion(
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 @@ -119,10 +134,14 @@ func (r *DRClusterConfigReconciler) processDeletion(
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 @@ -169,22 +188,31 @@ func (r *DRClusterConfigReconciler) processCreateOrUpdate(
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 a11c518

Please sign in to comment.