Skip to content

Commit

Permalink
Check profile, node name to prevent duplication
Browse files Browse the repository at this point in the history
Check profile and node name before add to prevent conflict with
machine name on multinode cluster.
  • Loading branch information
daehyeok committed Jan 9, 2021
1 parent f17951c commit 2fac486
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ func runStart(cmd *cobra.Command, args []string) {

if existing != nil {
upgradeExistingConfig(existing)
} else {
validPs, _, err := config.ListProfiles()
if err != nil {
exit.Message(reason.InternalListConfig, "Unable to list profiles: {{.error}}", out.V{"error": err})
}
for _, ps := range validPs {
for _, existNode := range ps.Config.Nodes {
machineName := config.MachineName(*ps.Config, existNode)
if ClusterFlagValue() == machineName {
out.WarningT("Profile name '{{.name}}' is duplicated with machine name '{{.machine}}' in profile '{{.profile}}'", out.V{"name": ClusterFlagValue(),
"machine": machineName,
"profile": ps.Name})
exit.Message(reason.Usage, "Profile name should be unique")
}
}
}
}

validateSpecifiedDriver(existing)
Expand Down
2 changes: 1 addition & 1 deletion pkg/minikube/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func ProfileFolderPath(profile string, miniHome ...string) string {
// MachineName returns the name of the machine, as seen by the hypervisor given the cluster and node names
func MachineName(cc ClusterConfig, n Node) string {
// For single node cluster, default to back to old naming
if len(cc.Nodes) == 1 || n.ControlPlane {
if (len(cc.Nodes) == 1 && cc.Nodes[0].Name == n.Name) || n.ControlPlane {
return cc.Name
}
return fmt.Sprintf("%s-%s", cc.Name, n.Name)
Expand Down
14 changes: 14 additions & 0 deletions pkg/minikube/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ const (

// Add adds a new node config to an existing cluster.
func Add(cc *config.ClusterConfig, n config.Node, delOnFail bool) error {
validPs, _, err := config.ListProfiles()
if err != nil {
return err
}

machineName := config.MachineName(*cc, n)
for _, ps := range validPs {
for _, existNode := range ps.Config.Nodes {
if machineName == config.MachineName(*ps.Config, existNode) {
return errors.Errorf("Node %s already exists in %s profile", machineName, ps.Name)
}
}
}

if err := config.SaveNode(cc, &n); err != nil {
return errors.Wrap(err, "save node")
}
Expand Down

0 comments on commit 2fac486

Please sign in to comment.