Skip to content

Commit fe8d172

Browse files
Merge pull request #20074 from sttts/sttts-kube-loopback-in-openshift-kube-apiserver
openshift-kube-apiserver: use in-process loopback client config from Kube
2 parents d4e8f05 + a00191a commit fe8d172

File tree

3 files changed

+44
-44
lines changed

3 files changed

+44
-44
lines changed

pkg/cmd/openshift-kube-apiserver/server.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,7 @@ func RunOpenShiftKubeAPIServerServer(masterConfig *configapi.MasterConfig) error
4343
return kerrors.NewInvalid(configapi.Kind("MasterConfig"), "master-config.yaml", validationResults.Errors)
4444
}
4545

46-
// informers are shared amongst all the various api components we build
47-
// TODO the needs of the apiserver and the controllers are drifting. We should consider two different skins here
48-
clientConfig, err := configapi.GetClientConfig(masterConfig.MasterClients.OpenShiftLoopbackKubeConfig, masterConfig.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
49-
if err != nil {
50-
return err
51-
}
52-
informers, err := origin.NewInformers(clientConfig)
53-
if err != nil {
54-
return err
55-
}
56-
if err := informers.AddUserIndexes(); err != nil {
57-
return err
58-
}
59-
46+
informers := origin.InformerAccess(nil) // use real kube-apiserver loopback client with secret token instead of that from masterConfig.MasterClients.OpenShiftLoopbackKubeConfig
6047
openshiftConfig, err := origin.BuildMasterConfig(*masterConfig, informers)
6148
if err != nil {
6249
return err

pkg/cmd/server/kubernetes/master/master_config.go

+24-28
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
auditlog "k8s.io/apiserver/plugin/pkg/audit/log"
4949
auditwebhook "k8s.io/apiserver/plugin/pkg/audit/webhook"
5050
pluginwebhook "k8s.io/apiserver/plugin/pkg/audit/webhook"
51+
"k8s.io/client-go/rest"
5152
"k8s.io/kube-aggregator/pkg/apis/apiregistration"
5253
apiregistrationv1beta1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
5354
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
@@ -377,12 +378,13 @@ func buildPublicAddress(masterConfig configapi.MasterConfig) (net.IP, error) {
377378
return publicAddress, nil
378379
}
379380

380-
func buildKubeApiserverConfig(
381-
masterConfig configapi.MasterConfig,
382-
admissionControl admission.Interface,
383-
originAuthenticator authenticator.Request,
384-
kubeAuthorizer authorizer.Authorizer,
385-
) (*master.Config, error) {
381+
type incompleteKubeMasterConfig struct {
382+
options *kapiserveroptions.ServerRunOptions
383+
incompleteConfig *apiserver.Config
384+
masterConfig configapi.MasterConfig
385+
}
386+
387+
func BuildKubernetesMasterConfig(masterConfig configapi.MasterConfig) (*incompleteKubeMasterConfig, error) {
386388
apiserverOptions, err := BuildKubeAPIserverOptions(masterConfig)
387389
if err != nil {
388390
return nil, err
@@ -393,6 +395,20 @@ func buildKubeApiserverConfig(
393395
return nil, err
394396
}
395397

398+
return &incompleteKubeMasterConfig{apiserverOptions, genericConfig, masterConfig}, nil
399+
}
400+
401+
func (rc *incompleteKubeMasterConfig) LoopbackConfig() *rest.Config {
402+
return rc.incompleteConfig.LoopbackClientConfig
403+
}
404+
405+
func (rc *incompleteKubeMasterConfig) Complete(
406+
admissionControl admission.Interface,
407+
originAuthenticator authenticator.Request,
408+
kubeAuthorizer authorizer.Authorizer,
409+
) (*master.Config, error) {
410+
genericConfig, apiserverOptions, masterConfig := rc.incompleteConfig, rc.options, rc.masterConfig
411+
396412
proxyClientCerts, err := buildProxyClientCerts(masterConfig)
397413
if err != nil {
398414
return nil, err
@@ -567,33 +583,13 @@ func buildKubeApiserverConfig(
567583
)
568584
}
569585

570-
return kubeApiserverConfig, nil
571-
}
572-
573-
// TODO this function's parameters need to be refactored
574-
func BuildKubernetesMasterConfig(
575-
masterConfig configapi.MasterConfig,
576-
admissionControl admission.Interface,
577-
originAuthenticator authenticator.Request,
578-
kubeAuthorizer authorizer.Authorizer,
579-
) (*master.Config, error) {
580-
apiserverConfig, err := buildKubeApiserverConfig(
581-
masterConfig,
582-
admissionControl,
583-
originAuthenticator,
584-
kubeAuthorizer,
585-
)
586-
if err != nil {
587-
return nil, err
588-
}
589-
590586
// we do this for integration tests to be able to turn it off for better startup speed
591587
// TODO remove the entire option once openapi is faster
592588
if masterConfig.DisableOpenAPI {
593-
apiserverConfig.GenericConfig.OpenAPIConfig = nil
589+
kubeApiserverConfig.GenericConfig.OpenAPIConfig = nil
594590
}
595591

596-
return apiserverConfig, nil
592+
return kubeApiserverConfig, nil
597593
}
598594

599595
func defaultOpenAPIConfig(config configapi.MasterConfig) *openapicommon.Config {

pkg/cmd/server/origin/master_config.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,24 @@ func BuildMasterConfig(
132132
options configapi.MasterConfig,
133133
informers InformerAccess,
134134
) (*MasterConfig, error) {
135+
incompleteKubeAPIServerConfig, err := kubernetes.BuildKubernetesMasterConfig(options)
136+
if err != nil {
137+
return nil, err
138+
}
139+
if informers == nil {
140+
// use the real Kubernetes loopback client (using a secret token and preferibly localhost networking), not
141+
// the one provided by options.MasterClients.OpenShiftLoopbackKubeConfig. The latter is meant for out-of-process
142+
// components of the master.
143+
realLoopbackInformers, err := NewInformers(incompleteKubeAPIServerConfig.LoopbackConfig())
144+
if err != nil {
145+
return nil, err
146+
}
147+
if err := realLoopbackInformers.AddUserIndexes(); err != nil {
148+
return nil, err
149+
}
150+
informers = realLoopbackInformers
151+
}
152+
135153
restOptsGetter, err := originrest.StorageOptions(options)
136154
if err != nil {
137155
return nil, err
@@ -189,8 +207,7 @@ func BuildMasterConfig(
189207
return nil, err
190208
}
191209

192-
kubeAPIServerConfig, err := kubernetes.BuildKubernetesMasterConfig(
193-
options,
210+
kubeAPIServerConfig, err := incompleteKubeAPIServerConfig.Complete(
194211
admission,
195212
authenticator,
196213
authorizer,

0 commit comments

Comments
 (0)