mirror of https://github.com/k3s-io/k3s
Address PR comments
parent
e97a18b435
commit
aca62a1741
|
@ -47,16 +47,16 @@ func (elem GroupKindElement) Accept(visitor KindVisitor) error {
|
|||
visitor.VisitDeployment(elem)
|
||||
return nil
|
||||
}
|
||||
if elem.GroupMatch("apps", "extensions") && elem.Kind == "Job" {
|
||||
visitor.VisitDeployment(elem)
|
||||
if elem.GroupMatch("batch") && elem.Kind == "Job" {
|
||||
visitor.VisitJob(elem)
|
||||
return nil
|
||||
}
|
||||
if elem.GroupMatch("", "core") && elem.Kind == "Pod" {
|
||||
visitor.VisitPod(elem)
|
||||
return nil
|
||||
}
|
||||
if elem.GroupMatch("apps", "extensions") && elem.Kind == "ReplicaSet" {
|
||||
visitor.VisitReplicationController(elem)
|
||||
if elem.GroupMatch("extensions") && elem.Kind == "ReplicaSet" {
|
||||
visitor.VisitReplicaSet(elem)
|
||||
return nil
|
||||
}
|
||||
if elem.GroupMatch("", "core") && elem.Kind == "ReplicationController" {
|
||||
|
@ -81,15 +81,15 @@ func (elem GroupKindElement) GroupMatch(groups ...string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// DefaultKindVisitor implements KindVisitor with no-op functions.
|
||||
type DefaultKindVisitor struct{}
|
||||
// NoOpKindVisitor implements KindVisitor with no-op functions.
|
||||
type NoOpKindVisitor struct{}
|
||||
|
||||
var _ KindVisitor = &DefaultKindVisitor{}
|
||||
var _ KindVisitor = &NoOpKindVisitor{}
|
||||
|
||||
func (*DefaultKindVisitor) VisitDaemonSet(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitDeployment(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitJob(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitPod(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitReplicaSet(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitReplicationController(kind GroupKindElement) {}
|
||||
func (*DefaultKindVisitor) VisitStatefulSet(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitDaemonSet(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitDeployment(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitJob(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitPod(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitReplicaSet(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitReplicationController(kind GroupKindElement) {}
|
||||
func (*NoOpKindVisitor) VisitStatefulSet(kind GroupKindElement) {}
|
||||
|
|
|
@ -60,10 +60,11 @@ type ClientCache struct {
|
|||
discoveryClientFactory DiscoveryClientFactory
|
||||
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 {
|
||||
// once makes sure the client is only initialized once
|
||||
once sync.Once
|
||||
|
@ -73,20 +74,20 @@ type KubernetesClientCache struct {
|
|||
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.
|
||||
// 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.
|
||||
func (c *ClientCache) KubernetesClientSet(requiredVersion *schema.GroupVersion) (*kubernetes.Clientset, error) {
|
||||
c.kubernetesClientLoader.once.Do(func() {
|
||||
func (c *ClientCache) KubernetesClientSetForVersion(requiredVersion *schema.GroupVersion) (*kubernetes.Clientset, error) {
|
||||
c.kubernetesClientCache.once.Do(func() {
|
||||
config, err := c.ClientConfigForVersion(requiredVersion)
|
||||
if err != nil {
|
||||
c.kubernetesClientLoader.err = err
|
||||
c.kubernetesClientCache.err = err
|
||||
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
|
||||
|
|
|
@ -93,7 +93,7 @@ type ClientAccessFactory interface {
|
|||
// ClientSet gives you back an internal, generated clientset
|
||||
ClientSet() (internalclientset.Interface, error)
|
||||
|
||||
// KubernetesClientSet gives you back an external clientset
|
||||
// KubernetesClientSetForVersion gives you back an external clientset
|
||||
KubernetesClientSet() (*kubernetes.Clientset, error)
|
||||
|
||||
// Returns a RESTClient for accessing Kubernetes resources or an error.
|
||||
|
|
|
@ -169,7 +169,7 @@ func (f *ring0Factory) DiscoveryClient() (discovery.CachedDiscoveryInterface, er
|
|||
}
|
||||
|
||||
func (f *ring0Factory) KubernetesClientSet() (*kubernetes.Clientset, error) {
|
||||
return f.clientCache.KubernetesClientSet(nil)
|
||||
return f.clientCache.KubernetesClientSetForVersion(nil)
|
||||
}
|
||||
|
||||
func (f *ring0Factory) ClientSet() (internalclientset.Interface, error) {
|
||||
|
|
Loading…
Reference in New Issue