Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Match ExpectApplied expectation implementation with implementation from karpenter core #121

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions 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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I'm convinced by the deletionTimestamp logic that's present here -- this might have been in the karpenter implementation, but I'm not sure that this makes sense and is something that we want to pull in here


// 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)

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

Expand Down