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

tools/bumper: Refactor using DeferCleanup #1978

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

RamLavi
Copy link
Collaborator

@RamLavi RamLavi commented Jan 12, 2025

What this PR does / why we need it:
This PR is refactoring the bumper unit tests to use DeferCleanup, following a discussion in anotherPR

Special notes for your reviewer:

Release note:

NONE

@kubevirt-bot kubevirt-bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Jan 12, 2025
@RamLavi
Copy link
Collaborator Author

RamLavi commented Jan 12, 2025

/cherry-pick release-0.97

@kubevirt-bot
Copy link
Collaborator

@RamLavi: once the present PR merges, I will cherry-pick it on top of release-0.97 in a new PR and assign it to you.

In response to this:

/cherry-pick release-0.97

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

defer func(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}(gitCnaoRepo.gitRepo.localDir)
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Aint DeferCleanup should be used on BeforeAll and such ?
It meant to auto create a corresponding AfterAll block for example,
Here it feels that defer is more suitable,
unless the docs etc says otherwise

Copy link
Contributor

Choose a reason for hiding this comment

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

defer func(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}(gitCnaoRepo.gitRepo.localDir)
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that now, after moving to DeferCleanup, it's possible, and so it is proffered, to check the error; e.g.

Suggested change
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
DeferCleanup(func(){
Expect(os.RemoveAll(gitCnaoRepo.gitRepo.localDir)).To(Succeed())
})

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would say better to keep it simple

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say that in go, you must check errors

Copy link
Collaborator Author

@RamLavi RamLavi Jan 12, 2025

Choose a reason for hiding this comment

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

@nunnatsa but it looks like ginkgo already checks for error

defer func(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}(gitCnaoRepo.gitRepo.localDir)
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

same

defer func(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}(gitCnaoRepo.gitRepo.localDir)
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

same

defer func(path string) {
Expect(os.RemoveAll(path)).To(Succeed())
}(gitCnaoRepo.gitRepo.localDir)
DeferCleanup(os.RemoveAll, gitCnaoRepo.gitRepo.localDir)
Copy link
Contributor

Choose a reason for hiding this comment

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

same

@oshoval
Copy link
Collaborator

oshoval commented Jan 12, 2025

Not related to this PR
https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_cluster-network-addons-operator/1978/pull-e2e-cluster-network-addons-operator-kubemacpool-functests/1878404002324942848

does this require some retry on either core / test ? or just an uninteresting flake ?

Thanks
/lgtm

@kubevirt-bot kubevirt-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2025
@oshoval
Copy link
Collaborator

oshoval commented Jan 12, 2025

Nit: the PR desc should be under the "What this PR does / why we need it:" line
would be nice if github would know to do it automatically

@RamLavi
Copy link
Collaborator Author

RamLavi commented Jan 12, 2025

Not related to this PR
https://prow.ci.kubevirt.io/view/gs/kubevirt-prow/pr-logs/pull/kubevirt_cluster-network-addons-operator/1978/pull-e2e-cluster-network-addons-operator-kubemacpool-functests/1878404002324942848

does this require some retry on either core / test ? or just an uninteresting flake ?

Thanks
/lgtm

I'm monitoring it as a flake (see on kmp) and also trying to investigate further.
Thanks for the lgtm
/retest

Signed-off-by: Ram Lavi <ralavi@redhat.com>
Currently the DeferCleanup is performed on every unit test.
Move it to be more centralized - where the repo is first created.

Signed-off-by: Ram Lavi <ralavi@redhat.com>
The tests creates a temporary test directory on every run.
Removing it to prevent leftover folders.

Signed-off-by: Ram Lavi <ralavi@redhat.com>
@RamLavi RamLavi force-pushed the fix_deferDuringDescribe_table branch from c57f313 to 81abf78 Compare January 14, 2025 08:12
@kubevirt-bot
Copy link
Collaborator

New changes are detected. LGTM label has been removed.

@kubevirt-bot kubevirt-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2025
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from oshoval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@RamLavi
Copy link
Collaborator Author

RamLavi commented Jan 14, 2025

@nunnatsa PTAL

@@ -28,6 +28,11 @@ var _ = Describe("Testing internal git CNAO Repo", func() {
githubApi = newFakeGithubApi(repoDir)

gitCnaoRepo = newFakeGitCnaoRepo(githubApi, repoDir, &component{}, expectedTagCommitMap)

DeferCleanup(func() {
Expect(os.RemoveAll(gitCnaoRepo.gitRepo.localDir)).To(Succeed())
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need both of them? Isn't the first dir under the 2nd?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I though about keeping them both but maybe it's an overkill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has DCO signed all their commits. release-note-none Denotes a PR that doesn't merit a release note. size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants