Move KubeNodeName out of driver package

pull/7141/head
Zhongcheng Lao 2020-03-22 15:11:03 +08:00
parent 15b1647b42
commit 43b5f7c86d
No known key found for this signature in database
GPG Key ID: 3B0C92A7E58EF413
3 changed files with 13 additions and 13 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: KubeNodeName(cc, n),
CRISocket: r.SocketPath(),
ImageRepository: k8s.ImageRepository,
ComponentOptions: componentOpts,

View File

@ -19,6 +19,7 @@ package bsutil
import (
"bytes"
"os"
"path"
"github.com/pkg/errors"
@ -60,7 +61,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 := KubeNodeName(mc, nc)
if nodeName != "" {
extraOpts["hostname-override"] = nodeName
}
@ -117,3 +118,13 @@ func NewKubeletService(cfg config.KubernetesConfig) ([]byte, error) {
}
return b.Bytes(), nil
}
// KubeNodeName returns the node name registered in Kubernetes
func KubeNodeName(cc config.ClusterConfig, n config.Node) string {
if cc.Driver == driver.None {
// Always use hostname for "none" driver
hostname, _ := os.Hostname()
return hostname
}
return driver.MachineName(cc, n)
}

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, "---") {