@@ -22,7 +22,6 @@ import (
22
22
23
23
. "github.com/onsi/ginkgo"
24
24
. "github.com/onsi/gomega"
25
-
26
25
apierrors "k8s.io/apimachinery/pkg/api/errors"
27
26
"sigs.k8s.io/cluster-api/test/framework/options"
28
27
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -56,6 +55,24 @@ func CreateCluster(ctx context.Context, input CreateClusterInput, intervals ...i
56
55
}, intervals ... ).Should (Succeed ())
57
56
}
58
57
58
+ // GetAllClustersByNamespaceInput is the input for GetAllClustersByNamespace.
59
+ type GetAllClustersByNamespaceInput struct {
60
+ Lister Lister
61
+ Namespace string
62
+ }
63
+
64
+ // GetClustersByNamespace returns the list of Cluster object in a namespace
65
+ func GetAllClustersByNamespace (ctx context.Context , input GetAllClustersByNamespaceInput ) []* clusterv1.Cluster {
66
+ clusterList := & clusterv1.ClusterList {}
67
+ Expect (input .Lister .List (ctx , clusterList , client .InNamespace (input .Namespace ))).To (Succeed (), "Failed to list clusters in namespace %s" , input .Namespace )
68
+
69
+ clusters := make ([]* clusterv1.Cluster , len (clusterList .Items ))
70
+ for i := range clusterList .Items {
71
+ clusters [i ] = & clusterList .Items [i ]
72
+ }
73
+ return clusters
74
+ }
75
+
59
76
// GetClusterByNameInput is the input for GetClusterByName.
60
77
type GetClusterByNameInput struct {
61
78
Getter Getter
@@ -194,6 +211,39 @@ func DeleteClusterAndWait(ctx context.Context, input DeleteClusterAndWaitInput,
194
211
Expect (resources ).To (BeEmpty (), "There are still Cluster API resources in the %q namespace" , input .Cluster .Namespace )
195
212
}
196
213
214
+ // DeleteAllClustersAndWaitInput is the input type for DeleteAllClustersAndWait.
215
+ type DeleteAllClustersAndWaitInput struct {
216
+ Client client.Client
217
+ Namespace string
218
+ }
219
+
220
+ // DeleteAllClustersAndWait deletes a cluster object and waits for it to be gone.
221
+ func DeleteAllClustersAndWait (ctx context.Context , input DeleteAllClustersAndWaitInput , intervals ... interface {}) {
222
+ Expect (ctx ).NotTo (BeNil (), "ctx is required for DeleteAllClustersAndWait" )
223
+ Expect (input .Client ).ToNot (BeNil (), "Invalid argument. input.Client can't be nil when calling DeleteAllClustersAndWait" )
224
+ Expect (input .Namespace ).ToNot (BeEmpty (), "Invalid argument. input.Namespace can't be empty when calling DeleteAllClustersAndWait" )
225
+
226
+ clusters := GetAllClustersByNamespace (ctx , GetAllClustersByNamespaceInput {
227
+ Lister : input .Client ,
228
+ Namespace : input .Namespace ,
229
+ })
230
+
231
+ for _ , c := range clusters {
232
+ DeleteCluster (ctx , DeleteClusterInput {
233
+ Deleter : input .Client ,
234
+ Cluster : c ,
235
+ })
236
+ }
237
+
238
+ for _ , c := range clusters {
239
+ fmt .Fprintf (GinkgoWriter , "Waiting for the Cluster %s/%s to be deleted\n " , c .Namespace , c .Name )
240
+ WaitForClusterDeleted (ctx , WaitForClusterDeletedInput {
241
+ Getter : input .Client ,
242
+ Cluster : c ,
243
+ }, intervals ... )
244
+ }
245
+ }
246
+
197
247
// byClusterOptions returns a set of ListOptions that allows to identify all the objects belonging to a Cluster.
198
248
func byClusterOptions (name , namespace string ) []client.ListOption {
199
249
return []client.ListOption {
0 commit comments