@@ -61,8 +61,10 @@ import (
61
61
"github.com/operator-framework/operator-controller/internal/catalogd/serverutil"
62
62
"github.com/operator-framework/operator-controller/internal/catalogd/storage"
63
63
"github.com/operator-framework/operator-controller/internal/catalogd/webhook"
64
+ sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
64
65
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
65
66
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
67
+ sautil "github.com/operator-framework/operator-controller/internal/shared/util/sa"
66
68
"github.com/operator-framework/operator-controller/internal/shared/version"
67
69
)
68
70
@@ -246,18 +248,40 @@ func run(ctx context.Context) error {
246
248
cacheOptions := crcache.Options {
247
249
ByObject : map [client.Object ]crcache.ByObject {},
248
250
}
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
+ }),
258
266
},
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
+ }),
259
282
}
260
283
}
284
+ cacheOptions .ByObject [& corev1.Secret {}] = secretCache
261
285
262
286
// Create manager
263
287
mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
@@ -312,7 +336,7 @@ func run(ctx context.Context) error {
312
336
DockerCertPath : cfg .pullCasDir ,
313
337
OCICertPath : cfg .pullCasDir ,
314
338
}
315
- if _ , err := os .Stat (authFilePath ); err == nil && cfg . globalPullSecretKey != nil {
339
+ if _ , err := os .Stat (authFilePath ); err == nil {
316
340
logger .Info ("using available authentication information for pulling image" )
317
341
srcContext .AuthFilePath = authFilePath
318
342
} else if os .IsNotExist (err ) {
@@ -370,17 +394,16 @@ func run(ctx context.Context) error {
370
394
return err
371
395
}
372
396
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
384
407
}
385
408
//+kubebuilder:scaffold:builder
386
409
0 commit comments