diff --git a/cmd/kubelet/app/server.go b/cmd/kubelet/app/server.go index 3fcec121b9..bce74cd886 100644 --- a/cmd/kubelet/app/server.go +++ b/cmd/kubelet/app/server.go @@ -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, diff --git a/pkg/client/cache/listwatch.go b/pkg/client/cache/listwatch.go index 96fdecaa04..6347e6a57b 100644 --- a/pkg/client/cache/listwatch.go +++ b/pkg/client/cache/listwatch.go @@ -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() diff --git a/pkg/kubelet/kubelet.go b/pkg/kubelet/kubelet.go index e12b84a5f9..7f3d83ad41 100644 --- a/pkg/kubelet/kubelet.go +++ b/pkg/kubelet/kubelet.go @@ -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