@@ -78,52 +78,43 @@ func (k *Cluster) getKubeconfig() (string, error) {
78
78
return file .Name (), nil
79
79
}
80
80
81
- func (k * Cluster ) CreateWithConfig (imageName , kindConfigFile string ) (string , error ) {
82
- log .V (4 ).Info ("Creating kind cluster " , k .name )
83
- if err := k .findOrInstallKind (k .e ); err != nil {
84
- return "" , err
85
- }
86
-
87
- if strings .Contains (k .e .Run ("kind get clusters" ), k .name ) {
88
- log .V (4 ).Info ("Skipping Kind Cluster.Create: cluster already created: " , k .name )
89
- return k .getKubeconfig ()
90
- }
91
-
92
- log .V (4 ).Info ("Launching: kind create cluster --name" , k .name , "--image" , imageName , "--config" , kindConfigFile )
93
- p := k .e .RunProc (fmt .Sprintf (`kind create cluster --name %s --image %s --config %s` , k .name , imageName , kindConfigFile ))
94
- if p .Err () != nil {
95
- return "" , fmt .Errorf ("failed to create kind cluster: %s : %s" , p .Err (), p .Result ())
96
- }
97
-
81
+ func (k * Cluster ) clusterExists (name string ) (string , bool ) {
98
82
clusters := k .e .Run ("kind get clusters" )
99
- if ! strings .Contains (clusters , k .name ) {
100
- return "" , fmt .Errorf ("kind Cluster.Create: cluster %v still not in 'cluster list' after creation: %v" , k .name , clusters )
83
+ for _ , c := range strings .Split (clusters , "\n " ) {
84
+ if c == name {
85
+ return clusters , true
86
+ }
101
87
}
102
- log .V (4 ).Info ("kind clusters available: " , clusters )
88
+ return clusters , false
89
+ }
103
90
104
- // Grab kubeconfig file for cluster.
105
- return k .getKubeconfig ( )
91
+ func ( k * Cluster ) CreateWithConfig ( imageName , kindConfigFile string ) ( string , error ) {
92
+ return k .Create ( "--image" , imageName , "--config" , kindConfigFile )
106
93
}
107
94
108
- func (k * Cluster ) Create () (string , error ) {
95
+ func (k * Cluster ) Create (args ... string ) (string , error ) {
109
96
log .V (4 ).Info ("Creating kind cluster " , k .name )
110
97
if err := k .findOrInstallKind (k .e ); err != nil {
111
98
return "" , err
112
99
}
113
100
114
- if strings . Contains ( k . e . Run ( "kind get clusters" ), k .name ) {
101
+ if _ , ok := k .clusterExists ( k . name ); ok {
115
102
log .V (4 ).Info ("Skipping Kind Cluster.Create: cluster already created: " , k .name )
116
103
return k .getKubeconfig ()
117
104
}
118
105
119
- log .V (4 ).Info ("Launching: kind create cluster --name" , k .name )
120
- p := k .e .RunProc (fmt .Sprintf (`kind create cluster --name %s` , k .name ))
106
+ command := fmt .Sprintf (`kind create cluster --name %s` , k .name )
107
+ if len (args ) > 0 {
108
+ command = fmt .Sprintf ("%s %s" , command , strings .Join (args , " " ))
109
+ }
110
+ log .V (4 ).Info ("Launching:" , command )
111
+ p := k .e .RunProc (command )
121
112
if p .Err () != nil {
122
113
return "" , fmt .Errorf ("failed to create kind cluster: %s : %s" , p .Err (), p .Result ())
123
114
}
124
115
125
- clusters := k .e . Run ( "kind get clusters" )
126
- if ! strings . Contains ( clusters , k . name ) {
116
+ clusters , ok := k .clusterExists ( k . name )
117
+ if ! ok {
127
118
return "" , fmt .Errorf ("kind Cluster.Create: cluster %v still not in 'cluster list' after creation: %v" , k .name , clusters )
128
119
}
129
120
log .V (4 ).Info ("kind clusters available: " , clusters )
0 commit comments