@@ -23,13 +23,17 @@ import (
2323 "net/http"
2424 "os"
2525 "path/filepath"
26+ "strings"
2627 "time"
2728
2829 "github.com/spf13/pflag"
2930 "go.uber.org/zap/zapcore"
31+ corev1 "k8s.io/api/core/v1"
3032 apiextensionsv1client "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1"
33+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34+ "k8s.io/apimachinery/pkg/fields"
3135 k8slabels "k8s.io/apimachinery/pkg/labels"
32- "k8s.io/apimachinery/pkg/selection "
36+ k8stypes "k8s.io/apimachinery/pkg/types "
3337 corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
3438 _ "k8s.io/client-go/plugin/pkg/client/auth"
3539 ctrl "sigs.k8s.io/controller-runtime"
@@ -52,7 +56,6 @@ import (
5256 "github.com/operator-framework/operator-controller/internal/contentmanager"
5357 "github.com/operator-framework/operator-controller/internal/controllers"
5458 "github.com/operator-framework/operator-controller/internal/httputil"
55- "github.com/operator-framework/operator-controller/internal/labels"
5659 "github.com/operator-framework/operator-controller/internal/resolve"
5760 "github.com/operator-framework/operator-controller/internal/rukpak/preflights/crdupgradesafety"
5861 "github.com/operator-framework/operator-controller/internal/rukpak/source"
@@ -87,6 +90,7 @@ func main() {
8790 operatorControllerVersion bool
8891 systemNamespace string
8992 caCertDir string
93+ globalPullSecret string
9094 )
9195 flag .StringVar (& metricsAddr , "metrics-bind-address" , ":8080" , "The address the metric endpoint binds to." )
9296 flag .StringVar (& probeAddr , "health-probe-bind-address" , ":8081" , "The address the probe endpoint binds to." )
@@ -97,6 +101,7 @@ func main() {
97101 flag .StringVar (& cachePath , "cache-path" , "/var/cache" , "The local directory path used for filesystem based caching" )
98102 flag .BoolVar (& operatorControllerVersion , "version" , false , "Prints operator-controller version information" )
99103 flag .StringVar (& systemNamespace , "system-namespace" , "" , "Configures the namespace that gets used to deploy system resources." )
104+ flag .StringVar (& globalPullSecret , "global-pull-secret" , "" , "The <namespace>/<name> of the global pull secret that is going to be used to pull bundle images." )
100105 opts := zap.Options {
101106 Development : true ,
102107 TimeEncoder : zapcore .RFC3339NanoTimeEncoder ,
@@ -115,16 +120,42 @@ func main() {
115120 ctrl .SetLogger (zap .New (zap .UseFlagOptions (& opts ), zap .StacktraceLevel (zapcore .DPanicLevel )))
116121 setupLog .Info ("starting up the controller" , "version info" , version .String ())
117122
123+ var globalPullSecretKey * k8stypes.NamespacedName
124+ if globalPullSecret != "" {
125+ secretParts := strings .Split (globalPullSecret , "/" )
126+ if len (secretParts ) != 2 {
127+ setupLog .Error (fmt .Errorf ("incorrect number of components" ), "value of global-pull-secret should be of the format <namespace>/<name>" )
128+ os .Exit (1 )
129+ }
130+ globalPullSecretKey = & k8stypes.NamespacedName {Name : secretParts [1 ], Namespace : secretParts [0 ]}
131+ }
132+
118133 if systemNamespace == "" {
119134 systemNamespace = podNamespace ()
120135 }
121136
122- dependentRequirement , err := k8slabels .NewRequirement (labels .OwnerKindKey , selection .In , []string {ocv1alpha1 .ClusterExtensionKind })
123- if err != nil {
124- setupLog .Error (err , "unable to create dependent label selector for cache" )
125- os .Exit (1 )
137+ cacheOptions := crcache.Options {
138+ ByObject : map [client.Object ]crcache.ByObject {
139+ & ocv1alpha1.ClusterExtension {}: {Label : k8slabels .Everything ()},
140+ & catalogd.ClusterCatalog {}: {Label : k8slabels .Everything ()},
141+ },
142+ DefaultNamespaces : map [string ]crcache.Config {
143+ systemNamespace : {LabelSelector : k8slabels .Everything ()},
144+ },
145+ DefaultLabelSelector : k8slabels .Nothing (),
146+ }
147+ if globalPullSecretKey != nil {
148+ cacheOptions .ByObject [& corev1.Secret {}] = crcache.ByObject {
149+ Namespaces : map [string ]crcache.Config {
150+ globalPullSecretKey .Namespace : {
151+ LabelSelector : k8slabels .Everything (),
152+ FieldSelector : fields .SelectorFromSet (map [string ]string {
153+ "metadata.name" : globalPullSecretKey .Name ,
154+ }),
155+ },
156+ },
157+ }
126158 }
127- dependentSelector := k8slabels .NewSelector ().Add (* dependentRequirement )
128159
129160 setupLog .Info ("set up manager" )
130161 mgr , err := ctrl .NewManager (ctrl .GetConfigOrDie (), ctrl.Options {
@@ -133,16 +164,7 @@ func main() {
133164 HealthProbeBindAddress : probeAddr ,
134165 LeaderElection : enableLeaderElection ,
135166 LeaderElectionID : "9c4404e7.operatorframework.io" ,
136- Cache : crcache.Options {
137- ByObject : map [client.Object ]crcache.ByObject {
138- & ocv1alpha1.ClusterExtension {}: {Label : k8slabels .Everything ()},
139- & catalogd.ClusterCatalog {}: {Label : k8slabels .Everything ()},
140- },
141- DefaultNamespaces : map [string ]crcache.Config {
142- systemNamespace : {LabelSelector : k8slabels .Everything ()},
143- },
144- DefaultLabelSelector : dependentSelector ,
145- },
167+ Cache : cacheOptions ,
146168 // LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
147169 // when the Manager ends. This requires the binary to immediately end when the
148170 // Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
@@ -200,6 +222,15 @@ func main() {
200222 AuthNamespace : systemNamespace ,
201223 CertPoolWatcher : certPoolWatcher ,
202224 }
225+ if globalPullSecretKey != nil {
226+ unpacker .PullSecretFetcher = func (ctx context.Context ) ([]corev1.Secret , error ) {
227+ pullSecret , err := coreClient .Secrets (globalPullSecretKey .Namespace ).Get (ctx , globalPullSecretKey .Name , metav1.GetOptions {})
228+ if err != nil {
229+ return nil , err
230+ }
231+ return []corev1.Secret {* pullSecret }, err
232+ }
233+ }
203234
204235 clusterExtensionFinalizers := crfinalizer .NewFinalizers ()
205236 domain := ocv1alpha1 .GroupVersion .Group
0 commit comments