Skip to content
Draft
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
13 changes: 13 additions & 0 deletions api/v1alpha1/pool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ type PoolSpec struct {
StorageClassParameters *StorageClassParameters `json:"storageClassParameters,omitempty"`
}

// Condition type constants used in PoolStatus.Conditions.
const (
// ConditionTypePoolReady indicates the pool is fully reconciled and operational.
ConditionTypePoolReady = "Ready"
)

// PoolStatus defines the observed state of Pool.
type PoolStatus struct {
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Pool UUID"
Expand All @@ -163,6 +169,13 @@ type PoolStatus struct {
QoS *PoolQoSStatus `json:"qos,omitempty"`
// AllowedNodes lists the Kubernetes node names currently registered on the backend.
AllowedNodes []string `json:"allowedNodes,omitempty"`
// +operator-sdk:csv:customresourcedefinitions:type=status,displayName="Conditions"
// Conditions provides human-readable status conditions for kubectl describe output.
// +listType=map
// +listMapKey=type
// +patchStrategy=merge
// +patchMergeKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 35 additions & 3 deletions internal/controller/simplyblockpool_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ func (r *PoolReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
)

if err != nil {
log.Info("Cluster UUID not ready yet, requeuing",
"cluster", poolCR.Spec.ClusterName,
)
log.Info("Cluster not ready, requeuing", "cluster", poolCR.Spec.ClusterName, "reason", err.Error())
if setErr := r.setCondition(ctx, poolCR, simplyblockv1alpha1.ConditionTypePoolReady,
metav1.ConditionFalse, "ClusterNotFound", err.Error()); setErr != nil {
log.Error(setErr, "Failed to set Ready condition")
}
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
}

Expand Down Expand Up @@ -491,6 +493,36 @@ func (r *PoolReconciler) syncPoolHosts(
return changed, nil
}

// setCondition patches the Pool status with the given condition.
func (r *PoolReconciler) setCondition(ctx context.Context, poolCR *simplyblockv1alpha1.Pool, condType string, status metav1.ConditionStatus, reason, message string) error {
now := metav1.Now()
for i, c := range poolCR.Status.Conditions {
if c.Type == condType {
if c.Status == status && c.Reason == reason && c.Message == message {
return nil
}
poolCR.Status.Conditions[i] = metav1.Condition{
Type: condType,
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: now,
ObservedGeneration: poolCR.Generation,
}
return r.Status().Update(ctx, poolCR)
}
}
poolCR.Status.Conditions = append(poolCR.Status.Conditions, metav1.Condition{
Type: condType,
Status: status,
Reason: reason,
Message: message,
LastTransitionTime: now,
ObservedGeneration: poolCR.Generation,
})
return r.Status().Update(ctx, poolCR)
}

// SetupWithManager sets up the controller with the Manager.
func (r *PoolReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
Expand Down
7 changes: 5 additions & 2 deletions internal/utils/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,15 @@ func ResolveClusterUUID(
}

for _, cluster := range clusters.Items {
if cluster.Name == clusterName && cluster.Status.UUID != "" {
if cluster.Name == clusterName {
if cluster.Status.UUID == "" {
return "", fmt.Errorf("StorageCluster %q found in namespace %q but UUID not yet populated", clusterName, namespace)
}
return cluster.Status.UUID, nil
}
}

return "", fmt.Errorf("cluster %q not found or UUID not ready", clusterName)
return "", fmt.Errorf("StorageCluster %q not found in namespace %q", clusterName, namespace)
}

func ResolveClusterIdentifier(ctx context.Context, k8sClient client.Client, namespace, cluster string) (string, error) {
Expand Down
Loading