From 01cc1b5d80f1b23640c86157f147aeb2e5075d78 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 22 Feb 2024 09:57:52 +0000 Subject: [PATCH] test(e2e): Find specific CRS when checking if resource is applied Check the relevant ResourceSetBinding to see if the resource is applied. If multiple ClusterResourceSets match a cluster, the ClusterResourceSetBinding will have multiple bindings and so only the relevant ResourceSetBinding should be checked. --- test/e2e/clusterresourceset_helpers.go | 28 +++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/e2e/clusterresourceset_helpers.go b/test/e2e/clusterresourceset_helpers.go index ce8078a54..9afc4cb6d 100644 --- a/test/e2e/clusterresourceset_helpers.go +++ b/test/e2e/clusterresourceset_helpers.go @@ -110,18 +110,28 @@ func waitForClusterResourceSetToApplyResources( continue } - // Fix a bug from upstream to check all bindings. - resourceApplied := false - for _, binding := range binding.Spec.Bindings { - if binding.IsApplied(resource) { - resourceApplied = true - break - } - } - if !resourceApplied { + // Check relevant ResourceSetBinding to see if the resource is applied. If no ResourceSetBinding is found for + // the specified ClusterResourceSet, the resource has not applied. + resourceSetBinding, found := getResourceSetBindingForClusterResourceSet( + binding, + input.ClusterResourceSet, + ) + if !found || !resourceSetBinding.IsApplied(resource) { return false } } return true }, intervals...).Should(BeTrue()) } + +func getResourceSetBindingForClusterResourceSet( + clusterResourceSetBinding *addonsv1.ClusterResourceSetBinding, + clusterResourceSet *addonsv1.ClusterResourceSet, +) (*addonsv1.ResourceSetBinding, bool) { + for _, binding := range clusterResourceSetBinding.Spec.Bindings { + if binding.ClusterResourceSetName == clusterResourceSet.Name { + return binding, true + } + } + return nil, false +}