88
99 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1010 "k8s.io/client-go/kubernetes"
11+ "k8s.io/client-go/rest"
1112
1213 configv1 "github.com/openshift/api/config/v1"
1314 configclient "github.com/openshift/client-go/config/clientset/versioned"
@@ -16,20 +17,33 @@ import (
1617 operatorclientv1 "github.com/openshift/client-go/operator/clientset/versioned/typed/operator/v1"
1718 operatorinformers "github.com/openshift/client-go/operator/informers/externalversions"
1819 "github.com/openshift/library-go/pkg/controller/controllercmd"
20+ "github.com/openshift/library-go/pkg/operator/resource/resourceapply"
1921 "github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
22+ "github.com/openshift/library-go/pkg/operator/staticresourcecontroller"
2023 "github.com/openshift/library-go/pkg/operator/status"
2124 "github.com/openshift/library-go/pkg/operator/v1helpers"
2225
2326 configobservationcontroller "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/configobservation/configobservercontroller"
2427 "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/usercaobservation"
28+ "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/operator/v311_00_assets"
2529 "github.com/openshift/cluster-openshift-controller-manager-operator/pkg/util"
2630)
2731
2832func RunOperator (ctx context.Context , controllerConfig * controllercmd.ControllerContext ) error {
29- kubeClient , err := kubernetes .NewForConfig (controllerConfig .ProtoKubeConfig )
33+ // Increase QPS and burst to avoid client-side rate limits when reconciling RBAC API objects.
34+ // See TODO below for the StaticResourceController
35+ highRateLimitProtoKubeConfig := rest .CopyConfig (controllerConfig .ProtoKubeConfig )
36+ if highRateLimitProtoKubeConfig .QPS < 50 {
37+ highRateLimitProtoKubeConfig .QPS = 50
38+ }
39+ if highRateLimitProtoKubeConfig .Burst < 100 {
40+ highRateLimitProtoKubeConfig .Burst = 100
41+ }
42+ kubeClient , err := kubernetes .NewForConfig (highRateLimitProtoKubeConfig )
3043 if err != nil {
3144 return err
3245 }
46+
3347 operatorClient , err := operatorclient .NewForConfig (controllerConfig .KubeConfig )
3448 if err != nil {
3549 return err
@@ -39,15 +53,26 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
3953 return err
4054 }
4155
42- kubeInformers := v1helpers .NewKubeInformersForNamespaces (kubeClient , util .TargetNamespace , util .OperatorNamespace , util .UserSpecifiedGlobalConfigNamespace )
56+ // Create kube informers for namespaces that the operator reconciles content from or to.
57+ // The empty string "" adds informers for cluster-scoped resources.
58+ kubeInformers := v1helpers .NewKubeInformersForNamespaces (kubeClient ,
59+ "" ,
60+ util .TargetNamespace ,
61+ util .OperatorNamespace ,
62+ util .UserSpecifiedGlobalConfigNamespace ,
63+ util .InfraNamespace ,
64+ metav1 .NamespaceSystem ,
65+ )
4366 operatorConfigInformers := operatorinformers .NewSharedInformerFactory (operatorClient , 10 * time .Minute )
4467 configInformers := configinformers .NewSharedInformerFactory (configClient , 10 * time .Minute )
4568
69+ // OpenShiftControlllerManagerOperator reconciles the state of the openshift-controller-manager
70+ // DaemonSet and associated ConfigMaps.
4671 operator := NewOpenShiftControllerManagerOperator (
4772 os .Getenv ("IMAGE" ),
4873 operatorConfigInformers .Operator ().V1 ().OpenShiftControllerManagers (),
4974 configInformers .Config ().V1 ().Proxies (),
50- kubeInformers . InformersFor ( util . TargetNamespace ) ,
75+ kubeInformers ,
5176 operatorClient .OperatorV1 (),
5277 kubeClient ,
5378 controllerConfig .EventRecorder ,
@@ -69,6 +94,8 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
6994 controllerConfig .EventRecorder ,
7095 )
7196
97+ // ConfigObserver observes the configuration state from cluster config objects and transforms
98+ // them into configuration used by openshift-controller-manager
7299 configObserver := configobservationcontroller .NewConfigObserver (
73100 opClient ,
74101 operatorConfigInformers ,
@@ -89,6 +116,9 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
89116 openshiftControllerManagers : operatorClient .OperatorV1 ().OpenShiftControllerManagers (),
90117 version : os .Getenv ("RELEASE_VERSION" ),
91118 }
119+
120+ // ClusterOperatorStatusController aggregates the conditions in our openshiftcontrollermanager
121+ // object to the corresponding ClusterOperator object.
92122 clusterOperatorStatus := status .NewClusterOperatorStatusController (
93123 util .ClusterOperatorName ,
94124 []configv1.ObjectReference {
@@ -105,10 +135,43 @@ func RunOperator(ctx context.Context, controllerConfig *controllercmd.Controller
105135 controllerConfig .EventRecorder ,
106136 )
107137
138+ // StaticResourceController uses library-go's resourceapply package to reconcile a set of YAML
139+ // manifests against a cluster.
140+ // TODO: enhance resourceapply to use listers for RBAC APIs.
141+ staticResourceController := staticresourcecontroller .NewStaticResourceController (
142+ "OpenshiftControllerManagerStaticResources" ,
143+ v311_00_assets .Asset ,
144+ []string {
145+ "v3.11.0/openshift-controller-manager/informer-clusterrole.yaml" ,
146+ "v3.11.0/openshift-controller-manager/informer-clusterrolebinding.yaml" ,
147+ "v3.11.0/openshift-controller-manager/ingress-to-route-controller-clusterrole.yaml" ,
148+ "v3.11.0/openshift-controller-manager/ingress-to-route-controller-clusterrolebinding.yaml" ,
149+ "v3.11.0/openshift-controller-manager/tokenreview-clusterrole.yaml" ,
150+ "v3.11.0/openshift-controller-manager/tokenreview-clusterrolebinding.yaml" ,
151+ "v3.11.0/openshift-controller-manager/leader-role.yaml" ,
152+ "v3.11.0/openshift-controller-manager/leader-rolebinding.yaml" ,
153+ "v3.11.0/openshift-controller-manager/ns.yaml" ,
154+ "v3.11.0/openshift-controller-manager/old-leader-role.yaml" ,
155+ "v3.11.0/openshift-controller-manager/old-leader-rolebinding.yaml" ,
156+ "v3.11.0/openshift-controller-manager/separate-sa-role.yaml" ,
157+ "v3.11.0/openshift-controller-manager/separate-sa-rolebinding.yaml" ,
158+ "v3.11.0/openshift-controller-manager/sa.yaml" ,
159+ "v3.11.0/openshift-controller-manager/svc.yaml" ,
160+ "v3.11.0/openshift-controller-manager/servicemonitor-role.yaml" ,
161+ "v3.11.0/openshift-controller-manager/servicemonitor-rolebinding.yaml" ,
162+ "v3.11.0/openshift-controller-manager/buildconfigstatus-clusterrole.yaml" ,
163+ "v3.11.0/openshift-controller-manager/buildconfigstatus-clusterrolebinding.yaml" ,
164+ },
165+ resourceapply .NewKubeClientHolder (kubeClient ),
166+ opClient ,
167+ controllerConfig .EventRecorder ,
168+ ).AddKubeInformers (kubeInformers )
169+
108170 operatorConfigInformers .Start (ctx .Done ())
109171 kubeInformers .Start (ctx .Done ())
110172 configInformers .Start (ctx .Done ())
111173
174+ go staticResourceController .Run (ctx , 1 )
112175 go operator .Run (ctx , 1 )
113176 go resourceSyncer .Run (ctx , 1 )
114177 go configObserver .Run (ctx , 1 )
0 commit comments