mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-06 10:43:56 +00:00
Merge pull request #7910 from yujuhong/hostname
Use the full hostname for mirror pod name.
This commit is contained in:
commit
5074e98ee9
@ -21,7 +21,6 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
@ -37,13 +36,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Generate a pod name that is unique among nodes by appending the hostname.
|
// Generate a pod name that is unique among nodes by appending the hostname.
|
||||||
func generatePodName(name, hostname string) (string, error) {
|
func generatePodName(name, hostname string) string {
|
||||||
// Hostname can be a fully-qualified domain name. To increase readability,
|
return fmt.Sprintf("%s-%s", name, hostname)
|
||||||
// only append the first chunk. Note that this assumes that no two nodes in
|
|
||||||
// the cluster should have the same host-specific label; this is true if
|
|
||||||
// all nodes have the same domain name.
|
|
||||||
chunks := strings.Split(hostname, ".")
|
|
||||||
return fmt.Sprintf("%s-%s", name, chunks[0]), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) error {
|
func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) error {
|
||||||
@ -62,13 +56,10 @@ func applyDefaults(pod *api.Pod, source string, isFile bool, hostname string) er
|
|||||||
|
|
||||||
// This is required for backward compatibility, and should be removed once we
|
// This is required for backward compatibility, and should be removed once we
|
||||||
// completely deprecate ContainerManifest.
|
// completely deprecate ContainerManifest.
|
||||||
var err error
|
|
||||||
if len(pod.Name) == 0 {
|
if len(pod.Name) == 0 {
|
||||||
pod.Name = string(pod.UID)
|
pod.Name = string(pod.UID)
|
||||||
}
|
}
|
||||||
if pod.Name, err = generatePodName(pod.Name, hostname); err != nil {
|
pod.Name = generatePodName(pod.Name, hostname)
|
||||||
return err
|
|
||||||
}
|
|
||||||
glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source)
|
glog.V(5).Infof("Generated Name %q for UID %q from URL %s", pod.Name, pod.UID, source)
|
||||||
|
|
||||||
if pod.Namespace == "" {
|
if pod.Namespace == "" {
|
||||||
|
@ -24,13 +24,16 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func GetHostname(hostnameOverride string) string {
|
func GetHostname(hostnameOverride string) string {
|
||||||
hostname := []byte(hostnameOverride)
|
hostname := hostnameOverride
|
||||||
if string(hostname) == "" {
|
if string(hostname) == "" {
|
||||||
fqdn, err := exec.Command("uname", "-n").Output()
|
nodename, err := exec.Command("uname", "-n").Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Fatalf("Couldn't determine hostname: %v", err)
|
glog.Fatalf("Couldn't determine hostname: %v", err)
|
||||||
}
|
}
|
||||||
hostname = fqdn
|
chunks := strings.Split(string(nodename), ".")
|
||||||
|
// nodename could be a fully-qualified domain name or not. Take the first
|
||||||
|
// word of nodename as the hostname for consistency.
|
||||||
|
hostname = chunks[0]
|
||||||
}
|
}
|
||||||
return strings.ToLower(strings.TrimSpace(string(hostname)))
|
return strings.ToLower(strings.TrimSpace(hostname))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user