Skip to content

Commit 2c44bf1

Browse files
Add CRS re-reconcile to ownerReference test
Signed-off-by: killianmuldoon <[email protected]>
1 parent 3b55934 commit 2c44bf1

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

test/framework/ownerreference_helpers.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,23 @@ import (
4545
func ValidateOwnerReferencesOnUpdate(ctx context.Context, proxy ClusterProxy, namespace, clusterName string, assertFuncs ...map[string]func(reference []metav1.OwnerReference) error) {
4646
clusterKey := client.ObjectKey{Namespace: namespace, Name: clusterName}
4747

48-
// Changes the version of all the owner references to v1alpha1. Expect the apiVersion to be updated after reconciliation.
48+
// Pause the cluster.
4949
setClusterPause(ctx, proxy.GetClient(), clusterKey, true)
5050

5151
// Change the version of the OwnerReferences on each object in the Graph to "v1alpha1"
5252
changeOwnerReferencesAPIVersion(ctx, proxy, namespace)
5353

54+
// Unpause the cluster.
5455
setClusterPause(ctx, proxy.GetClient(), clusterKey, false)
5556

56-
// Annotate the clusterClass, if one is in use, to speed up reconciliation. This ensures ClusterClass ownerReferences
57-
// are re-reconciled before asserting the owner reference graph.
57+
// Force ClusterClass reconciliation. This ensures ClusterClass ownerReferences are re-reconciled before asserting
58+
// the owner reference graph.
5859
forceClusterClassReconcile(ctx, proxy.GetClient(), clusterKey)
5960

61+
// Force ClusterResourceSet reconciliation. This ensures ClusterResourceBinding ownerReferences are re-reconciled before
62+
// asserting the owner reference graph.
63+
forceClusterResourceSetReconcile(ctx, proxy.GetClient(), namespace)
64+
6065
// Check that the ownerReferences have updated their apiVersions to current versions after reconciliation.
6166
AssertOwnerReferences(namespace, proxy.GetKubeconfigPath(), assertFuncs...)
6267
}
@@ -79,6 +84,7 @@ func ValidateOwnerReferencesResilience(ctx context.Context, proxy ClusterProxy,
7984
// Once all Clusters are paused remove the OwnerReference from all objects in the graph.
8085
removeOwnerReferences(ctx, proxy, namespace)
8186

87+
// Unpause the cluster.
8288
setClusterPause(ctx, proxy.GetClient(), clusterKey, false)
8389

8490
// Annotate the clusterClass, if one is in use, to speed up reconciliation. This ensures ClusterClass ownerReferences
@@ -367,6 +373,16 @@ func forceClusterClassReconcile(ctx context.Context, cli client.Client, clusterK
367373
}
368374
}
369375

376+
// forceClusterResourceSetReconcile forces reconciliation of all ClusterResourceSets.
377+
func forceClusterResourceSetReconcile(ctx context.Context, cli client.Client, namespace string) {
378+
crsList := &addonsv1.ClusterResourceSetList{}
379+
Expect(cli.List(ctx, crsList, client.InNamespace(namespace))).To(Succeed())
380+
for _, crs := range crsList.Items {
381+
annotationPatch := client.RawPatch(types.MergePatchType, []byte(fmt.Sprintf("{\"metadata\":{\"annotations\":{\"cluster.x-k8s.io/modifiedAt\":\"%v\"}}}", time.Now().Format(time.RFC3339))))
382+
Expect(cli.Patch(ctx, crs.DeepCopy(), annotationPatch)).To(Succeed())
383+
}
384+
}
385+
370386
func changeOwnerReferencesAPIVersion(ctx context.Context, proxy ClusterProxy, namespace string) {
371387
graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, proxy.GetKubeconfigPath())
372388
Expect(err).ToNot(HaveOccurred())

0 commit comments

Comments
 (0)