1
1
package start
2
2
3
3
import (
4
- "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
4
+ "strconv"
5
+
6
+ "github.com/golang/glog"
7
+ "github.com/spf13/pflag"
8
+
9
+ kerrors "k8s.io/apimachinery/pkg/util/errors"
10
+ controllerapp "k8s.io/kubernetes/cmd/kube-controller-manager/app"
11
+ controlleroptions "k8s.io/kubernetes/cmd/kube-controller-manager/app/options"
5
12
"k8s.io/kubernetes/pkg/api/v1"
6
13
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
14
+ kubeexternalinformers "k8s.io/kubernetes/pkg/client/informers/informers_generated/externalversions"
15
+ "k8s.io/kubernetes/pkg/controller"
7
16
"k8s.io/kubernetes/pkg/volume"
17
+ _ "k8s.io/kubernetes/plugin/pkg/scheduler/algorithmprovider"
18
+
19
+ "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
20
+ cmdflags "github.com/openshift/origin/pkg/cmd/util/flags"
21
+ "k8s.io/kubernetes/pkg/apis/componentconfig"
8
22
)
9
23
10
24
// newPersistentVolumeRecyclerPodTemplate provides a function which makes our recycler pod template for use in the kube-controller-manager
@@ -26,3 +40,143 @@ func newPersistentVolumeRecyclerPodTemplate(recyclerImageName string) func() *v1
26
40
return defaultScrubPod
27
41
}
28
42
}
43
+
44
+ // newControllerContext provides a function which overrides the default and plugs a different set of informers in
45
+ func newControllerContext (kubeExternalInformers kubeexternalinformers.SharedInformerFactory ) func (s * controlleroptions.CMServer , rootClientBuilder , clientBuilder controller.ControllerClientBuilder , stop <- chan struct {}) (controllerapp.ControllerContext , error ) {
46
+ oldContextFunc := controllerapp .CreateControllerContext
47
+ return func (s * controlleroptions.CMServer , rootClientBuilder , clientBuilder controller.ControllerClientBuilder , stop <- chan struct {}) (controllerapp.ControllerContext , error ) {
48
+ ret , err := oldContextFunc (s , rootClientBuilder , clientBuilder , stop )
49
+ if err != nil {
50
+ return controllerapp.ControllerContext {}, err
51
+ }
52
+
53
+ // Overwrite the informers. Since nothing accessed the existing informers that we're overwriting, they are inert.
54
+ // TODO Remove this. It keeps in-process memory utilization down, but we shouldn't do it.
55
+ ret .InformerFactory = kubeExternalInformers
56
+
57
+ return ret , nil
58
+ }
59
+ }
60
+
61
+ func kubeControllerManagerAddFlags (cmserver * controlleroptions.CMServer ) func (flags * pflag.FlagSet ) {
62
+ return func (flags * pflag.FlagSet ) {
63
+ cmserver .AddFlags (flags , controllerapp .KnownControllers (), controllerapp .ControllersDisabledByDefault .List ())
64
+ }
65
+ }
66
+
67
+ func newKubeControllerManager (kubeconfigFile , saPrivateKeyFile , saRootCAFile , podEvictionTimeout string , dynamicProvisioningEnabled bool , cmdLineArgs map [string ][]string ) (* controlleroptions.CMServer , error ) {
68
+ if cmdLineArgs == nil {
69
+ cmdLineArgs = map [string ][]string {}
70
+ }
71
+
72
+ if _ , ok := cmdLineArgs ["controllers" ]; ! ok {
73
+ cmdLineArgs ["controllers" ] = []string {
74
+ "*" , // start everything but the exceptions}
75
+ // we don't appear to use this
76
+ "-ttl" ,
77
+ // we have to configure this separately until it is generic
78
+ "-horizontalpodautoscaling" ,
79
+ // we carry patches on this. For now....
80
+ "-serviceaccount-token" ,
81
+ }
82
+ }
83
+ if _ , ok := cmdLineArgs ["service-account-private-key-file" ]; ! ok {
84
+ cmdLineArgs ["service-account-private-key-file" ] = []string {saPrivateKeyFile }
85
+ }
86
+ if _ , ok := cmdLineArgs ["root-ca-file" ]; ! ok {
87
+ cmdLineArgs ["root-ca-file" ] = []string {saRootCAFile }
88
+ }
89
+ if _ , ok := cmdLineArgs ["kubeconfig" ]; ! ok {
90
+ cmdLineArgs ["kubeconfig" ] = []string {kubeconfigFile }
91
+ }
92
+ if _ , ok := cmdLineArgs ["pod-eviction-timeout" ]; ! ok {
93
+ cmdLineArgs ["pod-eviction-timeout" ] = []string {podEvictionTimeout }
94
+ }
95
+ if _ , ok := cmdLineArgs ["enable-dynamic-provisioning" ]; ! ok {
96
+ cmdLineArgs ["enable-dynamic-provisioning" ] = []string {strconv .FormatBool (dynamicProvisioningEnabled )}
97
+ }
98
+
99
+ // disable serving http since we didn't used to expose it
100
+ if _ , ok := cmdLineArgs ["port" ]; ! ok {
101
+ cmdLineArgs ["port" ] = []string {"-1" }
102
+ }
103
+
104
+ // these force "default" values to match what we want
105
+ if _ , ok := cmdLineArgs ["use-service-account-credentials" ]; ! ok {
106
+ cmdLineArgs ["use-service-account-credentials" ] = []string {"true" }
107
+ }
108
+ if _ , ok := cmdLineArgs ["cluster-signing-cert-file" ]; ! ok {
109
+ cmdLineArgs ["cluster-signing-cert-file" ] = []string {"" }
110
+ }
111
+ if _ , ok := cmdLineArgs ["cluster-signing-key-file" ]; ! ok {
112
+ cmdLineArgs ["cluster-signing-key-file" ] = []string {"" }
113
+ }
114
+ if _ , ok := cmdLineArgs ["experimental-cluster-signing-duration" ]; ! ok {
115
+ cmdLineArgs ["experimental-cluster-signing-duration" ] = []string {"0s" }
116
+ }
117
+ if _ , ok := cmdLineArgs ["leader-elect-retry-period" ]; ! ok {
118
+ cmdLineArgs ["leader-elect-retry-period" ] = []string {"3s" }
119
+ }
120
+ if _ , ok := cmdLineArgs ["leader-elect-resource-lock" ]; ! ok {
121
+ cmdLineArgs ["leader-elect-resource-lock" ] = []string {"configmaps" }
122
+ }
123
+
124
+ // resolve arguments
125
+ controllerManager := controlleroptions .NewCMServer ()
126
+ if err := cmdflags .Resolve (cmdLineArgs , kubeControllerManagerAddFlags (controllerManager )); len (err ) > 0 {
127
+ return nil , kerrors .NewAggregate (err )
128
+ }
129
+
130
+ // TODO make this configurable or discoverable. This is going to prevent us from running the stock GC controller
131
+ // IF YOU ADD ANYTHING TO THIS LIST, MAKE SURE THAT YOU UPDATE THEIR STRATEGIES TO PREVENT GC FINALIZERS
132
+ controllerManager .GCIgnoredResources = append (controllerManager .GCIgnoredResources ,
133
+ // explicitly disabled from GC for now - not enough value to track them
134
+ componentconfig.GroupResource {Group : "authorization.openshift.io" , Resource : "rolebindingrestrictions" },
135
+ componentconfig.GroupResource {Group : "network.openshift.io" , Resource : "clusternetworks" },
136
+ componentconfig.GroupResource {Group : "network.openshift.io" , Resource : "egressnetworkpolicies" },
137
+ componentconfig.GroupResource {Group : "network.openshift.io" , Resource : "hostsubnets" },
138
+ componentconfig.GroupResource {Group : "network.openshift.io" , Resource : "netnamespaces" },
139
+ componentconfig.GroupResource {Group : "oauth.openshift.io" , Resource : "oauthclientauthorizations" },
140
+ componentconfig.GroupResource {Group : "oauth.openshift.io" , Resource : "oauthclients" },
141
+ componentconfig.GroupResource {Group : "quota.openshift.io" , Resource : "clusterresourcequotas" },
142
+ componentconfig.GroupResource {Group : "user.openshift.io" , Resource : "groups" },
143
+ componentconfig.GroupResource {Group : "user.openshift.io" , Resource : "identities" },
144
+ componentconfig.GroupResource {Group : "user.openshift.io" , Resource : "users" },
145
+ componentconfig.GroupResource {Group : "image.openshift.io" , Resource : "images" },
146
+
147
+ // virtual resource
148
+ componentconfig.GroupResource {Group : "project.openshift.io" , Resource : "projects" },
149
+ // these resources contain security information in their names, and we don't need to track them
150
+ componentconfig.GroupResource {Group : "oauth.openshift.io" , Resource : "oauthaccesstokens" },
151
+ componentconfig.GroupResource {Group : "oauth.openshift.io" , Resource : "oauthauthorizetokens" },
152
+ // exposed already as cronjobs
153
+ componentconfig.GroupResource {Group : "batch" , Resource : "scheduledjobs" },
154
+ // exposed already as extensions v1beta1 by other controllers
155
+ componentconfig.GroupResource {Group : "apps" , Resource : "deployments" },
156
+ // exposed as autoscaling v1
157
+ componentconfig.GroupResource {Group : "extensions" , Resource : "horizontalpodautoscalers" },
158
+ )
159
+
160
+ return controllerManager , nil
161
+ }
162
+
163
+ func runEmbeddedKubeControllerManager (kubeconfigFile , saPrivateKeyFile , saRootCAFile , podEvictionTimeout string , dynamicProvisioningEnabled bool , cmdLineArgs map [string ][]string ,
164
+ recyclerImage string , kubeExternalInformers kubeexternalinformers.SharedInformerFactory ) {
165
+ volume .NewPersistentVolumeRecyclerPodTemplate = newPersistentVolumeRecyclerPodTemplate (recyclerImage )
166
+ controllerapp .CreateControllerContext = newControllerContext (kubeExternalInformers )
167
+
168
+ for {
169
+ // TODO we need a real identity for this. Right now it's just using the loopback connection like it used to.
170
+ controllerManager , err := newKubeControllerManager (kubeconfigFile , saPrivateKeyFile , saRootCAFile , podEvictionTimeout , dynamicProvisioningEnabled , cmdLineArgs )
171
+ if err != nil {
172
+ glog .Error (err )
173
+ continue
174
+ }
175
+ // this does a second leader election, but doing the second leader election will allow us to move out process in
176
+ // 3.8 if we so choose.
177
+ if err := controllerapp .Run (controllerManager ); err != nil {
178
+ glog .Error (err )
179
+ continue
180
+ }
181
+ }
182
+ }
0 commit comments