@@ -107,6 +107,7 @@ type Framework struct {
107107 controllerRuntimeConfig * rest.Config
108108 Log gwlog.Logger
109109 LatticeClient services.Lattice
110+ TaggingClient services.Tagging
110111 Ec2Client * ec2.EC2
111112 GrpcurlRunner * corev1.Pod
112113 DefaultTags services.Tags
@@ -123,10 +124,12 @@ func NewFramework(ctx context.Context, log gwlog.Logger, testNamespace string) *
123124 Region : config .Region ,
124125 ClusterName : config .ClusterName ,
125126 }
127+ sess := session .Must (session .NewSession ())
126128 framework := & Framework {
127129 Client : lo .Must (client .New (controllerRuntimeConfig , client.Options {Scheme : testScheme })),
128- LatticeClient : services .NewDefaultLattice (session .Must (session .NewSession ()), config .Region ), // region is currently hardcoded
129- Ec2Client : ec2 .New (session .Must (session .NewSession (& aws.Config {Region : aws .String (config .Region )}))),
130+ LatticeClient : services .NewDefaultLattice (sess , config .Region ),
131+ TaggingClient : services .NewDefaultTagging (sess , config .Region ),
132+ Ec2Client : ec2 .New (sess , & aws.Config {Region : aws .String (config .Region )}),
130133 GrpcurlRunner : & corev1.Pod {},
131134 ctx : ctx ,
132135 Log : log ,
@@ -150,25 +153,17 @@ func (env *Framework) ExpectToBeClean(ctx context.Context) {
150153 })
151154
152155 Eventually (func (g Gomega ) {
153- retrievedServices , _ := env .LatticeClient .ListServicesAsList (ctx , & vpclattice.ListServicesInput {})
154- for _ , service := range retrievedServices {
155- env .Log .Infof ("Found service, checking if created by current EKS Cluster: %v" , service )
156- managed , err := env .Cloud .IsArnManaged (ctx , * service .Arn )
157- if err == nil { // ignore error as they can be a shared resource.
158- g .Expect (managed ).To (BeFalse ())
159- }
160- }
156+ arns , err := env .TaggingClient .FindResourcesByTags (ctx , services .ResourceTypeService , env .DefaultTags )
157+ env .Log .Infow ("Expecting no services created by the controller" , "found" , arns )
158+ g .Expect (err ).To (BeNil ())
159+ g .Expect (arns ).To (BeEmpty ())
160+ }).Should (Succeed ())
161161
162- retrievedTargetGroups , _ := env .LatticeClient .ListTargetGroupsAsList (ctx , & vpclattice.ListTargetGroupsInput {
163- VpcIdentifier : & config .VpcID ,
164- })
165- for _ , tg := range retrievedTargetGroups {
166- env .Log .Infof ("Found TargetGroup: %s, checking if created by current EKS Cluster" , * tg .Id )
167- managed , err := env .Cloud .IsArnManaged (ctx , * tg .Arn )
168- if err == nil { // ignore error as they can be a shared resource.
169- g .Expect (managed ).To (BeFalse ())
170- }
171- }
162+ Eventually (func (g Gomega ) {
163+ arns , err := env .TaggingClient .FindResourcesByTags (ctx , services .ResourceTypeTargetGroup , env .DefaultTags )
164+ env .Log .Infow ("Expecting no target groups created by the controller" , "found" , arns )
165+ g .Expect (err ).To (BeNil ())
166+ g .Expect (arns ).To (BeEmpty ())
172167 }).Should (Succeed ())
173168}
174169
0 commit comments