mirror of https://github.com/k3s-io/k3s
Merge pull request #4907 from ddysher/kubelet-client-interface
kubelet should take a client interfacepull/6/head
commit
a8dd10dab7
|
@ -389,12 +389,20 @@ type KubeletConfig struct {
|
|||
func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) (*kubelet.Kubelet, error) {
|
||||
// TODO: block until all sources have delivered at least one update to the channel, or break the sync loop
|
||||
// up into "per source" synchronizations
|
||||
|
||||
// TODO: KubeletConfig.KubeClient should be a client interface, but client interface misses certain methods
|
||||
// used by kubelet. Since NewMainKubelet expects a client interface, we need to make sure we are not passing
|
||||
// a nil pointer to it when what we really want is a nil interface.
|
||||
var kubeClient client.Interface
|
||||
if kc.KubeClient == nil {
|
||||
kubeClient = nil
|
||||
} else {
|
||||
kubeClient = kc.KubeClient
|
||||
}
|
||||
k, err := kubelet.NewMainKubelet(
|
||||
kc.Hostname,
|
||||
kc.DockerClient,
|
||||
kc.EtcdClient,
|
||||
kc.KubeClient,
|
||||
kubeClient,
|
||||
kc.RootDirectory,
|
||||
kc.PodInfraContainerImage,
|
||||
kc.SyncFrequency,
|
||||
|
|
|
@ -37,7 +37,7 @@ type ListWatch struct {
|
|||
WatchFunc WatchFunc
|
||||
}
|
||||
|
||||
// ListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector
|
||||
// NewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.
|
||||
func NewListWatchFromClient(client *client.Client, resource string, namespace string, fieldSelector labels.Selector) *ListWatch {
|
||||
listFunc := func() (runtime.Object, error) {
|
||||
return client.Get().Namespace(namespace).Resource(resource).SelectorParam("fields", fieldSelector).Do().Get()
|
||||
|
|
|
@ -42,10 +42,12 @@ import (
|
|||
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/volume"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/probe"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
|
||||
"github.com/fsouza/go-dockerclient"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
@ -76,7 +78,7 @@ func NewMainKubelet(
|
|||
hostname string,
|
||||
dockerClient dockertools.DockerInterface,
|
||||
etcdClient tools.EtcdClient,
|
||||
kubeClient *client.Client,
|
||||
kubeClient client.Interface,
|
||||
rootDirectory string,
|
||||
podInfraContainerImage string,
|
||||
resyncInterval time.Duration,
|
||||
|
@ -103,12 +105,17 @@ func NewMainKubelet(
|
|||
|
||||
serviceStore := cache.NewStore(cache.MetaNamespaceKeyFunc)
|
||||
if kubeClient != nil {
|
||||
cache.NewReflector(
|
||||
cache.NewListWatchFromClient(kubeClient, "services", api.NamespaceAll, labels.Everything()),
|
||||
&api.Service{},
|
||||
serviceStore,
|
||||
0,
|
||||
).Run()
|
||||
// TODO: cache.NewListWatchFromClient is limited as it takes a client implementation rather
|
||||
// than an interface. There is no way to construct a list+watcher using resource name.
|
||||
listWatch := &cache.ListWatch{
|
||||
ListFunc: func() (runtime.Object, error) {
|
||||
return kubeClient.Services(api.NamespaceAll).List(labels.Everything())
|
||||
},
|
||||
WatchFunc: func(resourceVersion string) (watch.Interface, error) {
|
||||
return kubeClient.Services(api.NamespaceAll).Watch(labels.Everything(), labels.Everything(), resourceVersion)
|
||||
},
|
||||
}
|
||||
cache.NewReflector(listWatch, &api.Service{}, serviceStore, 0).Run()
|
||||
}
|
||||
serviceLister := &cache.StoreToServiceLister{serviceStore}
|
||||
|
||||
|
@ -173,7 +180,7 @@ type Kubelet struct {
|
|||
hostname string
|
||||
dockerClient dockertools.DockerInterface
|
||||
dockerCache dockertools.DockerCache
|
||||
kubeClient *client.Client
|
||||
kubeClient client.Interface
|
||||
rootDirectory string
|
||||
podInfraContainerImage string
|
||||
podWorkers *podWorkers
|
||||
|
|
Loading…
Reference in New Issue