@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "errors"
2222
23+ corev1 "k8s.io/api/core/v1"
2324 ctrl "sigs.k8s.io/controller-runtime"
2425 "sigs.k8s.io/controller-runtime/pkg/builder"
2526 "sigs.k8s.io/controller-runtime/pkg/controller"
@@ -86,6 +87,17 @@ var domainImportDependency = dependency.NewDependency[*orcv1alpha1.UserList, *or
8687 },
8788)
8889
90+ var passwordDependency = dependency .NewDependency [* orcv1alpha1.UserList , * corev1.Secret ](
91+ "spec.resource.passwordRef" ,
92+ func (user * orcv1alpha1.User ) []string {
93+ resource := user .Spec .Resource
94+ if resource == nil {
95+ return nil
96+ }
97+ return []string {string (resource .PasswordRef )}
98+ },
99+ )
100+
89101// SetupWithManager sets up the controller with the Manager.
90102func (c userReconcilerConstructor ) SetupWithManager (ctx context.Context , mgr ctrl.Manager , options controller.Options ) error {
91103 log := ctrl .LoggerFrom (ctx )
@@ -106,8 +118,14 @@ func (c userReconcilerConstructor) SetupWithManager(ctx context.Context, mgr ctr
106118 return err
107119 }
108120
121+ passwordWatchEventHandler , err := passwordDependency .WatchEventHandler (log , k8sClient )
122+ if err != nil {
123+ return err
124+ }
125+
109126 builder := ctrl .NewControllerManagedBy (mgr ).
110127 WithOptions (options ).
128+ For (& orcv1alpha1.User {}).
111129 Watches (& orcv1alpha1.Domain {}, domainWatchEventHandler ,
112130 builder .WithPredicates (predicates .NewBecameAvailable (log , & orcv1alpha1.Domain {})),
113131 ).
@@ -118,12 +136,20 @@ func (c userReconcilerConstructor) SetupWithManager(ctx context.Context, mgr ctr
118136 Watches (& orcv1alpha1.Domain {}, domainImportWatchEventHandler ,
119137 builder .WithPredicates (predicates .NewBecameAvailable (log , & orcv1alpha1.Domain {})),
120138 ).
121- For (& orcv1alpha1.User {})
139+ // XXX: This is a general watch on secrets. A general watch on secrets
140+ // is undesirable because:
141+ // - It requires problematic RBAC
142+ // - Secrets are arbitrarily large, and we don't want to cache their contents
143+ //
144+ // These will require separate solutions. For the latter we should
145+ // probably use a MetadataOnly watch on secrets.
146+ Watches (& corev1.Secret {}, passwordWatchEventHandler )
122147
123148 if err := errors .Join (
124149 domainDependency .AddToManager (ctx , mgr ),
125150 projectDependency .AddToManager (ctx , mgr ),
126151 domainImportDependency .AddToManager (ctx , mgr ),
152+ passwordDependency .AddToManager (ctx , mgr ),
127153 credentialsDependency .AddToManager (ctx , mgr ),
128154 credentials .AddCredentialsWatch (log , mgr .GetClient (), builder , credentialsDependency ),
129155 ); err != nil {
0 commit comments