Unverified Commit 7a1e4445 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #61890 from dims/better-specify-dhcp-domain-for-hostname

Automatic merge from submit-queue (batch tested with PRs 61871, 61890, 61786). 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>. Specify DHCP domain for hostname **What this PR does / why we need it**: In 9a8c6db4, we looked at the hostname in the metadata service and used '.' as the delimiter to chop off the dhcp_domain (specified in nova.conf). However administrators need to better control the dhcp domain better as there may be a '.' in the host name itself. So let's introduce a config option that we can use and default it to what nova uses when dhcp_domain is not specified which is "novalocal" **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 # **Special notes for your reviewer**: **Release note**: ```release-note new dhcp-domain parameter to be used for figuring out the hostname of a node ```
parents 718568a9 da5ccf7f
...@@ -121,6 +121,7 @@ type RouterOpts struct { ...@@ -121,6 +121,7 @@ type RouterOpts struct {
type MetadataOpts struct { type MetadataOpts struct {
SearchOrder string `gcfg:"search-order"` SearchOrder string `gcfg:"search-order"`
RequestTimeout MyDuration `gcfg:"request-timeout"` RequestTimeout MyDuration `gcfg:"request-timeout"`
DHCPDomain string `gcfg:"dhcp-domain"`
} }
// OpenStack is an implementation of cloud provider Interface for OpenStack. // OpenStack is an implementation of cloud provider Interface for OpenStack.
...@@ -233,6 +234,7 @@ func configFromEnv() (cfg Config, ok bool) { ...@@ -233,6 +234,7 @@ func configFromEnv() (cfg Config, ok bool) {
cfg.Global.TrustID != "") cfg.Global.TrustID != "")
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
cfg.BlockStorage.BSVersion = "auto" cfg.BlockStorage.BSVersion = "auto"
return return
...@@ -250,6 +252,7 @@ func readConfig(config io.Reader) (Config, error) { ...@@ -250,6 +252,7 @@ func readConfig(config io.Reader) (Config, error) {
cfg.BlockStorage.TrustDevicePath = false cfg.BlockStorage.TrustDevicePath = false
cfg.BlockStorage.IgnoreVolumeAZ = false cfg.BlockStorage.IgnoreVolumeAZ = false
cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID) cfg.Metadata.SearchOrder = fmt.Sprintf("%s,%s", configDriveID, metadataID)
cfg.Metadata.DHCPDomain = "novalocal"
err := gcfg.ReadInto(&cfg, config) err := gcfg.ReadInto(&cfg, config)
return cfg, err return cfg, err
......
...@@ -61,6 +61,10 @@ func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types ...@@ -61,6 +61,10 @@ func (i *Instances) CurrentNodeName(ctx context.Context, hostname string) (types
if err != nil { if err != nil {
return "", err return "", err
} }
domain := "." + i.opts.DHCPDomain
if i.opts.DHCPDomain != "" && strings.HasSuffix(md.Hostname, domain) {
return types.NodeName(strings.TrimSuffix(md.Hostname, domain)), nil
}
return types.NodeName(strings.Split(md.Hostname, ".")[0]), nil return types.NodeName(strings.Split(md.Hostname, ".")[0]), nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment