From e4ac3fdfea8742838e4d71d8f6eb38438bc73499 Mon Sep 17 00:00:00 2001 From: Christian Schlotter Date: Fri, 22 Dec 2023 11:54:03 +0100 Subject: [PATCH] ssa: fix flaky test TestPatch/Test patch with Machine During the test at the additional Patch calls the defaulting webhook did always set the .spec.infrastructureRef.namespace field. This caused flaky behaviour because there was a chance for the resourceVersion to getting bumped with the only change being the timestamp in managedFields. --- internal/util/ssa/patch_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/util/ssa/patch_test.go b/internal/util/ssa/patch_test.go index a3a2fa0b32ae..4d321771c3a1 100644 --- a/internal/util/ssa/patch_test.go +++ b/internal/util/ssa/patch_test.go @@ -21,6 +21,7 @@ import ( "time" . "github.com/onsi/gomega" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/utils/pointer" @@ -111,6 +112,11 @@ func TestPatch(t *testing.T) { Bootstrap: clusterv1.Bootstrap{ DataSecretName: pointer.String("data-secret"), }, + InfrastructureRef: corev1.ObjectReference{ + // The namespace needs to get set here. Otherwise the defaulting webhook always sets this field again + // which would lead to an resourceVersion bump at the 3rd step and to a flaky test. + Namespace: ns.Name, + }, }, } fieldManager := "test-manager"