Skip to content

Commit 75c64e3

Browse files
Merge pull request #16516 from deads2k/client-06-cmd-snips
Automatic merge from submit-queue remove legacy client usage Cleans up a bunch of different legacy client usage.
2 parents 1bec7c1 + d894a3e commit 75c64e3

File tree

19 files changed

+218
-298
lines changed

19 files changed

+218
-298
lines changed

pkg/apps/client/v1/scale.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package v1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
extensionsv1beta1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
6+
kextensionsclient "k8s.io/kubernetes/pkg/client/clientset_generated/clientset/typed/extensions/v1beta1"
7+
8+
appstypedclient "github.com/openshift/origin/pkg/apps/generated/clientset/typed/apps/v1"
9+
)
10+
11+
type delegatingScaleInterface struct {
12+
dcs appstypedclient.DeploymentConfigInterface
13+
scales kextensionsclient.ScaleInterface
14+
}
15+
16+
type delegatingScaleNamespacer struct {
17+
dcNS appstypedclient.DeploymentConfigsGetter
18+
scaleNS kextensionsclient.ScalesGetter
19+
}
20+
21+
func (c *delegatingScaleNamespacer) Scales(namespace string) kextensionsclient.ScaleInterface {
22+
return &delegatingScaleInterface{
23+
dcs: c.dcNS.DeploymentConfigs(namespace),
24+
scales: c.scaleNS.Scales(namespace),
25+
}
26+
}
27+
28+
func NewDelegatingScaleNamespacer(dcNamespacer appstypedclient.DeploymentConfigsGetter, sNamespacer kextensionsclient.ScalesGetter) kextensionsclient.ScalesGetter {
29+
return &delegatingScaleNamespacer{
30+
dcNS: dcNamespacer,
31+
scaleNS: sNamespacer,
32+
}
33+
}
34+
35+
// Get takes the reference to scale subresource and returns the subresource or error, if one occurs.
36+
func (c *delegatingScaleInterface) Get(kind string, name string) (result *extensionsv1beta1.Scale, err error) {
37+
switch {
38+
case kind == "DeploymentConfig":
39+
return c.dcs.GetScale(name, metav1.GetOptions{})
40+
// TODO: This is borked because the interface for Get is broken. Kind is insufficient.
41+
default:
42+
return c.scales.Get(kind, name)
43+
}
44+
}
45+
46+
// Update takes a scale subresource object, updates the stored version to match it, and
47+
// returns the subresource or error, if one occurs.
48+
func (c *delegatingScaleInterface) Update(kind string, scale *extensionsv1beta1.Scale) (result *extensionsv1beta1.Scale, err error) {
49+
switch {
50+
case kind == "DeploymentConfig":
51+
return c.dcs.UpdateScale(scale.Name, scale)
52+
// TODO: This is borked because the interface for Update is broken. Kind is insufficient.
53+
default:
54+
return c.scales.Update(kind, scale)
55+
}
56+
}

pkg/cmd/server/api/helpers.go

-71
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
kclientsetinternal "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
2121
kubeletclient "k8s.io/kubernetes/pkg/kubelet/client"
2222

23-
"github.com/openshift/origin/pkg/client"
2423
cmdutil "github.com/openshift/origin/pkg/cmd/util"
2524
)
2625

@@ -379,30 +378,6 @@ func GetExternalKubeClient(kubeConfigFile string, overrides *ClientConnectionOve
379378
return clientset, kubeConfig, nil
380379
}
381380

