Skip to content

Commit

Permalink
add watch for namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
bdevcich committed Jan 29, 2024
1 parent db22d3c commit 7235556
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions internal/controller/lustrefilesystem_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -139,6 +141,7 @@ func (r *LustreFileSystemReconciler) Reconcile(ctx context.Context, req ctrl.Req
ns := &corev1.Namespace{}
if err := r.Get(ctx, types.NamespacedName{Name: namespace}, ns); err != nil {
// TODO: remove the namespace from the spec if it does not exist?
// TODO: mark as pending if we don't remove it from the spec?
log.FromContext(ctx).Info("Namespace does not exist, skipping...", "namespace", namespace)
continue
}
Expand Down Expand Up @@ -363,5 +366,19 @@ func (r *LustreFileSystemReconciler) deleteAccess(ctx context.Context, fs *lusv1
func (r *LustreFileSystemReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&lusv1beta1.LustreFileSystem{}).
// Watch all namespaces for changes to ensure this reconciler keeps its list of namespaces current
Watches(
&lusv1beta1.LustreFileSystem{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, o client.Object) []reconcile.Request {
return []reconcile.Request{
{
NamespacedName: types.NamespacedName{
Name: o.GetName(),
Namespace: o.GetNamespace(),
},
},
}
}),
).
Complete(r)
}

0 comments on commit 7235556

Please sign in to comment.