remove metrics client factory method

This commit is contained in:
David Eads
2018-02-21 11:01:09 -05:00
parent c153aff99f
commit f084311326
11 changed files with 145 additions and 136 deletions

View File

@@ -27,7 +27,6 @@ import (
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
oldclient "k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/version"
metricsclientset "k8s.io/metrics/pkg/client/clientset_generated/clientset"
)
func NewClientCache(loader clientcmd.ClientConfig, discoveryClientFactory DiscoveryClientFactory) *ClientCache {
@@ -59,7 +58,6 @@ type ClientCache struct {
discoveryClient discovery.DiscoveryInterface
kubernetesClientCache kubernetesClientCache
metricsClientCache metricsClientCache
}
// kubernetesClientCache creates a new kubernetes.Clientset one time
@@ -73,17 +71,6 @@ type kubernetesClientCache struct {
err error
}
// metricsClientCache creates a new metricsclientset.Clientset one time
// and then returns the result for all future requests
type metricsClientCache struct {
// once makes sure the client is only initialized once
once sync.Once
// client is the cached client value
client *metricsclientset.Clientset
// err is the cached error value
err error
}
// KubernetesClientSetForVersion returns a new kubernetes.Clientset. It will cache the value
// the first time it is called and return the cached value on subsequent calls.
// If an error is encountered the first time KubernetesClientSetForVersion is called,
@@ -100,22 +87,6 @@ func (c *ClientCache) KubernetesClientSetForVersion(requiredVersion *schema.Grou
return c.kubernetesClientCache.client, c.kubernetesClientCache.err
}
// MetricsClientSetForVersion returns a new kubernetes.Clientset. It will cache the value
// the first time it is called and return the cached value on subsequent calls.
// If an error is encountered the first time MetircsClientSetForVersion is called,
// the error will be cached.
func (c *ClientCache) MetricsClientSetForVersion(requiredVersion *schema.GroupVersion) (*metricsclientset.Clientset, error) {
c.metricsClientCache.once.Do(func() {
config, err := c.ClientConfigForVersion(requiredVersion)
if err != nil {
c.kubernetesClientCache.err = err
return
}
c.metricsClientCache.client, c.metricsClientCache.err = metricsclientset.NewForConfig(config)
})
return c.metricsClientCache.client, c.metricsClientCache.err
}
// also looks up the discovery client. We can't do this during init because the flags won't have been set
// because this is constructed pre-command execution before the command tree is
// even set up. Requires the lock to already be acquired