Skip to content

Commit 2fac486

Browse files
committed
Check profile, node name to prevent duplication
Check profile and node name before add to prevent conflict with machine name on multinode cluster.
1 parent f17951c commit 2fac486

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Diff for: cmd/minikube/cmd/start.go

+16
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,22 @@ func runStart(cmd *cobra.Command, args []string) {
176176

177177
if existing != nil {
178178
upgradeExistingConfig(existing)
179+
} else {
180+
validPs, _, err := config.ListProfiles()
181+
if err != nil {
182+
exit.Message(reason.InternalListConfig, "Unable to list profiles: {{.error}}", out.V{"error": err})
183+
}
184+
for _, ps := range validPs {
185+
for _, existNode := range ps.Config.Nodes {
186+
machineName := config.MachineName(*ps.Config, existNode)
187+
if ClusterFlagValue() == machineName {
188+
out.WarningT("Profile name '{{.name}}' is duplicated with machine name '{{.machine}}' in profile '{{.profile}}'", out.V{"name": ClusterFlagValue(),
189+
"machine": machineName,
190+
"profile": ps.Name})
191+
exit.Message(reason.Usage, "Profile name should be unique")
192+
}
193+
}
194+
}
179195
}
180196

181197
validateSpecifiedDriver(existing)

Diff for: pkg/minikube/config/profile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ func ProfileFolderPath(profile string, miniHome ...string) string {
291291
// MachineName returns the name of the machine, as seen by the hypervisor given the cluster and node names
292292
func MachineName(cc ClusterConfig, n Node) string {
293293
// For single node cluster, default to back to old naming
294-
if len(cc.Nodes) == 1 || n.ControlPlane {
294+
if (len(cc.Nodes) == 1 && cc.Nodes[0].Name == n.Name) || n.ControlPlane {
295295
return cc.Name
296296
}
297297
return fmt.Sprintf("%s-%s", cc.Name, n.Name)

Diff for: pkg/minikube/node/node.go

+14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ const (
3838

3939
// Add adds a new node config to an existing cluster.
4040
func Add(cc *config.ClusterConfig, n config.Node, delOnFail bool) error {
41+
validPs, _, err := config.ListProfiles()
42+
if err != nil {
43+
return err
44+
}
45+
46+
machineName := config.MachineName(*cc, n)
47+
for _, ps := range validPs {
48+
for _, existNode := range ps.Config.Nodes {
49+
if machineName == config.MachineName(*ps.Config, existNode) {
50+
return errors.Errorf("Node %s already exists in %s profile", machineName, ps.Name)
51+
}
52+
}
53+
}
54+
4155
if err := config.SaveNode(cc, &n); err != nil {
4256
return errors.Wrap(err, "save node")
4357
}

0 commit comments

Comments
 (0)