From f9ed4a64600f7312f032c4d0f7098ee99da28ba4 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Tue, 17 Sep 2019 23:29:57 +0800 Subject: [PATCH 1/9] Allow user to override node name Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 4 +++- pkg/minikube/bootstrapper/bsutil/kubelet.go | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index a3ff0039851b..1b9a25f68457 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -95,6 +95,7 @@ const ( keepContext = "keep-context" createMount = "mount" featureGates = "feature-gates" + nodeName = "node-name" apiServerName = "apiserver-name" apiServerPort = "apiserver-port" dnsDomain = "dns-domain" @@ -193,6 +194,7 @@ func initKubernetesFlags() { startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") + startCmd.Flags().String(nodeName, constants.DefaultNodeName, "The node name") } // initDriverFlags inits the commandline flags for vm drivers @@ -921,7 +923,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) KubernetesConfig: cfg.KubernetesConfig{ KubernetesVersion: k8sVersion, NodePort: viper.GetInt(apiServerPort), - NodeName: constants.DefaultNodeName, + NodeName: viper.GetString(nodeName), APIServerName: viper.GetString(apiServerName), APIServerNames: apiServerNames, APIServerIPs: apiServerIPs, diff --git a/pkg/minikube/bootstrapper/bsutil/kubelet.go b/pkg/minikube/bootstrapper/bsutil/kubelet.go index 48864d80feeb..aea5bad07f6f 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubelet.go +++ b/pkg/minikube/bootstrapper/bsutil/kubelet.go @@ -50,6 +50,9 @@ func NewKubeletConfig(k8s config.KubernetesConfig, r cruntime.Manager) ([]byte, if _, ok := extraOpts["node-ip"]; !ok { extraOpts["node-ip"] = k8s.NodeIP } + if k8s.NodeName != "" { + extraOpts["hostname-override"] = k8s.NodeName + } pauseImage := images.Pause(k8s.ImageRepository) if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != remoteContainerRuntime { From 914c34cc2ab09957ad980d38f844fe05c20de2bb Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Thu, 19 Sep 2019 08:48:07 +0800 Subject: [PATCH 2/9] Set node name in non-default profile Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 1b9a25f68457..f2b9106bec27 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -194,7 +194,7 @@ func initKubernetesFlags() { startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") - startCmd.Flags().String(nodeName, constants.DefaultNodeName, "The node name") + startCmd.Flags().String(nodeName, "", "The node name") } // initDriverFlags inits the commandline flags for vm drivers @@ -888,6 +888,16 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository}) } + kubeNodeName := viper.GetString(nodeName) + if kubeNodeName == "" { + machineName := viper.GetString(cfg.MachineProfile) + if machineName != constants.DefaultMachineName { + kubeNodeName = fmt.Sprintf("%s-%s", constants.DefaultNodeName, machineName) + } else { + kubeNodeName = constants.DefaultNodeName + } + } + cfg := cfg.MachineConfig{ Name: viper.GetString(cfg.MachineProfile), KeepContext: viper.GetBool(keepContext), @@ -923,7 +933,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) KubernetesConfig: cfg.KubernetesConfig{ KubernetesVersion: k8sVersion, NodePort: viper.GetInt(apiServerPort), - NodeName: viper.GetString(nodeName), + NodeName: kubeNodeName, APIServerName: viper.GetString(apiServerName), APIServerNames: apiServerNames, APIServerIPs: apiServerIPs, From 73608d60e47df2604c1883df8c7af48bc7b9c08c Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Fri, 3 Jan 2020 00:32:05 +0800 Subject: [PATCH 3/9] Set node name the same as host name by default for none driver Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index f2b9106bec27..064f97627d59 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -890,11 +890,19 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) kubeNodeName := viper.GetString(nodeName) if kubeNodeName == "" { - machineName := viper.GetString(cfg.MachineProfile) - if machineName != constants.DefaultMachineName { - kubeNodeName = fmt.Sprintf("%s-%s", constants.DefaultNodeName, machineName) - } else { - kubeNodeName = constants.DefaultNodeName + if drvName == driver.None { + // set the node name the same as host name for none driver + hostname, _ := os.Hostname() + kubeNodeName = hostname + } + + if kubeNodeName == "" { + machineName := viper.GetString(cfg.MachineProfile) + if machineName != constants.DefaultMachineName { + kubeNodeName = fmt.Sprintf("%s-%s", constants.DefaultNodeName, machineName) + } else { + kubeNodeName = constants.DefaultNodeName + } } } From d3ff888743aa2a56a6a1fa0ab9299e94d77172a7 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Wed, 8 Jan 2020 14:30:40 +0800 Subject: [PATCH 4/9] Use profile name as the node name Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 064f97627d59..79aa60c34da8 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -194,7 +194,6 @@ func initKubernetesFlags() { startCmd.Flags().String(apiServerName, constants.APIServerName, "The apiserver name which is used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().StringArrayVar(&apiServerNames, "apiserver-names", nil, "A set of apiserver names which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") startCmd.Flags().IPSliceVar(&apiServerIPs, "apiserver-ips", nil, "A set of apiserver IP Addresses which are used in the generated certificate for kubernetes. This can be used if you want to make the apiserver available from outside the machine") - startCmd.Flags().String(nodeName, "", "The node name") } // initDriverFlags inits the commandline flags for vm drivers @@ -888,22 +887,15 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository}) } - kubeNodeName := viper.GetString(nodeName) - if kubeNodeName == "" { - if drvName == driver.None { - // set the node name the same as host name for none driver - hostname, _ := os.Hostname() - kubeNodeName = hostname - } + var kubeNodeName string + if drvName == driver.None { + // set the node name the same as host name for none driver + hostname, _ := os.Hostname() + kubeNodeName = hostname + } - if kubeNodeName == "" { - machineName := viper.GetString(cfg.MachineProfile) - if machineName != constants.DefaultMachineName { - kubeNodeName = fmt.Sprintf("%s-%s", constants.DefaultNodeName, machineName) - } else { - kubeNodeName = constants.DefaultNodeName - } - } + if kubeNodeName == "" { + kubeNodeName = viper.GetString(cfg.MachineProfile) } cfg := cfg.MachineConfig{ From be7b52791ab4dfb32a4450e74f8c75087b09f3f4 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Wed, 8 Jan 2020 15:40:48 +0800 Subject: [PATCH 5/9] Remove unused var Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index f528acd3f28e..b72650dfa20d 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -96,7 +96,6 @@ const ( keepContext = "keep-context" createMount = "mount" featureGates = "feature-gates" - nodeName = "node-name" apiServerName = "apiserver-name" apiServerPort = "apiserver-port" dnsDomain = "dns-domain" From 05128825209f020306a78d117c51c75fa1178242 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Thu, 9 Jan 2020 19:51:29 +0800 Subject: [PATCH 6/9] Do not set host-override for kubelet by default Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 8 +------- pkg/minikube/bootstrapper/bsutil/versions.go | 2 -- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index b72650dfa20d..0a2080b2dbc0 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -908,13 +908,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) } var kubeNodeName string - if drvName == driver.None { - // set the node name the same as host name for none driver - hostname, _ := os.Hostname() - kubeNodeName = hostname - } - - if kubeNodeName == "" { + if drvName != driver.None { kubeNodeName = viper.GetString(cfg.MachineProfile) } diff --git a/pkg/minikube/bootstrapper/bsutil/versions.go b/pkg/minikube/bootstrapper/bsutil/versions.go index 39644abced92..bb6445ae44b7 100644 --- a/pkg/minikube/bootstrapper/bsutil/versions.go +++ b/pkg/minikube/bootstrapper/bsutil/versions.go @@ -23,7 +23,6 @@ import ( "github.com/blang/semver" "github.com/pkg/errors" "k8s.io/minikube/pkg/minikube/config" - "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/vmpath" "k8s.io/minikube/pkg/util" ) @@ -71,7 +70,6 @@ var versionSpecificOpts = []config.VersionedExtraOption{ }, LessThanOrEqual: semver.MustParse("1.9.10"), }, - config.NewUnversionedOption(Kubelet, "hostname-override", constants.DefaultNodeName), // System pods args config.NewUnversionedOption(Kubelet, "pod-manifest-path", vmpath.GuestManifestsDir), From 4a1f33e2823f4231e4bc9be29f7c4a1d29bcdcd1 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Thu, 9 Jan 2020 16:46:07 +0800 Subject: [PATCH 7/9] Adds cluster name to kubenetes config Signed-off-by: Zhongcheng Lao --- cmd/minikube/cmd/start.go | 1 + pkg/minikube/bootstrapper/bsutil/kubeadm.go | 2 ++ pkg/minikube/bootstrapper/bsutil/kubeadm_test.go | 2 ++ pkg/minikube/bootstrapper/bsutil/template/template.go | 4 ++-- pkg/minikube/config/types.go | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/minikube/cmd/start.go b/cmd/minikube/cmd/start.go index 0a2080b2dbc0..71db6a9208dc 100644 --- a/cmd/minikube/cmd/start.go +++ b/cmd/minikube/cmd/start.go @@ -947,6 +947,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string) KubernetesConfig: cfg.KubernetesConfig{ KubernetesVersion: k8sVersion, NodePort: viper.GetInt(apiServerPort), + ClusterName: viper.GetString(cfg.MachineProfile), NodeName: kubeNodeName, APIServerName: viper.GetString(apiServerName), APIServerNames: apiServerNames, diff --git a/pkg/minikube/bootstrapper/bsutil/kubeadm.go b/pkg/minikube/bootstrapper/bsutil/kubeadm.go index db580f3622f7..c5aae34eeb6e 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubeadm.go +++ b/pkg/minikube/bootstrapper/bsutil/kubeadm.go @@ -67,6 +67,7 @@ func GenerateKubeadmYAML(k8s config.KubernetesConfig, r cruntime.Manager) ([]byt APIServerPort int KubernetesVersion string EtcdDataDir string + ClusterName string NodeName string DNSDomain string CRISocket string @@ -82,6 +83,7 @@ func GenerateKubeadmYAML(k8s config.KubernetesConfig, r cruntime.Manager) ([]byt APIServerPort: nodePort, KubernetesVersion: k8s.KubernetesVersion, EtcdDataDir: EtcdDataDir(), + ClusterName: k8s.ClusterName, NodeName: k8s.NodeName, CRISocket: r.SocketPath(), ImageRepository: k8s.ImageRepository, diff --git a/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go b/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go index c0b90a2b4de9..8894e9ba524e 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go +++ b/pkg/minikube/bootstrapper/bsutil/kubeadm_test.go @@ -121,6 +121,7 @@ func TestGenerateKubeadmYAMLDNS(t *testing.T) { cfg := tc.cfg cfg.NodeIP = "1.1.1.1" cfg.NodeName = "mk" + cfg.ClusterName = "kubernetes" cfg.KubernetesVersion = version + ".0" got, err := GenerateKubeadmYAML(cfg, runtime) @@ -189,6 +190,7 @@ func TestGenerateKubeadmYAML(t *testing.T) { cfg := tc.cfg cfg.NodeIP = "1.1.1.1" cfg.NodeName = "mk" + cfg.ClusterName = "kubernetes" cfg.KubernetesVersion = version + ".0" got, err := GenerateKubeadmYAML(cfg, runtime) diff --git a/pkg/minikube/bootstrapper/bsutil/template/template.go b/pkg/minikube/bootstrapper/bsutil/template/template.go index 92ac7975aec5..5cb617f6d85e 100644 --- a/pkg/minikube/bootstrapper/bsutil/template/template.go +++ b/pkg/minikube/bootstrapper/bsutil/template/template.go @@ -77,7 +77,7 @@ kind: ClusterConfiguration {{$i}}: {{$val}}{{end}} {{end -}} certificatesDir: {{.CertDir}} -clusterName: kubernetes +clusterName: {{.ClusterName}} controlPlaneEndpoint: localhost:{{.APIServerPort}} etcd: local: @@ -129,7 +129,7 @@ kind: ClusterConfiguration {{range $i, $val := .FeatureArgs}}{{$i}}: {{$val}} {{end -}}{{end -}} certificatesDir: {{.CertDir}} -clusterName: kubernetes +clusterName: {{.ClusterName}} controlPlaneEndpoint: localhost:{{.APIServerPort}} dns: type: CoreDNS diff --git a/pkg/minikube/config/types.go b/pkg/minikube/config/types.go index 79e7f186918c..b6863022e485 100644 --- a/pkg/minikube/config/types.go +++ b/pkg/minikube/config/types.go @@ -73,6 +73,7 @@ type KubernetesConfig struct { KubernetesVersion string NodeIP string NodePort int + ClusterName string NodeName string APIServerName string APIServerNames []string From c6340c78e726f7fdf2b86fffec82b084075be99f Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Mon, 3 Feb 2020 19:29:45 +0800 Subject: [PATCH 8/9] Fixes merge issue Signed-off-by: Zhongcheng Lao --- pkg/minikube/bootstrapper/bsutil/kubelet.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/minikube/bootstrapper/bsutil/kubelet.go b/pkg/minikube/bootstrapper/bsutil/kubelet.go index 3208df1d7f28..3f3ae294c44c 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubelet.go +++ b/pkg/minikube/bootstrapper/bsutil/kubelet.go @@ -60,8 +60,8 @@ func NewKubeletConfig(mc config.MachineConfig, r cruntime.Manager) ([]byte, erro if _, ok := extraOpts["node-ip"]; !ok { extraOpts["node-ip"] = cp.IP } - if k8s.NodeName != "" { - extraOpts["hostname-override"] = k8s.NodeName + if len(mc.Nodes) > 0 && mc.Nodes[0].Name != "" { + extraOpts["hostname-override"] = mc.Nodes[0].Name } pauseImage := images.Pause(k8s.ImageRepository) From fc85dd6d45ddf38a1068ed533a44c4df79e91b67 Mon Sep 17 00:00:00 2001 From: Zhongcheng Lao Date: Mon, 3 Feb 2020 22:31:59 +0800 Subject: [PATCH 9/9] Handle node info in kubelet config --- pkg/minikube/bootstrapper/bsutil/kubeadm.go | 1 + pkg/minikube/bootstrapper/bsutil/kubelet.go | 6 +++--- pkg/minikube/bootstrapper/bsutil/kubelet_test.go | 2 +- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 3 ++- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/bootstrapper/bsutil/kubeadm.go b/pkg/minikube/bootstrapper/bsutil/kubeadm.go index 8158ec151ade..8e40f3ab954f 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubeadm.go +++ b/pkg/minikube/bootstrapper/bsutil/kubeadm.go @@ -88,6 +88,7 @@ func GenerateKubeadmYAML(mc config.MachineConfig, r cruntime.Manager) ([]byte, e KubernetesVersion: k8s.KubernetesVersion, EtcdDataDir: EtcdDataDir(), ClusterName: k8s.ClusterName, + NodeName: cp.Name, CRISocket: r.SocketPath(), ImageRepository: k8s.ImageRepository, ExtraArgs: extraComponentConfig, diff --git a/pkg/minikube/bootstrapper/bsutil/kubelet.go b/pkg/minikube/bootstrapper/bsutil/kubelet.go index 3f3ae294c44c..f080a7eba758 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubelet.go +++ b/pkg/minikube/bootstrapper/bsutil/kubelet.go @@ -30,7 +30,7 @@ import ( // NewKubeletConfig generates a new systemd unit containing a configured kubelet // based on the options present in the KubernetesConfig. -func NewKubeletConfig(mc config.MachineConfig, r cruntime.Manager) ([]byte, error) { +func NewKubeletConfig(mc config.MachineConfig, nc config.Node, r cruntime.Manager) ([]byte, error) { k8s := mc.KubernetesConfig version, err := ParseKubernetesVersion(k8s.KubernetesVersion) if err != nil { @@ -60,8 +60,8 @@ func NewKubeletConfig(mc config.MachineConfig, r cruntime.Manager) ([]byte, erro if _, ok := extraOpts["node-ip"]; !ok { extraOpts["node-ip"] = cp.IP } - if len(mc.Nodes) > 0 && mc.Nodes[0].Name != "" { - extraOpts["hostname-override"] = mc.Nodes[0].Name + if nc.Name != "" { + extraOpts["hostname-override"] = nc.Name } pauseImage := images.Pause(k8s.ImageRepository) diff --git a/pkg/minikube/bootstrapper/bsutil/kubelet_test.go b/pkg/minikube/bootstrapper/bsutil/kubelet_test.go index b50a4b89ef83..d4bf9af4827f 100644 --- a/pkg/minikube/bootstrapper/bsutil/kubelet_test.go +++ b/pkg/minikube/bootstrapper/bsutil/kubelet_test.go @@ -177,7 +177,7 @@ ExecStart=/var/lib/minikube/binaries/v1.17.2/kubelet --authorization-mode=Webhoo t.Fatalf("runtime: %v", err) } - got, err := NewKubeletConfig(tc.cfg, runtime) + got, err := NewKubeletConfig(tc.cfg, tc.cfg.Nodes[0], runtime) if err != nil && !tc.shouldErr { t.Errorf("got unexpected error generating config: %v", err) return diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index d3801ddff8f8..e6b9505c44bb 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -464,7 +464,8 @@ func (k *Bootstrapper) UpdateCluster(cfg config.MachineConfig) error { return errors.Wrap(err, "generating kubeadm cfg") } - kubeletCfg, err := bsutil.NewKubeletConfig(cfg, r) + // TODO: multiple nodes + kubeletCfg, err := bsutil.NewKubeletConfig(cfg, cfg.Nodes[0], r) if err != nil { return errors.Wrap(err, "generating kubelet config") }