@@ -30,10 +30,8 @@ import (
3030
3131 "github.com/containers/image/v5/types"
3232 "github.com/spf13/cobra"
33- corev1 "k8s.io/api/core/v1"
3433 rbacv1 "k8s.io/api/rbac/v1"
3534 apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
36- "k8s.io/apimachinery/pkg/fields"
3735 k8slabels "k8s.io/apimachinery/pkg/labels"
3836 k8stypes "k8s.io/apimachinery/pkg/types"
3937 apimachineryrand "k8s.io/apimachinery/pkg/util/rand"
@@ -71,9 +69,12 @@ import (
7169 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/certproviders"
7270 "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
7371 "github.com/operator-framework/operator-controller/internal/operator-controller/scheme"
72+ sharedcontrollers "github.com/operator-framework/operator-controller/internal/shared/controllers"
7473 fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs"
7574 httputil "github.com/operator-framework/operator-controller/internal/shared/util/http"
7675 imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image"
76+ "github.com/operator-framework/operator-controller/internal/shared/util/pullsecretcache"
77+ sautil "github.com/operator-framework/operator-controller/internal/shared/util/sa"
7778 "github.com/operator-framework/operator-controller/internal/shared/version"
7879)
7980
@@ -217,17 +218,19 @@ func run() error {
217218 },
218219 DefaultLabelSelector : k8slabels .Nothing (),
219220 }
220- if globalPullSecretKey != nil {
221- cacheOptions .ByObject [& corev1.Secret {}] = crcache.ByObject {
222- Namespaces : map [string ]crcache.Config {
223- globalPullSecretKey .Namespace : {
224- LabelSelector : k8slabels .Everything (),
225- FieldSelector : fields .SelectorFromSet (map [string ]string {
226- "metadata.name" : globalPullSecretKey .Name ,
227- }),
228- },
229- },
230- }
221+
222+ saKey , err := sautil .GetServiceAccount ()
223+ if err != nil {
224+ setupLog .Error (err , "Failed to extract serviceaccount from JWT" )
225+ return err
226+ }
227+ setupLog .Info ("Successfully extracted serviceaccount from JWT" , "serviceaccount" ,
228+ fmt .Sprintf ("%s/%s" , saKey .Namespace , saKey .Name ))
229+
230+ err = pullsecretcache .SetupPullSecretCache (& cacheOptions , globalPullSecretKey , saKey )
231+ if err != nil {
232+ setupLog .Error (err , "Unable to setup pull-secret cache" )
233+ return err
231234 }
232235
233236 metricsServerOptions := server.Options {}
@@ -360,7 +363,7 @@ func run() error {
360363 OCICertPath : cfg .pullCasDir ,
361364 }
362365 logger := log .FromContext (ctx )
363- if _ , err := os .Stat (authFilePath ); err == nil && globalPullSecretKey != nil {
366+ if _ , err := os .Stat (authFilePath ); err == nil {
364367 logger .Info ("using available authentication information for pulling image" )
365368 srcContext .AuthFilePath = authFilePath
366369 } else if os .IsNotExist (err ) {
@@ -482,17 +485,16 @@ func run() error {
482485 return err
483486 }
484487
485- if globalPullSecretKey != nil {
486- setupLog .Info ("creating SecretSyncer controller for watching secret" , "Secret" , cfg .globalPullSecret )
487- err := (& controllers.PullSecretReconciler {
488- Client : mgr .GetClient (),
489- AuthFilePath : authFilePath ,
490- SecretKey : * globalPullSecretKey ,
491- }).SetupWithManager (mgr )
492- if err != nil {
493- setupLog .Error (err , "unable to create controller" , "controller" , "SecretSyncer" )
494- return err
495- }
488+ setupLog .Info ("creating SecretSyncer controller for watching secret" , "Secret" , cfg .globalPullSecret )
489+ err = (& sharedcontrollers.PullSecretReconciler {
490+ Client : mgr .GetClient (),
491+ AuthFilePath : authFilePath ,
492+ SecretKey : globalPullSecretKey ,
493+ ServiceAccountKey : saKey ,
494+ }).SetupWithManager (mgr )
495+ if err != nil {
496+ setupLog .Error (err , "unable to create controller" , "controller" , "SecretSyncer" )
497+ return err
496498 }
497499
498500 //+kubebuilder:scaffold:builder
0 commit comments