Skip to content

Commit

Permalink
Remove cluster's subnode from ListProfiles result.
Browse files Browse the repository at this point in the history
Fix prolbem which ListProfiles return subnodes in Mult-Node clusters as
a part of inValidPs.
  • Loading branch information
daehyeok committed Dec 18, 2020
1 parent c50f38b commit f2f74c5
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions pkg/minikube/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package config

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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)
Expand All @@ -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
}

Expand All @@ -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...)
Expand Down

0 comments on commit f2f74c5

Please sign in to comment.