diff --git a/pkg/minikube/config/profile.go b/pkg/minikube/config/profile.go index 5bb5fc2f9d7d..45e0adf27e17 100644 --- a/pkg/minikube/config/profile.go +++ b/pkg/minikube/config/profile.go @@ -18,6 +18,7 @@ package config import ( "encoding/json" + "fmt" "io/ioutil" "os" "path/filepath" @@ -206,8 +207,9 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile, if err == nil { pDirs = append(pDirs, cs...) } - pDirs = removeDupes(pDirs) - for _, n := range pDirs { + + nodeNames := map[string]bool{} + for _, n := range removeDupes(pDirs) { p, err := LoadProfile(n, miniHome...) if err != nil { inValidPs = append(inValidPs, p) @@ -218,7 +220,13 @@ func ListProfiles(miniHome ...string) (validPs []*Profile, inValidPs []*Profile, continue } validPs = append(validPs, p) + + for _, child := range p.Config.Nodes { + nodeNames[MachineName(p.Config, &child)] = true + } } + + inValidPs = removeChildNodes(inValidPs, nodeNames) return validPs, inValidPs, nil } @@ -242,6 +250,27 @@ func removeDupes(profiles []string) []string { return result } +// TODO: MachineName is copied from driver to avoid dependency cycle. Remove it or move to other module +// 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 { + return cc.Name + } + return fmt.Sprintf("%s-%s", cc.Name, n.Name) +} + +func removeChildNodes(inValidPs []*Profile, nodeNames map[string]bool) []*Profile { + ps := []*Profile{} + for _, p := range inValidPs { + if _, ok := nodeNames[p.Name]; !ok { + ps = append(ps, p) + } + } + + return ps +} + // LoadProfile loads type Profile based on its name func LoadProfile(name string, miniHome ...string) (*Profile, error) { cfg, err := DefaultLoader.LoadConfigFromFile(name, miniHome...)