mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
kubelet: reading cloudinfo from cadvisor
When no --cloud-provider flag is given, try to use data from cadvisor to determine the current cloud provider.
This commit is contained in:
parent
f538d6019d
commit
7fb82d543f
@ -1064,6 +1064,11 @@ 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 err := kl.setNodeStatus(node); err != nil {
|
||||
return nil, err
|
||||
@ -3011,6 +3016,18 @@ func (kl *Kubelet) setNodeAddress(node *api.Node) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (kl *Kubelet) updateCloudProviderFromMachineInfo(node *api.Node, info *cadvisorapi.MachineInfo) {
|
||||
if info.CloudProvider != cadvisorapi.UnknownProvider &&
|
||||
info.CloudProvider != cadvisorapi.Baremetal {
|
||||
// The cloud providers from pkg/cloudprovider/providers/* that update ProviderID
|
||||
// will use the format of cloudprovider://project/availability_zone/instance_name
|
||||
// here we only have the cloudprovider and the instance name so we leave project
|
||||
// and availability zone empty for compatibility.
|
||||
node.Spec.ProviderID = strings.ToLower(string(info.CloudProvider)) +
|
||||
":////" + string(info.InstanceID)
|
||||
}
|
||||
}
|
||||
|
||||
func (kl *Kubelet) setNodeStatusMachineInfo(node *api.Node) {
|
||||
// TODO: Post NotReady if we cannot get MachineInfo from cAdvisor. This needs to start
|
||||
// cAdvisor locally, e.g. for test-cmd.sh, and in integration test.
|
||||
|
Loading…
Reference in New Issue
Block a user