Skip to content

Commit 1606c6d

Browse files
authored
Merge pull request #12552 from fabriziopandini/fix-resourceversion-flake
🌱 Fix ResourceVersion flake for MachinePools
2 parents 3a40744 + a7e5aa7 commit 1606c6d

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

test/framework/resourceversion_helpers.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func ValidateResourceVersionStable(ctx context.Context, proxy ClusterProxy, name
5656
Consistently(func(g Gomega) {
5757
objectsWithResourceVersion, objects, err := getObjectsWithResourceVersion(ctx, proxy, namespace, ownerGraphFilterFunction)
5858
g.Expect(err).ToNot(HaveOccurred())
59-
g.Expect(objectsWithResourceVersion).To(BeComparableTo(previousResourceVersions), printObjectDiff(previousObjects, objects))
59+
g.Expect(previousResourceVersions).To(BeComparableTo(objectsWithResourceVersion), printObjectDiff(previousObjects, objects))
6060
}, 2*time.Minute, 15*time.Second).Should(Succeed(), "resourceVersions didn't stay stable")
6161
}
6262

@@ -132,5 +132,37 @@ func getObjectsWithResourceVersion(ctx context.Context, proxy ClusterProxy, name
132132
objectsWithResourceVersion[fmt.Sprintf("%s/%s/%s", node.Object.Kind, node.Object.Namespace, node.Object.Name)] = obj.GetResourceVersion()
133133
objects[fmt.Sprintf("%s/%s/%s", node.Object.Kind, node.Object.Namespace, node.Object.Name)] = obj
134134
}
135+
136+
// Drop KubeConfig owned by MachinePools (and corresponding dataSecret), because they can change when the token.
137+
keysToDelete := sets.Set[string]{}
138+
for key, obj := range objects {
139+
if obj.GetObjectKind().GroupVersionKind().Kind != "KubeadmConfig" {
140+
continue
141+
}
142+
143+
isControlledByMachinePool := false
144+
for _, ref := range obj.GetOwnerReferences() {
145+
if ref.Controller != nil && *ref.Controller && ref.Kind == "MachinePool" {
146+
isControlledByMachinePool = true
147+
break
148+
}
149+
}
150+
if !isControlledByMachinePool {
151+
continue
152+
}
153+
154+
keysToDelete.Insert(key)
155+
if objUnstructured, ok := obj.(*unstructured.Unstructured); ok {
156+
if dataSecretName, ok, err := unstructured.NestedString(objUnstructured.Object, "status", "dataSecretName"); ok && err == nil {
157+
keysToDelete.Insert(fmt.Sprintf("Secret/%s/%s", obj.GetNamespace(), dataSecretName))
158+
}
159+
}
160+
}
161+
162+
for _, key := range keysToDelete.UnsortedList() {
163+
delete(objectsWithResourceVersion, key)
164+
delete(objects, key)
165+
}
166+
135167
return objectsWithResourceVersion, objects, nil
136168
}

0 commit comments

Comments
 (0)