Make node name registered in K8s part of Node type

pull/7141/head
Zhongcheng Lao 2020-03-22 14:31:37 +08:00
parent 63aef4ab54
commit 6ff82c6246
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,7 +29,6 @@ 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"
)
@ -94,7 +93,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: driver.KubeNodeName(cc, n),
NodeName: n.InternalName(),
CRISocket: r.SocketPath(),
ImageRepository: k8s.ImageRepository,
ComponentOptions: componentOpts,

View File

@ -26,7 +26,6 @@ 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"
)
@ -60,7 +59,7 @@ func extraKubeletOpts(mc config.ClusterConfig, nc config.Node, r cruntime.Manage
if _, ok := extraOpts["node-ip"]; !ok {
extraOpts["node-ip"] = cp.IP
}
nodeName := driver.KubeNodeName(mc, nc)
nodeName := nc.InternalName()
if nodeName != "" {
extraOpts["hostname-override"] = nodeName
}

View File

@ -18,6 +18,7 @@ package config
import (
"net"
"os"
"github.com/blang/semver"
)
@ -102,6 +103,17 @@ 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,16 +237,6 @@ 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, "---") {