Revert "Make node name registered in K8s part of Node type"

This reverts commit 6ff82c6246.
pull/7141/head
Zhongcheng Lao 2020-03-22 15:06:38 +08:00
parent 6ff82c6246
commit 15b1647b42
No known key found for this signature in database
GPG Key ID: 3B0C92A7E58EF413
4 changed files with 14 additions and 14 deletions

View File

@ -29,6 +29,7 @@ import (
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/vmpath"
"k8s.io/minikube/pkg/util"
)
@ -93,7 +94,7 @@ func GenerateKubeadmYAML(cc config.ClusterConfig, n config.Node, r cruntime.Mana
EtcdDataDir: EtcdDataDir(),
ClusterName: cc.Name,
//kubeadm uses NodeName as the --hostname-override parameter, so this needs to be the name of the machine
NodeName: n.InternalName(),
NodeName: driver.KubeNodeName(cc, n),
CRISocket: r.SocketPath(),
ImageRepository: k8s.ImageRepository,
ComponentOptions: componentOpts,

View File

@ -26,6 +26,7 @@ import (
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
"k8s.io/minikube/pkg/minikube/config"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/util"
)
@ -59,7 +60,7 @@ func extraKubeletOpts(mc config.ClusterConfig, nc config.Node, r cruntime.Manage
if _, ok := extraOpts["node-ip"]; !ok {
extraOpts["node-ip"] = cp.IP
}
nodeName := nc.InternalName()
nodeName := driver.KubeNodeName(mc, nc)
if nodeName != "" {
extraOpts["hostname-override"] = nodeName
}

View File

@ -18,7 +18,6 @@ package config
import (
"net"
"os"
"github.com/blang/semver"
)
@ -103,17 +102,6 @@ type Node struct {
Worker bool
}
// returns the name to be registered kubernetes
func (n Node) InternalName() string {
if n.Name == "" {
// Always use hostname for "none" driver
hostname, _ := os.Hostname()
return hostname
}
return n.Name
}
// VersionedExtraOption holds information on flags to apply to a specific range
// of versions
type VersionedExtraOption struct {

View File

@ -237,6 +237,16 @@ func MachineName(cc config.ClusterConfig, n config.Node) string {
return fmt.Sprintf("%s---%s", cc.Name, n.Name)
}
// KubeNodeName returns the node name registered in Kubernetes
func KubeNodeName(cc config.ClusterConfig, n config.Node) string {
if cc.Driver == None {
// Always use hostname for "none" driver
hostname, _ := os.Hostname()
return hostname
}
return MachineName(cc, n)
}
// ClusterNameFromMachine retrieves the cluster name embedded in the machine name
func ClusterNameFromMachine(name string) (string, string) {
if strings.Contains(name, "---") {