mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #28258 from vishh/28231
Automatic merge from submit-queue [kubelet] Allow opting out of automatic cloud provider detection in kubelet. By default kubelet will auto-detect cloud providers fixes #28231
This commit is contained in:
commit
ab37fbf4c2
@ -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
|
||||
@ -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},
|
||||
@ -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.")
|
||||
|
@ -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 {
|
||||
@ -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
|
||||
@ -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,
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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
|
||||
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user