Skip to content

Commit

Permalink
added cloud provider flag to kubelet
Browse files Browse the repository at this point in the history
This is to fix issue kubernetes#5667
  • Loading branch information
spothanis committed Mar 25, 2015
1 parent 1d2f0cf commit 1c06cde
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ func startComponents(firstManifestURL, secondManifestURL, apiVersion string) (st
testRootDir := makeTempDirOrDie("kubelet_integ_1.", "")
configFilePath := makeTempDirOrDie("config", testRootDir)
glog.Infof("Using %s as root dir for kubelet #1", testRootDir)
kcfg := kubeletapp.SimpleKubelet(cl, &fakeDocker1, machineList[0], testRootDir, firstManifestURL, "127.0.0.1", 10250, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, configFilePath)
kcfg := kubeletapp.SimpleKubelet(cl, &fakeDocker1, machineList[0], testRootDir, firstManifestURL, "127.0.0.1", 10250, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, configFilePath, nil)
kubeletapp.RunKubelet(kcfg)
// Kubelet (machine)
// Create a second kubelet so that the guestbook example's two redis slaves both
// have a place they can schedule.
testRootDir = makeTempDirOrDie("kubelet_integ_2.", "")
glog.Infof("Using %s as root dir for kubelet #2", testRootDir)
kcfg = kubeletapp.SimpleKubelet(cl, &fakeDocker2, machineList[1], testRootDir, secondManifestURL, "127.0.0.1", 10251, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, "")
kcfg = kubeletapp.SimpleKubelet(cl, &fakeDocker2, machineList[1], testRootDir, secondManifestURL, "127.0.0.1", 10251, api.NamespaceDefault, empty_dir.ProbeVolumePlugins(), nil, cadvisorInterface, "", nil)
kubeletapp.RunKubelet(kcfg)
return apiServer.URL, configFilePath
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/kubelet/app/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/host_path"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/nfs"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume/secret"
//Cloud providers
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/aws"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/gce"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/openstack"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/ovirt"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/rackspace"
_ "github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider/vagrant"
)

// ProbeVolumePlugins collects all volume plugins into an easy to use list.
Expand Down
18 changes: 16 additions & 2 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"

"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/golang/glog"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -79,6 +80,8 @@ type KubeletServer struct {
ImageGCHighThresholdPercent int
ImageGCLowThresholdPercent int
NetworkPluginName string
CloudProvider string
CloudConfigFile string
}

// NewKubeletServer will create a new KubeletServer with default values.
Expand Down Expand Up @@ -140,6 +143,8 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
fs.IntVar(&s.ImageGCHighThresholdPercent, "image_gc_high_threshold", s.ImageGCHighThresholdPercent, "The percent of disk usage after which image garbage collection is always run. Default: 90%%")
fs.IntVar(&s.ImageGCLowThresholdPercent, "image_gc_low_threshold", s.ImageGCLowThresholdPercent, "The percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. Default: 80%%")
fs.StringVar(&s.NetworkPluginName, "network_plugin", s.NetworkPluginName, "<Warning: Alpha feature> The name of the network plugin to be invoked for various events in kubelet/pod lifecycle")
fs.StringVar(&s.CloudProvider, "cloud_provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
fs.StringVar(&s.CloudConfigFile, "cloud_config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")
}

// Run runs the specified KubeletServer. This should never exit.
Expand Down Expand Up @@ -169,6 +174,10 @@ func (s *KubeletServer) Run(_ []string) error {
HighThresholdPercent: s.ImageGCHighThresholdPercent,
LowThresholdPercent: s.ImageGCLowThresholdPercent,
}

cloud := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
glog.Infof("Successfully initialized cloud provider: %q from the config file: %q\n", s.CloudProvider, s.CloudConfigFile)

