Skip to content

Commit

Permalink
chore: Match ExpectApplied expectation implementation with implementa…
Browse files Browse the repository at this point in the history
…tion from karpenter core
  • Loading branch information
jeevanpuchakay committed Jan 18, 2025
1 parent 5a204c8 commit e339c5a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion test/expectations/expectations.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Objec
GinkgoHelper()
for _, o := range objects {
current := o.DeepCopyObject().(client.Object)
statuscopy := o.DeepCopyObject().(client.Object) // Snapshot the status, since create/update may override
deletionTimestampSet := !o.GetDeletionTimestamp().IsZero()

// Create or Update
if err := c.Get(ctx, client.ObjectKeyFromObject(current), current); err != nil {
if errors.IsNotFound(err) {
Expand All @@ -100,9 +103,17 @@ func ExpectApplied(ctx context.Context, c client.Client, objects ...client.Objec
o.SetResourceVersion(current.GetResourceVersion())
Expect(c.Update(ctx, o)).To(Succeed())
}
// Update status
statuscopy.SetResourceVersion(o.GetResourceVersion())
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

// Re-get the object to grab the updated spec and status
ExpectObject(ctx, c, o)
Expect(c.Get(ctx, client.ObjectKeyFromObject(o), o)).To(Succeed())

// Set the deletion timestamp by adding a finalizer and deleting
if deletionTimestampSet {
ExpectDeletionTimestampSet(ctx, c, o)
}
}
}

Expand Down

0 comments on commit e339c5a

Please sign in to comment.