Skip to content

Commit d724d5e

Browse files
authored
Merge pull request #11903 from sbueringer/pr-extconfig-flake
🐛 Fix flaky TestExtensionReconciler_Reconcile test
2 parents 0563fcb + ce9c112 commit d724d5e

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

exp/runtime/internal/controllers/extensionconfig_controller_test.go

+22-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"sigs.k8s.io/controller-runtime/pkg/client"
3838
"sigs.k8s.io/controller-runtime/pkg/client/fake"
3939

40+
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
4041
runtimev1 "sigs.k8s.io/cluster-api/exp/runtime/api/v1alpha1"
4142
runtimecatalog "sigs.k8s.io/cluster-api/exp/runtime/catalog"
4243
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
@@ -45,6 +46,7 @@ import (
4546
runtimeregistry "sigs.k8s.io/cluster-api/internal/runtime/registry"
4647
fakev1alpha1 "sigs.k8s.io/cluster-api/internal/runtime/test/v1alpha1"
4748
"sigs.k8s.io/cluster-api/util"
49+
v1beta2conditions "sigs.k8s.io/cluster-api/util/conditions/v1beta2"
4850
)
4951

5052
func TestExtensionReconciler_Reconcile(t *testing.T) {
@@ -106,10 +108,19 @@ func TestExtensionReconciler_Reconcile(t *testing.T) {
106108
}
107109
g.Expect(warmup.Start(ctx)).To(Succeed())
108110

109-
// Reconcile the extension and assert discovery has succeeded (the first reconcile adds Paused).
111+
// Reconcile the extension and assert discovery has succeeded (the first reconcile adds the Paused condition).
110112
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(extensionConfig)})
111113
g.Expect(err).ToNot(HaveOccurred())
112114

115+
// Wait until the ExtensionConfig in the cache has the Paused condition so the next Reconcile can do discovery.
116+
g.Eventually(func(g Gomega) {
117+
conf := &runtimev1.ExtensionConfig{}
118+
g.Expect(env.Get(ctx, util.ObjectKey(extensionConfig), conf)).To(Succeed())
119+
pausedCondition := v1beta2conditions.Get(conf, clusterv1.PausedV1Beta2Condition)
120+
g.Expect(pausedCondition).ToNot(BeNil())
121+
g.Expect(pausedCondition.ObservedGeneration).To(Equal(conf.Generation))
122+
}).WithTimeout(10 * time.Second).WithPolling(100 * time.Millisecond).Should(Succeed())
123+
113124
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(extensionConfig)})
114125
g.Expect(err).ToNot(HaveOccurred())
115126

@@ -169,10 +180,19 @@ func TestExtensionReconciler_Reconcile(t *testing.T) {
169180
return nil
170181
}, 30*time.Second, 100*time.Millisecond).Should(Succeed())
171182

172-
// Reconcile the extension and assert discovery has succeeded (the first reconcile adds Paused).
183+
// Reconcile the extension and assert discovery has succeeded (the first reconcile updates observedGeneration in the Paused condition).
173184
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(extensionConfig)})
174185
g.Expect(err).ToNot(HaveOccurred())
175186

187+
// Wait until the ExtensionConfig in the cache has the up-to-date Paused condition so the next Reconcile can do discovery.
188+
g.Eventually(func(g Gomega) {
189+
conf := &runtimev1.ExtensionConfig{}
190+
g.Expect(env.Get(ctx, util.ObjectKey(extensionConfig), conf)).To(Succeed())
191+
pausedCondition := v1beta2conditions.Get(conf, clusterv1.PausedV1Beta2Condition)
192+
g.Expect(pausedCondition).ToNot(BeNil())
193+
g.Expect(pausedCondition.ObservedGeneration).To(Equal(conf.Generation))
194+
}).WithTimeout(10 * time.Second).WithPolling(100 * time.Millisecond).Should(Succeed())
195+
176196
_, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(extensionConfig)})
177197
g.Expect(err).ToNot(HaveOccurred())
178198

0 commit comments

Comments
 (0)