Skip to content

Commit

Permalink
Add CRS re-reconcile to ownerReference test
Browse files Browse the repository at this point in the history
Signed-off-by: killianmuldoon <kmuldoon@vmware.com>
  • Loading branch information
killianmuldoon committed Aug 24, 2023
1 parent 3b55934 commit 1b1cf0d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions test/framework/ownerreference_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,23 @@ import (
func ValidateOwnerReferencesOnUpdate(ctx context.Context, proxy ClusterProxy, namespace, clusterName string, assertFuncs ...map[string]func(reference []metav1.OwnerReference) error) {
clusterKey := client.ObjectKey{Namespace: namespace, Name: clusterName}

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

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

// Unpause the cluster.
setClusterPause(ctx, proxy.GetClient(), clusterKey, false)

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

// Force ClusterResourceSet reconciliation. This ensures ClusterResourceBinding ownerReferences are re-reconciled before
// asserting the owner reference graph.
forceClusterResourceSetReconcile(ctx, proxy.GetClient())

// Check that the ownerReferences have updated their apiVersions to current versions after reconciliation.
AssertOwnerReferences(namespace, proxy.GetKubeconfigPath(), assertFuncs...)
}
Expand All @@ -79,6 +84,7 @@ func ValidateOwnerReferencesResilience(ctx context.Context, proxy ClusterProxy,
// Once all Clusters are paused remove the OwnerReference from all objects in the graph.
removeOwnerReferences(ctx, proxy, namespace)

// Unpause the cluster.
setClusterPause(ctx, proxy.GetClient(), clusterKey, false)

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

// forceClusterResourceSetReconcile forces reconciliation of all ClusterResourceSets.
func forceClusterResourceSetReconcile(ctx context.Context, cli client.Client) {
crsList := &addonsv1.ClusterResourceSetList{}
Expect(cli.List(ctx, crsList)).To(Succeed())
for _, crs := range crsList.Items {
annotationPatch := client.RawPatch(types.MergePatchType, []byte(fmt.Sprintf("{\"metadata\":{\"annotations\":{\"cluster.x-k8s.io/modifiedAt\":\"%v\"}}}", time.Now().Format(time.RFC3339))))
Expect(cli.Patch(ctx, crs.DeepCopy(), annotationPatch)).To(Succeed())
}
}

func changeOwnerReferencesAPIVersion(ctx context.Context, proxy ClusterProxy, namespace string) {
graph, err := clusterctlcluster.GetOwnerGraph(ctx, namespace, proxy.GetKubeconfigPath())
Expect(err).ToNot(HaveOccurred())
Expand Down

0 comments on commit 1b1cf0d

Please sign in to comment.