Skip to content

Commit

Permalink
Allow opting out of automatic cloud provider detection in kubelet
Browse files Browse the repository at this point in the history
Signed-off-by: Vishnu Kannan <vishnuk@google.com>
Signed-off-by: Vishnu kannan <vishnuk@google.com>
  • Loading branch information
vishh committed Jun 30, 2016
1 parent 594e4d8 commit ea789e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
5 changes: 4 additions & 1 deletion cmd/kubelet/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
// When these values are updated, also update test/e2e/framework/util.go
defaultPodInfraContainerImageName = "gcr.io/google_containers/pause"
defaultPodInfraContainerImageVersion = "3.0"
// Auto detect cloud provider.
AutoDetectCloudProvider = "auto-detect"
)

// Returns the arch-specific pause image that kubelet should use as the default
Expand Down Expand Up @@ -83,6 +85,7 @@ func NewKubeletServer() *KubeletServer {
VolumeStatsAggPeriod: unversioned.Duration{Duration: time.Minute},
CertDirectory: "/var/run/kubernetes",
CgroupRoot: "",
CloudProvider: AutoDetectCloudProvider,
ConfigureCBR0: false,
ContainerRuntime: "docker",
RuntimeRequestTimeout: unversioned.Duration{Duration: 2 * time.Minute},
Expand Down Expand Up @@ -218,7 +221,7 @@ func (s *KubeletServer) AddFlags(fs *pflag.FlagSet) {
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.NetworkPluginDir, "network-plugin-dir", s.NetworkPluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for network plugins")
fs.StringVar(&s.VolumePluginDir, "volume-plugin-dir", s.VolumePluginDir, "<Warning: Alpha feature> The full path of the directory in which to search for additional third party volume plugins")
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. Empty string for no provider.")
fs.StringVar(&s.CloudProvider, "cloud-provider", s.CloudProvider, "The provider for cloud services. By default, kubelet will attempt to auto-detect the cloud provider. Specify empty string for running with no cloud provider. [default=auto-detect]")
fs.StringVar(&s.CloudConfigFile, "cloud-config", s.CloudConfigFile, "The path to the cloud provider configuration file. Empty string for no configuration file.")

fs.StringVar(&s.KubeletCgroups, "resource-container", s.KubeletCgroups, "Optional absolute name of the resource-only container to create and run the Kubelet in.")
Expand Down
16 changes: 11 additions & 5 deletions cmd/kubelet/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,16 @@ func run(s *options.KubeletServer, kcfg *KubeletConfig) (err error) {
glog.Warningf("No API client: %v", err)
}

cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
if err != nil {
return err
if s.CloudProvider == options.AutoDetectCloudProvider {
kcfg.AutoDetectCloudProvider = true
} else {
cloud, err := cloudprovider.InitCloudProvider(s.CloudProvider, s.CloudConfigFile)
if err != nil {
return err
}
glog.V(2).Infof("Successfully initialized cloud provider: %q from the config file: %q\n", s.CloudProvider, s.CloudConfigFile)
kcfg.Cloud = cloud
}
glog.V(2).Infof("Successfully initialized cloud provider: %q from the config file: %q\n", s.CloudProvider, s.CloudConfigFile)
kcfg.Cloud = cloud
}

if kcfg.CAdvisorInterface == nil {
Expand Down Expand Up @@ -773,6 +777,7 @@ type KubeletConfig struct {
Address net.IP
AllowPrivileged bool
Auth server.AuthInterface
AutoDetectCloudProvider bool
Builder KubeletBuilder
CAdvisorInterface cadvisor.Interface
VolumeStatsAggPeriod time.Duration
Expand Down Expand Up @@ -920,6 +925,7 @@ func CreateAndInitKubelet(kc *KubeletConfig) (k KubeletBootstrap, pc *config.Pod
kc.ImageGCPolicy,
kc.DiskSpacePolicy,
kc.Cloud,
kc.AutoDetectCloudProvider,
kc.NodeLabels,
kc.NodeStatusUpdateFrequency,
kc.OSInterface,
Expand Down
21 changes: 13 additions & 8 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func NewMainKubelet(
imageGCPolicy ImageGCPolicy,
diskSpacePolicy DiskSpacePolicy,
cloud cloudprovider.Interface,
autoDetectCloudProvider bool,
nodeLabels map[string]string,
nodeStatusUpdateFrequency time.Duration,
osInterface kubecontainer.OSInterface,
Expand Down Expand Up @@ -331,9 +332,10 @@ func NewMainKubelet(
cadvisor: cadvisorInterface,
diskSpaceManager: diskSpaceManager,
cloud: cloud,
nodeRef: nodeRef,
nodeLabels: nodeLabels,
nodeStatusUpdateFrequency: nodeStatusUpdateFrequency,
autoDetectCloudProvider: autoDetectCloudProvider,
nodeRef: nodeRef,
nodeLabels: nodeLabels,
nodeStatusUpdateFrequency: nodeStatusUpdateFrequency,
os: osInterface,
oomWatcher: oomWatcher,
cgroupRoot: cgroupRoot,
Expand Down Expand Up @@ -688,7 +690,8 @@ type Kubelet struct {
volumeManager kubeletvolume.VolumeManager

// Cloud provider interface.
cloud cloudprovider.Interface
cloud cloudprovider.Interface
autoDetectCloudProvider bool

// Reference to this node.
nodeRef *api.ObjectReference
Expand Down Expand Up @@ -1115,10 +1118,12 @@ func (kl *Kubelet) initialNodeStatus() (*api.Node, error) {
}
} else {
node.Spec.ExternalID = kl.hostname
// If no cloud provider is defined - use the one detected by cadvisor
info, err := kl.GetCachedMachineInfo()
if err == nil {
kl.updateCloudProviderFromMachineInfo(node, info)
if kl.autoDetectCloudProvider {
// If no cloud provider is defined - use the one detected by cadvisor
info, err := kl.GetCachedMachineInfo()
if err == nil {
kl.updateCloudProviderFromMachineInfo(node, info)
}
}
}
if err := kl.setNodeStatus(node); err != nil {
Expand Down

0 comments on commit ea789e8

Please sign in to comment.