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

dry-run: Add resttests #67136

Merged
merged 1 commit into from
Aug 15, 2018
Merged

Conversation

apelisse
Copy link
Member

@apelisse apelisse commented Aug 8, 2018

Add Resttests

What this PR does / why we need it:

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Partially #67128

Special notes for your reviewer:

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 8, 2018
@k8s-ci-robot k8s-ci-robot requested review from euank and ncdc August 8, 2018 13:47
@apelisse apelisse mentioned this pull request Aug 8, 2018
3 tasks
@@ -1005,7 +1005,7 @@ func (e *Store) Delete(ctx context.Context, name string, options *metav1.DeleteO
}

// If dry-run, then just return the object as just saved.
if dryrun.IsDryRun(options.DryRun) {
if dryrun.IsDryRun(options.DryRun) && out != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't expect this. Why shouldn't dry-run be honored in all cases? It seems like even an error would be better than actually doing a delete when a dry run is requested.

Copy link
Member

Choose a reason for hiding this comment

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

I am also confused about why we need this if statement when we also pass something about dry run into the delete statement below.

Copy link
Member Author

@apelisse apelisse Aug 8, 2018

Choose a reason for hiding this comment

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

The code before that condition/early-return is doing a guaranteedupdate to add the finalizer and deletion timestamp. That guaranteed update can be dry-run, which means that the object is never persisted with deletion timestamp and finalizers.
The code after does the delete when an immediate delete is required. Actually it does an atomic get-and-delete and returns the object as it is before being deleted (including finalizer and deletion timestamp). The dry-run delete just does a get, but in this case, it doesn't get the proper object since the guaranteed update never really happened.

The goal of this condition is just to avoid the second "get", but to return the object with the finalizer and deletion-timestamp.

Copy link
Member

Choose a reason for hiding this comment

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

Great, can you state this in a comment in the code? It's not obvious.

@@ -749,6 +823,38 @@ func (t *Tester) testUpdateIgnoreClusterName(obj runtime.Object, createFn Create
// =============================================================================
// Deletion tests.

func (t *Tester) testDeleteDryRunNoGraceful(obj runtime.Object, createFn CreateFunc, getFn GetFunc, isNotFoundFn IsErrorFunc) {
Copy link
Member

Choose a reason for hiding this comment

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

Why does dry run deletion need its own function?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because the non-dry run version verifies that the object has been removed (this one should probably verify that the object still exists)

Copy link
Member

Choose a reason for hiding this comment

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

Would we end up with easier to maintain code if they checked opts before doing that, rather than duplicating the functions?

Copy link
Member

Choose a reason for hiding this comment

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

(I expect yes?)

Copy link
Member Author

Choose a reason for hiding this comment

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

I've changed it because I don't have a strong opinion. Sometimes it's easier to maintain mostly-copy-pasted code than factorizing diverging code with lots of if-statements. In this case it's just one if-statement so I don't really care :-)

@neolit123
Copy link
Member

/sig api-machinery

@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Aug 8, 2018
@ncdc
Copy link
Member

ncdc commented Aug 8, 2018

/uncc

createdMeta.SetCreationTimestamp(createdFakeMeta.GetCreationTimestamp())
createdFakeMeta.SetResourceVersion("")
createdMeta.SetResourceVersion("")
// TODO(apelisse): This is wrong, we should have empty UID.
Copy link
Member

Choose a reason for hiding this comment

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

inaccurate comment

ctx := t.TestContext()

foo := obj.DeepCopyObject()
t.setObjectMeta(foo, t.namer(1))
if err := createFn(ctx, foo); err != nil {
t.Errorf("unexpected error: %v", err)
}
defer t.delete(ctx, foo)
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused about this-- if not dryRun, it should have already been deleted at the end, and if dryRun it should not be removed at all? What am I missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment.

@apelisse
Copy link
Member Author

/retest

@lavalamp
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 13, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, lavalamp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 13, 2018
@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel comment for consistent failures.

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 66177, 66185, 67136, 67157, 65065). If you want to cherry-pick this change to another branch, please follow the instructions here.

@k8s-github-robot k8s-github-robot merged commit b7579cc into kubernetes:master Aug 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants