11package controller
22
33import (
4- "fmt"
5- "io/ioutil"
64 "path"
75 "time"
86
97 "k8s.io/apimachinery/pkg/runtime/schema"
10- "k8s.io/client-go/util/cert"
118 "k8s.io/kubernetes/pkg/api/legacyscheme"
129 kapi "k8s.io/kubernetes/pkg/apis/core"
13- kcontroller "k8s.io/kubernetes/pkg/controller"
1410 serviceaccountadmission "k8s.io/kubernetes/plugin/pkg/admission/serviceaccount"
1511
1612 configapi "github.com/openshift/origin/pkg/cmd/server/apis/config"
17- "github.com/openshift/origin/pkg/cmd/server/crypto"
1813 "github.com/openshift/origin/pkg/cmd/util/variable"
1914)
2015
@@ -56,8 +51,6 @@ func getOpenShiftClientEnvVars(options configapi.MasterConfig) ([]kapi.EnvVar, e
5651// OpenshiftControllerConfig is the runtime (non-serializable) config object used to
5752// launch the set of openshift (not kube) controllers.
5853type OpenshiftControllerConfig struct {
59- ServiceAccountTokenControllerOptions ServiceAccountTokenControllerOptions
60-
6154 ServiceAccountControllerOptions ServiceAccountControllerOptions
6255
6356 BuildControllerConfig BuildControllerConfig
@@ -83,8 +76,6 @@ type OpenshiftControllerConfig struct {
8376func (c * OpenshiftControllerConfig ) GetControllerInitializers () (map [string ]InitFunc , error ) {
8477 ret := map [string ]InitFunc {}
8578
86- ret ["openshift.io/serviceaccount" ] = c .ServiceAccountControllerOptions .RunController
87-
8879 ret ["openshift.io/serviceaccount-pull-secrets" ] = RunServiceAccountPullSecretsController
8980 ret ["openshift.io/origin-namespace" ] = RunOriginNamespaceController
9081 ret ["openshift.io/service-serving-cert" ] = c .ServiceServingCertsControllerOptions .RunController
@@ -115,63 +106,10 @@ func (c *OpenshiftControllerConfig) GetControllerInitializers() (map[string]Init
115106 return ret , nil
116107}
117108
118- // NewOpenShiftControllerPreStartInitializers returns list of initializers for controllers
119- // that needed to be run before any other controller is started.
120- // Typically this has to done for the serviceaccount-token controller as it provides
121- // tokens to other controllers.
122- func (c * OpenshiftControllerConfig ) ServiceAccountContentControllerInit () InitFunc {
123- return c .ServiceAccountTokenControllerOptions .RunController
124- }
125-
126109func BuildOpenshiftControllerConfig (options configapi.MasterConfig ) (* OpenshiftControllerConfig , error ) {
127110 var err error
128111 ret := & OpenshiftControllerConfig {}
129112
130- _ , loopbackClientConfig , err := configapi .GetInternalKubeClient (options .MasterClients .OpenShiftLoopbackKubeConfig , options .MasterClients .OpenShiftLoopbackClientConnectionOverrides )
131- if err != nil {
132- return nil , err
133- }
134-
135- ret .ServiceAccountTokenControllerOptions = ServiceAccountTokenControllerOptions {
136- RootClientBuilder : kcontroller.SimpleControllerClientBuilder {
137- ClientConfig : loopbackClientConfig ,
138- },
139- }
140- if len (options .ServiceAccountConfig .PrivateKeyFile ) > 0 {
141- ret .ServiceAccountTokenControllerOptions .PrivateKey , err = cert .PrivateKeyFromFile (options .ServiceAccountConfig .PrivateKeyFile )
142- if err != nil {
143- return nil , fmt .Errorf ("error reading signing key for Service Account Token Manager: %v" , err )
144- }
145- }
146- if len (options .ServiceAccountConfig .MasterCA ) > 0 {
147- ret .ServiceAccountTokenControllerOptions .RootCA , err = ioutil .ReadFile (options .ServiceAccountConfig .MasterCA )
148- if err != nil {
149- return nil , fmt .Errorf ("error reading master ca file for Service Account Token Manager: %s: %v" , options .ServiceAccountConfig .MasterCA , err )
150- }
151- if _ , err := cert .ParseCertsPEM (ret .ServiceAccountTokenControllerOptions .RootCA ); err != nil {
152- return nil , fmt .Errorf ("error parsing master ca file for Service Account Token Manager: %s: %v" , options .ServiceAccountConfig .MasterCA , err )
153- }
154- }
155- if options .ControllerConfig .ServiceServingCert .Signer != nil && len (options .ControllerConfig .ServiceServingCert .Signer .CertFile ) > 0 {
156- certFile := options .ControllerConfig .ServiceServingCert .Signer .CertFile
157- serviceServingCA , err := ioutil .ReadFile (certFile )
158- if err != nil {
159- return nil , fmt .Errorf ("error reading ca file for Service Serving Certificate Signer: %s: %v" , certFile , err )
160- }
161- if _ , err := crypto .CertsFromPEM (serviceServingCA ); err != nil {
162- return nil , fmt .Errorf ("error parsing ca file for Service Serving Certificate Signer: %s: %v" , certFile , err )
163- }
164-
165- // if we have a rootCA bundle add that too. The rootCA will be used when hitting the default master service, since those are signed
166- // using a different CA by default. The rootCA's key is more closely guarded than ours and if it is compromised, that power could
167- // be used to change the trusted signers for every pod anyway, so we're already effectively trusting it.
168- if len (ret .ServiceAccountTokenControllerOptions .RootCA ) > 0 {
169- ret .ServiceAccountTokenControllerOptions .ServiceServingCA = append (ret .ServiceAccountTokenControllerOptions .ServiceServingCA , ret .ServiceAccountTokenControllerOptions .RootCA ... )
170- ret .ServiceAccountTokenControllerOptions .ServiceServingCA = append (ret .ServiceAccountTokenControllerOptions .ServiceServingCA , []byte ("\n " )... )
171- }
172- ret .ServiceAccountTokenControllerOptions .ServiceServingCA = append (ret .ServiceAccountTokenControllerOptions .ServiceServingCA , serviceServingCA ... )
173- }
174-
175113 ret .ServiceAccountControllerOptions = ServiceAccountControllerOptions {
176114 ManagedNames : options .ServiceAccountConfig .ManagedNames ,
177115 }
0 commit comments