kcfg := KubeletConfig{
Address: s.Address,
AllowPrivileged: s.AllowPrivileged,
Expand Down Expand Up @@ -200,6 +209,7 @@ func (s *KubeletServer) Run(_ []string) error {
NetworkPluginName: s.NetworkPluginName,
StreamingConnectionIdleTimeout: s.StreamingConnectionIdleTimeout,
ImageGCPolicy: imageGCPolicy,
Cloud: cloud,
}

RunKubelet(&kcfg)
Expand Down Expand Up @@ -262,7 +272,8 @@ func SimpleKubelet(client *client.Client,
volumePlugins []volume.VolumePlugin,
tlsOptions *kubelet.TLSOptions,
cadvisorInterface cadvisor.Interface,
configFilePath string) *KubeletConfig {
configFilePath string,
cloud cloudprovider.Interface) *KubeletConfig {

imageGCPolicy := kubelet.ImageGCPolicy{
HighThresholdPercent: 90,
Expand Down Expand Up @@ -291,6 +302,7 @@ func SimpleKubelet(client *client.Client,
CadvisorInterface: cadvisorInterface,
ConfigFile: configFilePath,
ImageGCPolicy: imageGCPolicy,
Cloud: cloud,
}
return &kcfg
}
Expand Down Expand Up @@ -399,6 +411,7 @@ type KubeletConfig struct {
Recorder record.EventRecorder
TLSOptions *kubelet.TLSOptions
ImageGCPolicy kubelet.ImageGCPolicy
Cloud cloudprovider.Interface
}

func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) (*kubelet.Kubelet, error) {
Expand Down Expand Up @@ -440,7 +453,8 @@ func createAndInitKubelet(kc *KubeletConfig, pc *config.PodConfig) (*kubelet.Kub
kc.StreamingConnectionIdleTimeout,
kc.Recorder,
kc.CadvisorInterface,
kc.ImageGCPolicy)
kc.ImageGCPolicy,
kc.Cloud)

if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion cmd/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,9 @@ func startComponents(etcdClient tools.EtcdClient, cl *client.Client, addr net.IP
if err != nil {
glog.Fatalf("Failed to create cAdvisor: %v", err)
}
kcfg := kubeletapp.SimpleKubelet(cl, dockerClient, machineList[0], "/tmp/kubernetes", "", "127.0.0.1", 10250, *masterServiceNamespace, kubeletapp.ProbeVolumePlugins(), nil, cadvisorInterface, "")
kcfg := kubeletapp.SimpleKubelet(cl, dockerClient, machineList[0], "/tmp/kubernetes", "", "127.0.0.1", 10250, *masterServiceNamespace, kubeletapp.ProbeVolumePlugins(), nil, cadvisorInterface, "", nil)
kubeletapp.RunKubelet(kcfg)

}

func newApiClient(addr net.IP, port int) *client.Client {
Expand Down
8 changes: 7 additions & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/cache"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/cadvisor"
kubecontainer "github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
Expand Down Expand Up @@ -137,7 +138,8 @@ func NewMainKubelet(
streamingConnectionIdleTimeout time.Duration,
recorder record.EventRecorder,
cadvisorInterface cadvisor.Interface,
imageGCPolicy ImageGCPolicy) (*Kubelet, error) {
imageGCPolicy ImageGCPolicy,
cloud cloudprovider.Interface) (*Kubelet, error) {
if rootDirectory == "" {
return nil, fmt.Errorf("invalid root directory %q", rootDirectory)
}
Expand Down Expand Up @@ -235,6 +237,7 @@ func NewMainKubelet(
containerGC: containerGC,
imageManager: imageManager,
statusManager: statusManager,
cloud: cloud,
}

klet.podManager = newBasicPodManager(klet.kubeClient)
Expand Down Expand Up @@ -351,6 +354,9 @@ type Kubelet struct {

// Syncs pods statuses with apiserver; also used as a cache of statuses.
statusManager *statusManager

//Cloud provider interface
cloud cloudprovider.Interface
}

// getRootDir returns the full path to the directory under which kubelet can
Expand Down

0 comments on commit 1c06cde

Please sign in to comment.