382-
// TODO: clients should be copied and instantiated from a common client config, tweaked, then
383-
// given to individual controllers and other infrastructure components. Overrides are optional
384-
// and may alter the default configuration.
385-
func GetOpenShiftClient(kubeConfigFile string, overrides *ClientConnectionOverrides) (*client.Client, *restclient.Config, error) {
386-
loadingRules := &clientcmd.ClientConfigLoadingRules{}
387-
loadingRules.ExplicitPath = kubeConfigFile
388-
loader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, &clientcmd.ConfigOverrides{})
389-
390-
kubeConfig, err := loader.ClientConfig()
391-
if err != nil {
392-
return nil, nil, err
393-
}
394-
395-
applyClientConnectionOverrides(overrides, kubeConfig)
396-
397-
kubeConfig.WrapTransport = DefaultClientTransport
398-
openshiftClient, err := client.New(kubeConfig)
399-
if err != nil {
400-
return nil, nil, err
401-
}
402-
403-
return openshiftClient, kubeConfig, nil
404-
}
405-
406381
// applyClientConnectionOverrides updates a kubeConfig with the overrides from the config.
407382
func applyClientConnectionOverrides(overrides *ClientConnectionOverrides, kubeConfig *restclient.Config) {
408383
if overrides == nil {
@@ -455,31 +430,6 @@ func GetNamedCertificateMap(namedCertificates []NamedCertificate) (map[string]*t
455430
return namedCerts, nil
456431
}
457432

458-
// GetClientCertCAPool returns a cert pool containing all client CAs that could be presented (union of API and OAuth)
459-
func GetClientCertCAPool(options MasterConfig) (*x509.CertPool, error) {
460-
roots := x509.NewCertPool()
461-
462-
// Add CAs for OAuth
463-
certs, err := GetOAuthClientCertCAs(options)
464-
if err != nil {
465-
return nil, err
466-
}
467-
for _, root := range certs {
468-
roots.AddCert(root)
469-
}
470-
471-
// Add CAs for API
472-
certs, err = getAPIClientCertCAs(options)
473-
if err != nil {
474-
return nil, err
475-
}
476-
for _, root := range certs {
477-
roots.AddCert(root)
478-
}
479-
480-
return roots, nil
481-
}
482-
483433
func GetOAuthClientCertCAs(options MasterConfig) ([]*x509.Certificate, error) {
484434
allCerts := []*x509.Certificate{}
485435

@@ -504,22 +454,6 @@ func GetOAuthClientCertCAs(options MasterConfig) ([]*x509.Certificate, error) {
504454
return allCerts, nil
505455
}
506456

507-
func GetRequestHeaderClientCertCAs(options MasterConfig) ([]*x509.Certificate, error) {
508-
if options.AuthConfig.RequestHeader == nil {
509-
return nil, nil
510-
}
511-
512-
certs, err := cmdutil.CertificatesFromFile(options.AuthConfig.RequestHeader.ClientCA)
513-
if err != nil {
514-
return nil, fmt.Errorf("Error reading %s: %s", options.AuthConfig.RequestHeader.ClientCA, err)
515-
}
516-
return certs, nil
517-
}
518-
519-
func getAPIClientCertCAs(options MasterConfig) ([]*x509.Certificate, error) {
520-
return cmdutil.CertificatesFromFile(options.ServingInfo.ClientCA)
521-
}
522-
523457
func GetKubeletClientConfig(options MasterConfig) *kubeletclient.KubeletClientConfig {
524458
config := &kubeletclient.KubeletClientConfig{
525459
Port: options.KubeletClientInfo.Port,
@@ -595,11 +529,6 @@ func IsOAuthIdentityProvider(provider IdentityProvider) bool {
595529
return false
596530
}
597531

598-
func HasOpenShiftAPILevel(config MasterConfig, apiLevel string) bool {
599-
apiLevelSet := sets.NewString(config.APILevels...)
600-
return apiLevelSet.Has(apiLevel)
601-
}
602-
603532
const kubeAPIEnablementFlag = "runtime-config"
604533

605534
// GetKubeAPIServerFlagAPIEnablement parses the available flag at the groupVersion level

pkg/cmd/server/origin/controller/autoscaling.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package controller
22

33
import (
4+
clientgoclientset "k8s.io/client-go/kubernetes"
5+
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
46
hpacontroller "k8s.io/kubernetes/pkg/controller/podautoscaler"
57
hpametrics "k8s.io/kubernetes/pkg/controller/podautoscaler/metrics"
68

7-
osclient "github.com/openshift/origin/pkg/client"
9+
appsv1client "github.com/openshift/origin/pkg/apps/client/v1"
10+
appstypedclient "github.com/openshift/origin/pkg/apps/generated/clientset/typed/apps/v1"
811
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
9-
clientgoclientset "k8s.io/client-go/kubernetes"
10-
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
1112
)
1213

1314
// NB: this is funky -- it's actually a Kubernetes controller, but we run it as an OpenShift controller in order
@@ -26,13 +27,10 @@ func (c *HorizontalPodAutoscalerControllerConfig) RunController(originCtx Contro
2627
if err != nil {
2728
return false, err
2829
}
29-
30-
// use the Kubernetes config so that the service account is in the same name namespace for both clients
31-
hpaOriginClient, err := osclient.New(hpaClientConfig)
30+
appsClient, err := appstypedclient.NewForConfig(hpaClientConfig)
3231
if err != nil {
3332
return false, err
3433
}
35-
3634
hpaEventsClient, err := clientgoclientset.NewForConfig(hpaClientConfig)
3735
if err != nil {
3836
return false, err
@@ -47,7 +45,7 @@ func (c *HorizontalPodAutoscalerControllerConfig) RunController(originCtx Contro
4745
)
4846
replicaCalc := hpacontroller.NewReplicaCalculator(metricsClient, hpaClient.Core())
4947

50-
delegatingScalesGetter := osclient.NewDelegatingScaleNamespacer(hpaOriginClient, hpaClient.ExtensionsV1beta1())
48+
delegatingScalesGetter := appsv1client.NewDelegatingScaleNamespacer(appsClient, hpaClient.ExtensionsV1beta1())
5149

5250
go hpacontroller.NewHorizontalController(
5351
hpaEventsClient.Core(),

pkg/cmd/server/origin/controller/interfaces.go

-21
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
1515
buildinformer "github.com/openshift/origin/pkg/build/generated/informers/internalversion"
1616
buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset"
17-
osclient "github.com/openshift/origin/pkg/client"
1817
imageinformer "github.com/openshift/origin/pkg/image/generated/informers/internalversion"
1918
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
2019
networkclientinternal "github.com/openshift/origin/pkg/network/generated/internalclientset"
@@ -55,10 +54,6 @@ type ControllerClientBuilder interface {
5554
KubeInternalClient(name string) (kclientsetinternal.Interface, error)
5655
KubeInternalClientOrDie(name string) kclientsetinternal.Interface
5756

58-
// Legacy OpenShift client (pkg/client)
59-
DeprecatedOpenshiftClient(name string) (osclient.Interface, error)
60-
DeprecatedOpenshiftClientOrDie(name string) osclient.Interface
61-
6257
OpenshiftInternalAppsClient(name string) (appsclientinternal.Interface, error)
6358
OpenshiftInternalAppsClientOrDie(name string) appsclientinternal.Interface
6459

@@ -104,22 +99,6 @@ func (b OpenshiftControllerClientBuilder) KubeInternalClientOrDie(name string) k
10499
return client
105100
}
106101

107-
func (b OpenshiftControllerClientBuilder) DeprecatedOpenshiftClient(name string) (osclient.Interface, error) {
108-
clientConfig, err := b.Config(name)
109-
if err != nil {
110-
return nil, err
111-
}
112-
return osclient.New(clientConfig)
113-
}
114-
115-
func (b OpenshiftControllerClientBuilder) DeprecatedOpenshiftClientOrDie(name string) osclient.Interface {
116-
client, err := b.DeprecatedOpenshiftClient(name)
117-
if err != nil {
118-
glog.Fatal(err)
119-
}
120-
return client
121-
}
122-
123102
// OpenshiftInternalTemplateClient provides a REST client for the template API.
124103
// If the client cannot be created because of configuration error, this function
125104
// will return an error.

pkg/cmd/server/origin/controller/unidling.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package controller
33
import (
44
"time"
55

6+
appsv1client "github.com/openshift/origin/pkg/apps/client/v1"
7+
appstypedclient "github.com/openshift/origin/pkg/apps/generated/clientset/typed/apps/v1"
68
deployclient "github.com/openshift/origin/pkg/apps/generated/internalclientset/typed/apps/internalversion"
7-
osclient "github.com/openshift/origin/pkg/client"
89
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
910
unidlingcontroller "github.com/openshift/origin/pkg/unidling/controller"
1011
)
@@ -14,10 +15,15 @@ type UnidlingControllerConfig struct {
1415
}
1516

1617
func (c *UnidlingControllerConfig) RunController(ctx ControllerContext) (bool, error) {
17-
scaleNamespacer := osclient.NewDelegatingScaleNamespacer(
18-
ctx.ClientBuilder.DeprecatedOpenshiftClientOrDie(bootstrappolicy.InfraUnidlingControllerServiceAccountName),
19-
ctx.ClientBuilder.ClientOrDie(bootstrappolicy.InfraUnidlingControllerServiceAccountName).Extensions(),
20-
)
18+
clientConfig := ctx.ClientBuilder.ConfigOrDie(bootstrappolicy.InfraUnidlingControllerServiceAccountName)
19+
appsClient, err := appstypedclient.NewForConfig(clientConfig)
20+
if err != nil {
21+
return false, err
22+
}
23+
24+
scaleNamespacer := appsv1client.NewDelegatingScaleNamespacer(appsClient,
25+
ctx.ClientBuilder.ClientOrDie(bootstrappolicy.InfraUnidlingControllerServiceAccountName).ExtensionsV1beta1())
26+
2127
coreClient := ctx.ClientBuilder.KubeInternalClientOrDie(bootstrappolicy.InfraUnidlingControllerServiceAccountName).Core()
2228
controller := unidlingcontroller.NewUnidlingController(
2329
scaleNamespacer,

pkg/cmd/server/origin/ensure.go

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
package origin
22

33
import (
4-
"github.com/golang/glog"
5-
6-
kapierror "k8s.io/apimachinery/pkg/api/errors"
7-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
84
genericapiserver "k8s.io/apiserver/pkg/server"
9-
kapi "k8s.io/kubernetes/pkg/api"
105
)
116

127
// ensureOpenShiftSharedResourcesNamespace is called as part of global policy initialization to ensure shared namespace exists
138
func (c *MasterConfig) ensureOpenShiftSharedResourcesNamespace(context genericapiserver.PostStartHookContext) error {
14-
if _, err := c.PrivilegedLoopbackKubernetesClientsetInternal.Core().Namespaces().Get(c.Options.PolicyConfig.OpenShiftSharedResourcesNamespace, metav1.GetOptions{}); kapierror.IsNotFound(err) {
15-
namespace, createErr := c.PrivilegedLoopbackKubernetesClientsetInternal.Core().Namespaces().Create(&kapi.Namespace{ObjectMeta: metav1.ObjectMeta{Name: c.Options.PolicyConfig.OpenShiftSharedResourcesNamespace}})
16-
if createErr != nil {
17-
glog.Errorf("Error creating namespace: %v due to %v\n", c.Options.PolicyConfig.OpenShiftSharedResourcesNamespace, createErr)
18-
return nil
19-
}
20-
21-
EnsureNamespaceServiceAccountRoleBindings(c.PrivilegedLoopbackKubernetesClientsetInternal, c.PrivilegedLoopbackOpenShiftClient, namespace)
22-
}
9+
ensureNamespaceServiceAccountRoleBindings(context, c.Options.PolicyConfig.OpenShiftSharedResourcesNamespace)
2310
return nil
2411
}

pkg/cmd/server/origin/master.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ func (c *MasterConfig) newOpenshiftAPIConfig(kubeAPIServerConfig apiserver.Confi
5959
KubeInternalInformers: c.InternalKubeInformers,
6060
QuotaInformers: c.QuotaInformers,
6161
SecurityInformers: c.SecurityInformers,
62-
DeprecatedOpenshiftClient: c.PrivilegedLoopbackOpenShiftClient,
6362
RuleResolver: c.RuleResolver,
6463
SubjectLocator: c.SubjectLocator,
6564
LimitVerifier: c.LimitVerifier,
@@ -339,9 +338,8 @@ func (c *MasterConfig) withOAuthRedirection(handler, oauthServerHandler http.Han
339338

340339
// RouteAllocator returns a route allocation controller.
341340
func (c *MasterConfig) RouteAllocator() *routeallocationcontroller.RouteAllocationController {
342-
_, kclient := c.RouteAllocatorClients()
343341
factory := routeallocationcontroller.RouteAllocationControllerFactory{
344-
KubeClient: kclient,
342+
KubeClient: c.PrivilegedLoopbackKubernetesClientsetInternal,
345343
}
346344

347345
plugin, err := routeplugin.NewSimpleAllocationPlugin(c.Options.RoutingConfig.Subdomain)

pkg/cmd/server/origin/master_config.go

+1-24
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ import (
7171
authorizationinformer "github.com/openshift/origin/pkg/authorization/generated/informers/internalversion"
7272
authorizationclient "github.com/openshift/origin/pkg/authorization/generated/internalclientset"
7373
buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset"
74-
osclient "github.com/openshift/origin/pkg/client"
7574
oadmission "github.com/openshift/origin/pkg/cmd/server/admission"
7675
configapi "github.com/openshift/origin/pkg/cmd/server/api"
7776
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
@@ -154,11 +153,6 @@ type MasterConfig struct {
154153
// different access control to a system component, create a separate client/config specifically for
155154
// that component.
156155
PrivilegedLoopbackKubernetesClientsetExternal kclientsetexternal.Interface
157-
// PrivilegedLoopbackOpenShiftClient is the client used to call OpenShift APIs from system components,
158-
// built from PrivilegedLoopbackClientConfig. It should only be accessed via the *TestingClient() helper methods.
159-
// To apply different access control to a system component, create a separate client/config specifically
160-
// for that component.
161-
PrivilegedLoopbackOpenShiftClient *osclient.Client
162156

163157
AuditBackend audit.Backend
164158

@@ -194,11 +188,7 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
194188
if err != nil {
195189
return nil, err
196190
}
197-
privilegedLoopbackKubeClientsetExternal, _, err := configapi.GetExternalKubeClient(options.MasterClients.OpenShiftLoopbackKubeConfig, options.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
198-
if err != nil {
199-
return nil, err
200-
}
201-
privilegedLoopbackOpenShiftClient, privilegedLoopbackClientConfig, err := configapi.GetOpenShiftClient(options.MasterClients.OpenShiftLoopbackKubeConfig, options.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
191+
privilegedLoopbackKubeClientsetExternal, privilegedLoopbackClientConfig, err := configapi.GetExternalKubeClient(options.MasterClients.OpenShiftLoopbackKubeConfig, options.MasterClients.OpenShiftLoopbackClientConnectionOverrides)
202192
if err != nil {
203193
return nil, err
204194
}
@@ -371,7 +361,6 @@ func BuildMasterConfig(options configapi.MasterConfig, informers InformerAccess)
371361
KubeletClientConfig: kubeletClientConfig,
372362

373363
PrivilegedLoopbackClientConfig: *privilegedLoopbackClientConfig,
374-
PrivilegedLoopbackOpenShiftClient: privilegedLoopbackOpenShiftClient,
375364
PrivilegedLoopbackKubernetesClientsetInternal: privilegedLoopbackKubeClientsetInternal,
376365
PrivilegedLoopbackKubernetesClientsetExternal: privilegedLoopbackKubeClientsetExternal,
377366

@@ -853,18 +842,6 @@ func (c *MasterConfig) KubeClientsetExternal() kclientsetexternal.Interface {
853842
return c.PrivilegedLoopbackKubernetesClientsetExternal
854843
}
855844

856-
// ServiceAccountRoleBindingClient returns the client object used to bind roles to service accounts
857-
// It must have the following capabilities:
858-
// get, list, update, create policyBindings and clusterPolicyBindings in all namespaces
859-
func (c *MasterConfig) ServiceAccountRoleBindingClient() *osclient.Client {
860-
return c.PrivilegedLoopbackOpenShiftClient
861-
}
862-
863-
// RouteAllocatorClients returns the route allocator client objects
864-
func (c *MasterConfig) RouteAllocatorClients() (*osclient.Client, kclientsetinternal.Interface) {
865-
return c.PrivilegedLoopbackOpenShiftClient, c.PrivilegedLoopbackKubernetesClientsetInternal
866-
}
867-
868845
// WebConsoleEnabled says whether web ui is not a disabled feature and asset service is configured.
869846
func (c *MasterConfig) WebConsoleEnabled() bool {
870847
return c.Options.AssetConfig != nil && !c.Options.DisabledFeatures.Has(configapi.FeatureWebConsole)

0 commit comments

Comments
 (0)