@@ -61,8 +61,10 @@ import (
6161 "github.com/operator-framework/operator-controller/internal/catalogd/serverutil"
6262 "github.com/operator-framework/operator-controller/internal/catalogd/storage"
6363 "github.com/operator-framework/operator-controller/internal/catalogd/webhook"
64+ sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
6465 fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
6566 imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
67+ sautil "github.com/operator-framework/operator-controller/internal/shared/util/sa"
6668 "github.com/operator-framework/operator-controller/internal/shared/version"
6769)
6870
@@ -246,18 +248,40 @@ func run(ctx context.Context) error {
246248 cacheOptions := crcache.Options {
247249 ByObject : map [client.Object ]crcache.ByObject {},
248250 }
249- if cfg .globalPullSecretKey != nil {
250- cacheOptions .ByObject [& corev1.Secret {}] = crcache.ByObject {
251- Namespaces : map [string ]crcache.Config {
252- cfg .globalPullSecretKey .Namespace : {
253- LabelSelector : k8slabels .Everything (),
254- FieldSelector : fields .SelectorFromSet (map [string ]string {
255- "metadata.name" : cfg .globalPullSecretKey .Name ,
256- }),
257- },
251+
252+ saKey , err := sautil .GetServiceAccount ()
253+ if err != nil {
254+ setupLog .Error (err , "Unable to get pod namesapce and serviceaccount" )
255+ return err
256+ }
257+
258+ setupLog .Info ("Read token" , "serviceaccount" , saKey )
259+ cacheOptions .ByObject [& corev1.ServiceAccount {}] = crcache.ByObject {
260+ Namespaces : map [string ]crcache.Config {
261+ saKey .Namespace : {
262+ LabelSelector : k8slabels .Everything (),
263+ FieldSelector : fields .SelectorFromSet (map [string ]string {
264+ "metadata.name" : saKey .Name ,
265+ }),
258266 },
267+ },
268+ }
269+
270+ secretCache := crcache.ByObject {}
271+ secretCache .Namespaces = make (map [string ]crcache.Config , 2 )
272+ secretCache .Namespaces [saKey .Namespace ] = crcache.Config {
273+ LabelSelector : k8slabels .Everything (),
274+ FieldSelector : fields .Everything (),
275+ }
276+ if cfg .globalPullSecretKey != nil {
277+ secretCache .Namespaces [cfg .globalPullSecretKey .Namespace ] = crcache.Config {
278+ LabelSelector : k8slabels .Everything (),
279+ FieldSelector : fields .SelectorFromSet (map [string ]string {
280+ "metadata.name" : cfg .globalPullSecretKey .Name ,
281+ }),
259282 }
260283 }
284+ cacheOptions .ByObject [& corev1.Secret {}] = secretCache
261285
262286 // Create manager
263287 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
@@ -312,7 +336,7 @@ func run(ctx context.Context) error {
312336 DockerCertPath : cfg .pullCasDir ,
313337 OCICertPath : cfg .pullCasDir ,
314338 }
315- if _ , err := os .Stat (authFilePath ); err == nil && cfg . globalPullSecretKey != nil {
339+ if _ , err := os .Stat (authFilePath ); err == nil {
316340 logger .Info ("using available authentication information for pulling image" )
317341 srcContext .AuthFilePath = authFilePath
318342 } else if os .IsNotExist (err ) {
@@ -370,17 +394,16 @@ func run(ctx context.Context) error {
370394 return err
371395 }
372396
373- if cfg .globalPullSecretKey != nil {
374- setupLog .Info ("creating SecretSyncer controller for watching secret" , "Secret" , cfg .globalPullSecret )
375- err := (& corecontrollers.PullSecretReconciler {
376- Client : mgr .GetClient (),
377- AuthFilePath : authFilePath ,
378- SecretKey : * cfg .globalPullSecretKey ,
379- }).SetupWithManager (mgr )
380- if err != nil {
381- setupLog .Error (err , "unable to create controller" , "controller" , "SecretSyncer" )
382- return err
383- }
397+ setupLog .Info ("creating SecretSyncer controller for watching secret" , "Secret" , cfg .globalPullSecret )
398+ err = (& sharedcontrollers.PullSecretReconciler {
399+ Client : mgr .GetClient (),
400+ AuthFilePath : authFilePath ,
401+ SecretKey : cfg .globalPullSecretKey ,
402+ ServiceAccountKey : saKey ,
403+ }).SetupWithManager (mgr )
404+ if err != nil {
405+ setupLog .Error (err , "unable to create controller" , "controller" , "SecretSyncer" )
406+ return err
384407 }
385408 //+kubebuilder:scaffold:builder
386409
0 commit comments