-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Blake Devcich <[email protected]>
- Loading branch information
Showing
1 changed file
with
43 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ type LustreFileSystemReconciler struct { | |
// For more details, check Reconcile and its Result here: | ||
// - https://pkg.go.dev/sigs.k8s.io/[email protected]/pkg/reconcile | ||
func (r *LustreFileSystemReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, err error) { | ||
log.FromContext(ctx).Info("Reconcile start") | ||
|
||
fs := &lusv1beta1.LustreFileSystem{} | ||
if err := r.Get(ctx, req.NamespacedName, fs); err != nil { | ||
|
@@ -149,27 +150,29 @@ func (r *LustreFileSystemReconciler) Reconcile(ctx context.Context, req ctrl.Req | |
} | ||
} | ||
|
||
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 | ||
} | ||
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 | ||
} | ||
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, | ||
}, | ||
} | ||
state := lusv1beta1.NamespaceAccessReady | ||
if !r.isPersistentVolumeClaimBound(ctx, fs, namespace, mode) { | ||
state = lusv1beta1.NamespaceAccessPending | ||
} | ||
|
||
fs.Status.Namespaces[namespace].Modes[mode] = lusv1beta1.LustreFileSystemNamespaceAccessStatus{ | ||
State: state, | ||
PersistentVolumeRef: &corev1.LocalObjectReference{ | ||
Name: pv.Name, | ||
}, | ||
PersistentVolumeClaimRef: &corev1.LocalObjectReference{ | ||
Name: pvc.Name, | ||
}, | ||
} | ||
} | ||
} | ||
|
@@ -215,6 +218,27 @@ func (r *LustreFileSystemReconciler) Reconcile(ctx context.Context, req ctrl.Req | |
return ctrl.Result{}, nil | ||
} | ||
|
||
func (r *LustreFileSystemReconciler) isPersistentVolumeClaimBound(ctx context.Context, fs *lusv1beta1.LustreFileSystem, namespace string, mode corev1.PersistentVolumeAccessMode) bool { | ||
pvc := &corev1.PersistentVolumeClaim{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: fs.PersistentVolumeClaimName(namespace, mode), | ||
Namespace: namespace, | ||
}, | ||
} | ||
|
||
// If we can't find it, then it's not bound | ||
if err := r.Get(ctx, client.ObjectKeyFromObject(pvc), pvc); err != nil { | ||
return false | ||
} | ||
|
||
// PVC is terminating or not bound | ||
if !pvc.GetDeletionTimestamp().IsZero() || pvc.Status.Phase != corev1.ClaimBound { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
func (r *LustreFileSystemReconciler) createOrUpdatePersistentVolumeClaim(ctx context.Context, fs *lusv1beta1.LustreFileSystem, namespace string, mode corev1.PersistentVolumeAccessMode) (*corev1.PersistentVolumeClaim, error) { | ||
|
||
pvc := &corev1.PersistentVolumeClaim{ | ||
|