Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 8 additions & 8 deletions internal/controllers/machine/machine_controller_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until InfraMachine has the ownerReference.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(infraMachine), infraMachine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(infraMachine), infraMachine); err != nil {
return false
}
g.Expect(infraMachine.GetOwnerReferences()).To(HaveLen(1))
Expand Down Expand Up @@ -2127,7 +2127,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhasePending))
Expand Down Expand Up @@ -2182,7 +2182,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseProvisioning))
Expand Down Expand Up @@ -2270,7 +2270,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.Addresses).To(HaveLen(2))
Expand Down Expand Up @@ -2349,7 +2349,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseRunning))
Expand Down Expand Up @@ -2427,7 +2427,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseRunning))
Expand Down Expand Up @@ -2489,7 +2489,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseProvisioned))
Expand Down Expand Up @@ -2582,7 +2582,7 @@ func TestReconcileMachinePhases(t *testing.T) {

// Wait until Machine was reconciled.
g.Eventually(func(g Gomega) bool {
if err := env.Get(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
if err := env.DirectApiServerGet(ctx, client.ObjectKeyFromObject(machine), machine); err != nil {
return false
}
g.Expect(machine.Status.GetTypedPhase()).To(Equal(clusterv1.MachinePhaseDeleting))
Expand Down
7 changes: 7 additions & 0 deletions internal/test/envtest/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ func (e *Environment) PatchAndWait(ctx context.Context, obj client.Object, opts
return nil
}

// DirectApiServerGet gets an object directly from apiserver bypassing informer caches..
//
// NOTE: Bypassing cache helps in preventing test flakes due to the cache sync delays but should only be used in validation steps of testing.
func (e *Environment) DirectApiServerGet(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
return e.Manager.GetAPIReader().Get(ctx, key, obj, opts...)
}

// CreateNamespace creates a new namespace with a generated name.
func (e *Environment) CreateNamespace(ctx context.Context, generateName string) (*corev1.Namespace, error) {
ns := &corev1.Namespace{
Expand Down
Loading