Skip to content

Commit

Permalink
always try the PV/PVC creates
Browse files Browse the repository at this point in the history
  • Loading branch information
bdevcich committed Jan 25, 2024
1 parent e839083 commit 1d7d047
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions internal/controller/lustrefilesystem_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,52 +133,49 @@ func (r *LustreFileSystemReconciler) Reconcile(ctx context.Context, req ctrl.Req
for namespace := range fs.Spec.Namespaces {
log.FromContext(ctx).Info("spec namespace loop start", "namespace", namespace)

// Create the Status Namespace map if empty
if fs.Status.Namespaces == nil {
fs.Status.Namespaces = make(map[string]lusv1beta1.LustreFileSystemNamespaceStatus)
log.FromContext(ctx).Info("spec namespace loop status nil", "namespace", namespace)
} else {
log.FromContext(ctx).Info("spec namespace loop status list", "status.namespaces", fs.Status.Namespaces)
}

// For each mode in the namespace
for _, mode := range fs.Spec.Namespaces[namespace].Modes {
log.FromContext(ctx).Info("spec namespace loop mode loop", "mode", mode)

// Create the Status Namespace Mode map if empty
if fs.Status.Namespaces[namespace].Modes == nil {
fs.Status.Namespaces[namespace] = lusv1beta1.LustreFileSystemNamespaceStatus{
Modes: make(map[corev1.PersistentVolumeAccessMode]lusv1beta1.LustreFileSystemNamespaceAccessStatus),
}
}

// If the Status Namespace doesn't have a mode, create it and mark it as Pending
if _, found := fs.Status.Namespaces[namespace].Modes[mode]; !found {
fs.Status.Namespaces[namespace].Modes[mode] = lusv1beta1.LustreFileSystemNamespaceAccessStatus{
State: lusv1beta1.NamespaceAccessPending,
}
log.FromContext(ctx).Info("spec namespace loop mode loop state pending")
}

status := fs.Status.Namespaces[namespace].Modes[mode]
if status.State != lusv1beta1.NamespaceAccessReady {
pv, err := r.createOrUpdatePersistentVolume(ctx, fs, namespace, mode)
if err != nil {
return ctrl.Result{}, err
}
// Attempt to create the PV, if it fails, the status will be marked as Pending
pv, err := r.createOrUpdatePersistentVolume(ctx, fs, namespace, mode)
if err != nil {
return ctrl.Result{}, err
}

pvc, err := r.createOrUpdatePersistentVolumeClaim(ctx, fs, namespace, mode)
if err != nil {
return ctrl.Result{}, err
}
// Attempt to create the PVC, if it fails, the status will be marked as Pending
pvc, err := r.createOrUpdatePersistentVolumeClaim(ctx, fs, namespace, mode)
if err != nil {
return ctrl.Result{}, err
}

fs.Status.Namespaces[namespace].Modes[mode] = lusv1beta1.LustreFileSystemNamespaceAccessStatus{
State: lusv1beta1.NamespaceAccessReady,
PersistentVolumeRef: &corev1.LocalObjectReference{
Name: pv.Name,
},
PersistentVolumeClaimRef: &corev1.LocalObjectReference{
Name: pvc.Name,
},
}
} else {
log.FromContext(ctx).Info("spec namespace loop mode loop status is not ready", "state", status.State)
// If we got this far, the status is Ready
fs.Status.Namespaces[namespace].Modes[mode] = lusv1beta1.LustreFileSystemNamespaceAccessStatus{
State: lusv1beta1.NamespaceAccessReady,
PersistentVolumeRef: &corev1.LocalObjectReference{
Name: pv.Name,
},
PersistentVolumeClaimRef: &corev1.LocalObjectReference{
Name: pvc.Name,
},
}
}
}
Expand Down

0 comments on commit 1d7d047

Please sign in to comment.