Skip to content

Commit

Permalink
Merge pull request #6200 from laozc/node-name
Browse files Browse the repository at this point in the history
Use profile name as cluster/node name
  • Loading branch information
sharifelgamal authored Feb 5, 2020
2 parents de1a491 + fc85dd6 commit 6d59d9d
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 8 deletions.
8 changes: 7 additions & 1 deletion cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,16 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string)
out.T(out.SuccessType, "Using image repository {{.name}}", out.V{"name": repository})
}

var kubeNodeName string
if drvName != driver.None {
kubeNodeName = viper.GetString(config.MachineProfile)
}

// Create the initial node, which will necessarily be a control plane
cp := config.Node{
Port: viper.GetInt(apiServerPort),
KubernetesVersion: k8sVersion,
Name: constants.DefaultNodeName,
Name: kubeNodeName,
ControlPlane: true,
Worker: true,
}
Expand Down Expand Up @@ -969,6 +974,7 @@ func generateCfgFromFlags(cmd *cobra.Command, k8sVersion string, drvName string)
NatNicType: viper.GetString(natNicType),
KubernetesConfig: config.KubernetesConfig{
KubernetesVersion: k8sVersion,
ClusterName: viper.GetString(config.MachineProfile),
APIServerName: viper.GetString(apiServerName),
APIServerNames: apiServerNames,
APIServerIPs: apiServerIPs,
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bsutil/ktmpl/v1alpha3.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ kind: ClusterConfiguration
{{$i}}: {{$val}}{{end}}
{{end -}}
certificatesDir: {{.CertDir}}
clusterName: kubernetes
clusterName: {{.ClusterName}}
apiServerCertSANs: ["127.0.0.1", "localhost", "{{.AdvertiseAddress}}"]
controlPlaneEndpoint: localhost:{{.APIServerPort}}
etcd:
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bsutil/ktmpl/v1beta1.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ kind: ClusterConfiguration
{{range $i, $val := .FeatureArgs}}{{$i}}: {{$val}}
{{end -}}{{end -}}
certificatesDir: {{.CertDir}}
clusterName: kubernetes
clusterName: {{.ClusterName}}
apiServer:
certSANs: ["127.0.0.1", "localhost", "{{.AdvertiseAddress}}"]
controlPlaneEndpoint: localhost:{{.APIServerPort}}
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/bootstrapper/bsutil/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func GenerateKubeadmYAML(mc config.MachineConfig, r cruntime.Manager) ([]byte, e
APIServerPort int
KubernetesVersion string
EtcdDataDir string
ClusterName string
NodeName string
DNSDomain string
CRISocket string
Expand All @@ -86,6 +87,7 @@ func GenerateKubeadmYAML(mc config.MachineConfig, r cruntime.Manager) ([]byte, e
APIServerPort: nodePort,
KubernetesVersion: k8s.KubernetesVersion,
EtcdDataDir: EtcdDataDir(),
ClusterName: k8s.ClusterName,
NodeName: cp.Name,
CRISocket: r.SocketPath(),
ImageRepository: k8s.ImageRepository,
Expand Down
2 changes: 2 additions & 0 deletions pkg/minikube/bootstrapper/bsutil/kubeadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func TestGenerateKubeadmYAMLDNS(t *testing.T) {
},
}
cfg.KubernetesConfig.KubernetesVersion = version + ".0"
cfg.KubernetesConfig.ClusterName = "kubernetes"

got, err := GenerateKubeadmYAML(cfg, runtime)
if err != nil && !tc.shouldErr {
Expand Down Expand Up @@ -207,6 +208,7 @@ func TestGenerateKubeadmYAML(t *testing.T) {
}
}
cfg.KubernetesConfig.KubernetesVersion = version + ".0"
cfg.KubernetesConfig.ClusterName = "kubernetes"

got, err := GenerateKubeadmYAML(cfg, runtime)
if err != nil && !tc.shouldErr {
Expand Down
5 changes: 4 additions & 1 deletion pkg/minikube/bootstrapper/bsutil/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -60,6 +60,9 @@ func NewKubeletConfig(mc config.MachineConfig, r cruntime.Manager) ([]byte, erro
if _, ok := extraOpts["node-ip"]; !ok {
extraOpts["node-ip"] = cp.IP
}
if nc.Name != "" {
extraOpts["hostname-override"] = nc.Name
}

pauseImage := images.Pause(k8s.ImageRepository)
if _, ok := extraOpts["pod-infra-container-image"]; !ok && k8s.ImageRepository != "" && pauseImage != "" && k8s.ContainerRuntime != remoteContainerRuntime {
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/bootstrapper/bsutil/kubelet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/minikube/bootstrapper/bsutil/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,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")
}
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type MachineConfig struct {
// KubernetesConfig contains the parameters used to configure the VM Kubernetes.
type KubernetesConfig struct {
KubernetesVersion string
ClusterName string
APIServerName string
APIServerNames []string
APIServerIPs []net.IP
Expand Down

0 comments on commit 6d59d9d

Please sign in to comment.