mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 02:09:56 +00:00
Allow cloud providers to return a node identifier different from the hostname
This commit is contained in:
parent
c28cdfbd43
commit
efaead81dc
@ -565,7 +565,27 @@ func SimpleKubelet(client *client.Client,
|
|||||||
// Eventually, #2 will be replaced with instances of #3
|
// Eventually, #2 will be replaced with instances of #3
|
||||||
func RunKubelet(kcfg *KubeletConfig, builder KubeletBuilder) error {
|
func RunKubelet(kcfg *KubeletConfig, builder KubeletBuilder) error {
|
||||||
kcfg.Hostname = nodeutil.GetHostname(kcfg.HostnameOverride)
|
kcfg.Hostname = nodeutil.GetHostname(kcfg.HostnameOverride)
|
||||||
kcfg.NodeName = kcfg.Hostname
|
|
||||||
|
if kcfg.NodeName == "" {
|
||||||
|
// Query the cloud provider for our node name, default to Hostname
|
||||||
|
nodeName := kcfg.Hostname
|
||||||
|
if kcfg.Cloud != nil {
|
||||||
|
var err error
|
||||||
|
instances, ok := kcfg.Cloud.Instances()
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("failed to get instances from cloud provider")
|
||||||
|
}
|
||||||
|
|
||||||
|
nodeName, err = instances.CurrentNodeName(kcfg.Hostname)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error fetching current instance name from cloud provider: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(2).Infof("cloud provider determined current node name to be %s", nodeName)
|
||||||
|
}
|
||||||
|
|
||||||
|
kcfg.NodeName = nodeName
|
||||||
|
}
|
||||||
|
|
||||||
eventBroadcaster := record.NewBroadcaster()
|
eventBroadcaster := record.NewBroadcaster()
|
||||||
kcfg.Recorder = eventBroadcaster.NewRecorder(api.EventSource{Component: "kubelet", Host: kcfg.NodeName})
|
kcfg.Recorder = eventBroadcaster.NewRecorder(api.EventSource{Component: "kubelet", Host: kcfg.NodeName})
|
||||||
|
@ -234,6 +234,10 @@ func (self *AWSCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error
|
|||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *AWSCloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Implementation of EC2.Instances
|
// Implementation of EC2.Instances
|
||||||
func (self *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*ec2.Instance, error) {
|
func (self *awsSdkEC2) DescribeInstances(request *ec2.DescribeInstancesInput) ([]*ec2.Instance, error) {
|
||||||
// Instances are paged
|
// Instances are paged
|
||||||
|
@ -111,6 +111,9 @@ type Instances interface {
|
|||||||
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
|
// AddSSHKeyToAllInstances adds an SSH public key as a legal identity for all instances
|
||||||
// expected format for the key is standard ssh-keygen format: <protocol> <blob>
|
// expected format for the key is standard ssh-keygen format: <protocol> <blob>
|
||||||
AddSSHKeyToAllInstances(user string, keyData []byte) error
|
AddSSHKeyToAllInstances(user string, keyData []byte) error
|
||||||
|
// Returns the name of the node we are currently running on
|
||||||
|
// On most clouds (e.g. GCE) this is the hostname, so we provide the hostname
|
||||||
|
CurrentNodeName(hostname string) (string, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Route is a representation of an advanced routing rule.
|
// Route is a representation of an advanced routing rule.
|
||||||
|
@ -149,6 +149,11 @@ func (f *FakeCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
|||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (f *FakeCloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
// NodeAddresses is a test-spy implementation of Instances.NodeAddresses.
|
// NodeAddresses is a test-spy implementation of Instances.NodeAddresses.
|
||||||
// It adds an entry "node-addresses" into the internal method call record.
|
// It adds an entry "node-addresses" into the internal method call record.
|
||||||
func (f *FakeCloud) NodeAddresses(instance string) ([]api.NodeAddress, error) {
|
func (f *FakeCloud) NodeAddresses(instance string) ([]api.NodeAddress, error) {
|
||||||
|
@ -483,6 +483,11 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (gce *GCECloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
func (gce *GCECloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
|
return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) {
|
||||||
project, err := gce.service.Projects.Get(gce.projectID).Do()
|
project, err := gce.service.Projects.Get(gce.projectID).Do()
|
||||||
|
@ -78,6 +78,11 @@ func newMesosCloud(configReader io.Reader) (*MesosCloud, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (c *MesosCloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *MesosCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
func (c *MesosCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -317,6 +317,11 @@ func getAddressByName(api *gophercloud.ServiceClient, name string) (string, erro
|
|||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (i *Instances) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -275,6 +275,11 @@ func (v *OVirtCloud) GetNodeResources(name string) (*api.NodeResources, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (v *OVirtCloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (v *OVirtCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
func (v *OVirtCloud) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
@ -380,6 +380,11 @@ func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {
|
|||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (i *Instances) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (i *Instances) GetNodeResources(name string) (*api.NodeResources, error) {
|
func (i *Instances) GetNodeResources(name string) (*api.NodeResources, error) {
|
||||||
glog.V(2).Infof("GetNodeResources(%v) called", name)
|
glog.V(2).Infof("GetNodeResources(%v) called", name)
|
||||||
|
|
||||||
|
@ -135,6 +135,11 @@ func (v *VagrantCloud) AddSSHKeyToAllInstances(user string, keyData []byte) erro
|
|||||||
return errors.New("unimplemented")
|
return errors.New("unimplemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Implementation of Instances.CurrentNodeName
|
||||||
|
func (v *VagrantCloud) CurrentNodeName(hostname string) (string, error) {
|
||||||
|
return hostname, nil
|
||||||
|
}
|
||||||
|
|
||||||
// NodeAddresses returns the NodeAddresses of a particular machine instance.
|
// NodeAddresses returns the NodeAddresses of a particular machine instance.
|
||||||
func (v *VagrantCloud) NodeAddresses(instance string) ([]api.NodeAddress, error) {
|
func (v *VagrantCloud) NodeAddresses(instance string) ([]api.NodeAddress, error) {
|
||||||
// Due to vagrant not running with a dedicated DNS setup, we return the IP address of a minion as its hostname at this time
|
// Due to vagrant not running with a dedicated DNS setup, we return the IP address of a minion as its hostname at this time
|
||||||
|
@ -1849,6 +1849,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
|
|||||||
}
|
}
|
||||||
// TODO(roberthbailey): Can we do this without having credentials to talk
|
// TODO(roberthbailey): Can we do this without having credentials to talk
|
||||||
// to the cloud provider?
|
// to the cloud provider?
|
||||||
|
// TODO(justinsb): We can if CurrentNodeName() was actually CurrentNode() and returned an interface
|
||||||
nodeAddresses, err := instances.NodeAddresses(kl.nodeName)
|
nodeAddresses, err := instances.NodeAddresses(kl.nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get node address from cloud provider: %v", err)
|
return fmt.Errorf("failed to get node address from cloud provider: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user