Address PR comments

pull/6/head
Phillip Wittrock 2017-08-16 14:22:32 -07:00
parent e97a18b435
commit aca62a1741
4 changed files with 26 additions and 25 deletions

View File

@ -47,16 +47,16 @@ func (elem GroupKindElement) Accept(visitor KindVisitor) error {
visitor.VisitDeployment(elem) visitor.VisitDeployment(elem)
return nil return nil
} }
if elem.GroupMatch("apps", "extensions") && elem.Kind == "Job" { if elem.GroupMatch("batch") && elem.Kind == "Job" {
visitor.VisitDeployment(elem) visitor.VisitJob(elem)
return nil return nil
} }
if elem.GroupMatch("", "core") && elem.Kind == "Pod" { if elem.GroupMatch("", "core") && elem.Kind == "Pod" {
visitor.VisitPod(elem) visitor.VisitPod(elem)
return nil return nil
} }
if elem.GroupMatch("apps", "extensions") && elem.Kind == "ReplicaSet" { if elem.GroupMatch("extensions") && elem.Kind == "ReplicaSet" {
visitor.VisitReplicationController(elem) visitor.VisitReplicaSet(elem)
return nil return nil
} }
if elem.GroupMatch("", "core") && elem.Kind == "ReplicationController" { if elem.GroupMatch("", "core") && elem.Kind == "ReplicationController" {
@ -81,15 +81,15 @@ func (elem GroupKindElement) GroupMatch(groups ...string) bool {
return false return false
} }
// DefaultKindVisitor implements KindVisitor with no-op functions. // NoOpKindVisitor implements KindVisitor with no-op functions.
type DefaultKindVisitor struct{} type NoOpKindVisitor struct{}
var _ KindVisitor = &DefaultKindVisitor{} var _ KindVisitor = &NoOpKindVisitor{}
func (*DefaultKindVisitor) VisitDaemonSet(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitDaemonSet(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitDeployment(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitDeployment(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitJob(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitJob(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitPod(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitPod(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitReplicaSet(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitReplicaSet(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitReplicationController(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitReplicationController(kind GroupKindElement) {}
func (*DefaultKindVisitor) VisitStatefulSet(kind GroupKindElement) {} func (*NoOpKindVisitor) VisitStatefulSet(kind GroupKindElement) {}

View File

@ -60,10 +60,11 @@ type ClientCache struct {
discoveryClientFactory DiscoveryClientFactory discoveryClientFactory DiscoveryClientFactory
discoveryClient discovery.DiscoveryInterface discoveryClient discovery.DiscoveryInterface
kubernetesClientLoader KubernetesClientCache kubernetesClientCache KubernetesClientCache
} }
// kubernetesClientLoader provides a new kubernetes.Clientset // KubernetesClientCache creates a new kubernetes.Clientset one time
// and then returns the result for all future requests
type KubernetesClientCache struct { type KubernetesClientCache struct {
// once makes sure the client is only initialized once // once makes sure the client is only initialized once
once sync.Once once sync.Once
@ -73,20 +74,20 @@ type KubernetesClientCache struct {
err error err error
} }
// KubernetesClientSet returns a new kubernetes.Clientset. It will cache the value // 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. // the first time it is called and return the cached value on subsequent calls.
// If an error is encountered the first time KubernetesClientSet is called, // If an error is encountered the first time KubernetesClientSetForVersion is called,
// the error will be cached. // the error will be cached.
func (c *ClientCache) KubernetesClientSet(requiredVersion *schema.GroupVersion) (*kubernetes.Clientset, error) { func (c *ClientCache) KubernetesClientSetForVersion(requiredVersion *schema.GroupVersion) (*kubernetes.Clientset, error) {
c.kubernetesClientLoader.once.Do(func() { c.kubernetesClientCache.once.Do(func() {
config, err := c.ClientConfigForVersion(requiredVersion) config, err := c.ClientConfigForVersion(requiredVersion)
if err != nil { if err != nil {
c.kubernetesClientLoader.err = err c.kubernetesClientCache.err = err
return return
} }
c.kubernetesClientLoader.client, c.kubernetesClientLoader.err = kubernetes.NewForConfig(config) c.kubernetesClientCache.client, c.kubernetesClientCache.err = kubernetes.NewForConfig(config)
}) })
return c.kubernetesClientLoader.client, c.kubernetesClientLoader.err return c.kubernetesClientCache.client, c.kubernetesClientCache.err
} }
// also looks up the discovery client. We can't do this during init because the flags won't have been set // also looks up the discovery client. We can't do this during init because the flags won't have been set

View File

@ -93,7 +93,7 @@ type ClientAccessFactory interface {
// ClientSet gives you back an internal, generated clientset // ClientSet gives you back an internal, generated clientset
ClientSet() (internalclientset.Interface, error) ClientSet() (internalclientset.Interface, error)
// KubernetesClientSet gives you back an external clientset // KubernetesClientSetForVersion gives you back an external clientset
KubernetesClientSet() (*kubernetes.Clientset, error) KubernetesClientSet() (*kubernetes.Clientset, error)
// Returns a RESTClient for accessing Kubernetes resources or an error. // Returns a RESTClient for accessing Kubernetes resources or an error.

View File

@ -169,7 +169,7 @@ func (f *ring0Factory) DiscoveryClient() (discovery.CachedDiscoveryInterface, er
} }
func (f *ring0Factory) KubernetesClientSet() (*kubernetes.Clientset, error) { func (f *ring0Factory) KubernetesClientSet() (*kubernetes.Clientset, error) {
return f.clientCache.KubernetesClientSet(nil) return f.clientCache.KubernetesClientSetForVersion(nil)
} }
func (f *ring0Factory) ClientSet() (internalclientset.Interface, error) { func (f *ring0Factory) ClientSet() (internalclientset.Interface, error) {