Skip to content

Commit d100e1e

Browse files
chore: Match ExpectApplied expectation implementation with implementation from karpenter core
1 parent 5a204c8 commit d100e1e

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

test/expectations/expectations.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Objec
8989
GinkgoHelper()
9090
for _, o := range objects {
9191
current := o.DeepCopyObject().(client.Object)
92+
statuscopy := o.DeepCopyObject().(client.Object) // Snapshot the status, since create/update may override
93+
deletionTimestampSet := !o.GetDeletionTimestamp().IsZero()
94+
9295
// Create or Update
9396
if err := c.Get(ctx, client.ObjectKeyFromObject(current), current); err != nil {
9497
if errors.IsNotFound(err) {
@@ -100,9 +103,17 @@ func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Objec
100103
o.SetResourceVersion(current.GetResourceVersion())
101104
Expect(c.Update(ctx, o)).To(Succeed())
102105
}
106+
// Update status
107+
statuscopy.SetResourceVersion(o.GetResourceVersion())
108+
Expect(c.Status().Update(ctx, statuscopy)).To(Or(Succeed(), MatchError("the server could not find the requested resource"))) // Some objects do not have a status
103109

104110
// Re-get the object to grab the updated spec and status
105111
ExpectObject(ctx, c, o)
112+
113+
// Set the deletion timestamp by adding a finalizer and deleting
114+
if deletionTimestampSet {
115+
ExpectDeletionTimestampSet(ctx, c, o)
116+
}
106117
}
107118
}
108119

0 commit comments

Comments
 (0)