Merge pull request #58502 from dixudx/register_openstack_hostname

Automatic merge from submit-queue (batch tested with PRs 57867, 58490, 58502, 58134). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Openstack: register metadata.hostname as node name

**What this PR does / why we need it**:
Currently Openstack can boot up instances with the name like `xyz/abc`, which is not a valid kubelet node name. While `hostname` retrieved from `meta_data.json` has already been sanitized 
 by Openstack to valid DNS-1123 format string. It's safe to register this `metadata.hostname` as valid kubelet node name.

/kind bug
/sig openstack

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #57765

**Special notes for your reviewer**:
/assign @dims @FengyunPan 

**Release note**:

```release-note
Openstack: register metadata.hostname as node name
```
This commit is contained in:
Kubernetes Submit Queue 2018-01-23 00:06:31 -08:00 committed by GitHub
commit 998490d4b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 5 deletions

View File

@ -69,7 +69,7 @@ type DeviceMetadata struct {
// See http://docs.openstack.org/user-guide/cli_config_drive.html
type Metadata struct {
Uuid string `json:"uuid"`
Name string `json:"name"`
Hostname string `json:"hostname"`
AvailabilityZone string `json:"availability_zone"`
Devices []DeviceMetadata `json:"devices,omitempty"`
// .. and other fields we don't care about. Expand as necessary.

View File

@ -23,7 +23,7 @@ import (
var FakeMetadata = Metadata{
Uuid: "83679162-1378-4288-a2d4-70e13ec132aa",
Name: "test",
Hostname: "test",
AvailabilityZone: "nova",
}
@ -81,8 +81,8 @@ func TestParseMetadata(t *testing.T) {
t.Fatalf("Should succeed when provided with valid data: %s", err)
}
if md.Name != "test" {
t.Errorf("incorrect name: %s", md.Name)
if md.Hostname != "test.novalocal" {
t.Errorf("incorrect hostname: %s", md.Hostname)
}
if md.Uuid != "83679162-1378-4288-a2d4-70e13ec132aa" {

View File

@ -58,7 +58,7 @@ func (i *Instances) CurrentNodeName(hostname string) (types.NodeName, error) {
if err != nil {
return "", err
}
return types.NodeName(md.Name), nil
return types.NodeName(md.Hostname), nil
}
func (i *Instances) AddSSHKeyToAllInstances(user string, keyData []byte) error {