Skip to content

Commit

Permalink
kubelet: reading cloudinfo from cadvisor
Browse files Browse the repository at this point in the history
When no --cloud-provider flag is given, try to use data from cadvisor to
determine the current cloud provider.
  • Loading branch information
Erez Freiberger committed May 22, 2016
1 parent f538d60 commit 7fb82d5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 7fb82d5

Please sign in to comment.