Skip to content

Commit 280e527

Browse files
clyang82k8s-ci-robot
authored andcommitted
support random generate cluster name (#984)
* support random generate cluster name Signed-off-by: Chun Lin Yang <[email protected]> * delete minikube cluster with name Signed-off-by: clyang82 <[email protected]> * fix lint error Signed-off-by: clyang82 <[email protected]> * Use the profile name generated during creation * remove the space to compile with this project-specific standard
1 parent 0b25546 commit 280e527

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

cmd/clusterctl/clusterdeployer/bootstrap/kind/kind.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ import (
2424

2525
"github.com/pkg/errors"
2626
"k8s.io/klog"
27+
"sigs.k8s.io/cluster-api/pkg/util"
2728
)
2829

2930
const (
30-
kindClusterName = "clusterapi"
31+
kindClusterNamePrefix = "clusterapi-"
3132
)
3233

3334
var (
@@ -55,7 +56,7 @@ func WithOptions(options []string) *Kind {
5556
}
5657
return true
5758
}() {
58-
options = append(options, fmt.Sprintf("name=%s", kindClusterName))
59+
options = append(options, fmt.Sprintf("name=%s", kindClusterNamePrefix+util.RandomString(5)))
5960
}
6061

6162
return &Kind{

cmd/clusterctl/clusterdeployer/bootstrap/minikube/minikube.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ import (
2525

2626
"github.com/pkg/errors"
2727
"k8s.io/klog"
28+
"sigs.k8s.io/cluster-api/pkg/util"
2829
)
2930

3031
const (
31-
minikubeClusterName = "clusterapi"
32+
minikubeClusterNamePrefix = "clusterapi-"
3233
)
3334

3435
type Minikube struct {
@@ -61,7 +62,7 @@ func WithOptionsAndKubeConfigPath(options []string, kubeconfigpath string) *Mini
6162
}
6263
return true
6364
}() {
64-
options = append(options, fmt.Sprintf("profile=%s", minikubeClusterName))
65+
options = append(options, fmt.Sprintf("profile=%s", minikubeClusterNamePrefix+util.RandomString(5)))
6566
}
6667

6768
return &Minikube{
@@ -94,7 +95,13 @@ func (m *Minikube) Create() error {
9495
}
9596

9697
func (m *Minikube) Delete() error {
97-
_, err := m.exec("delete")
98+
args := []string{"delete"}
99+
for _, opt := range m.options {
100+
if strings.HasPrefix(opt, "profile=") {
101+
args = append(args, fmt.Sprintf("--%v", opt))
102+
}
103+
}
104+
_, err := m.exec(args...)
98105
os.Remove(m.kubeconfigpath)
99106
return err
100107
}

0 commit comments

Comments
 (0)