Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Add CRS re-reconcile to ownerReference test #9296

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(), namespace)

// 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, namespace string) {
crsList := &addonsv1.ClusterResourceSetList{}
Expect(cli.List(ctx, crsList, client.InNamespace(namespace))).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
Loading