Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix driver.IndexFromMachineName() #10821

Merged
merged 2 commits into from Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions pkg/minikube/driver/driver.go
Expand Up @@ -321,12 +321,16 @@ func SetLibvirtURI(v string) {

// IndexFromMachineName returns the order of the container based on it is name
func IndexFromMachineName(machineName string) int {
// minikube-m02
// minikube or offline-docker-20210314040449-6655 or minion-m02
sp := strings.Split(machineName, "-")
m := strings.Trim(sp[len(sp)-1], "m") // m02
i, err := strconv.Atoi(m)
if err != nil {
return 1
m := sp[len(sp)-1] // minikube or 6655 or m02
if strings.HasPrefix(m, "m") { // likely minion node
m = strings.TrimPrefix(m, "m")
i, err := strconv.Atoi(m)
if err != nil {
return 1 // master node
}
return i // minion node
}
return i
return 1 // master node
medyagh marked this conversation as resolved.
Show resolved Hide resolved
}
64 changes: 64 additions & 0 deletions pkg/minikube/driver/driver_test.go
Expand Up @@ -300,6 +300,70 @@ func TestIndexFromMachineNameClusterConfig(t *testing.T) {
},
Want: 2,
},

{
ClusterConfig: config.ClusterConfig{Name: "p3",
Nodes: []config.Node{
{
Name: "",
IP: "172.17.0.3",
Port: 8443,
KubernetesVersion: "v1.19.2",
ControlPlane: true,
Worker: true,
},
{
Name: "m02",
IP: "172.17.0.4",
Port: 0,
KubernetesVersion: "v1.19.2",
ControlPlane: false,
Worker: true,
},
{
Name: "m03",
IP: "172.17.0.5",
Port: 0,
KubernetesVersion: "v1.19.2",
ControlPlane: false,
Worker: true,
},
},
},
Want: 3,
},

{
ClusterConfig: config.ClusterConfig{Name: "offline-docker-20210314040449-6654",
Nodes: []config.Node{
{
Name: "",
IP: "172.17.0.3",
Port: 8443,
KubernetesVersion: "v1.19.2",
ControlPlane: true,
Worker: true,
},
},
},
Want: 1,
},

{
ClusterConfig: config.ClusterConfig{Name: "offline-docker-20210314040449-6655",
Nodes: []config.Node{
{
Name: "",
IP: "172.17.0.3",
Port: 8443,
KubernetesVersion: "v1.19.2",
ControlPlane: true,
Worker: true,
},
},
},
Want: 1,
},
}

for _, tc := range testsCases {
Expand Down