-
Notifications
You must be signed in to change notification settings - Fork 377
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
Refactor common controller tests to use withXYZ functions and add tests #254
Refactor common controller tests to use withXYZ functions and add tests #254
Conversation
Signed-off-by: Grant Griffiths <[email protected]>
Also just added more tests as well. Coverage for snapshot_controller.go is now 74.1%, up from 68.2%. |
a04d964
to
20eb761
Compare
@@ -863,7 +876,7 @@ func newContentWithUnmatchDriverArray(contentName, boundToSnapshotUID, boundToSn | |||
func newSnapshot( | |||
snapshotName, snapshotUID, pvcName, targetContentName, snapshotClassName, boundContentName string, | |||
readyToUse *bool, creationTime *metav1.Time, restoreSize *resource.Quantity, | |||
err *crdv1.VolumeSnapshotError, nilStatus bool, withFinalizer bool, deletionTimestamp *metav1.Time) *crdv1.VolumeSnapshot { | |||
err *crdv1.VolumeSnapshotError, nilStatus bool, withAllFinalizers bool, deletionTimestamp *metav1.Time) *crdv1.VolumeSnapshot { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the test framework in pv/pvc controller will allow you to create a basic newSnapshot() without passing in the withAllFinalizers flag, and then we can have another function withAllFinalizers() which takes a created snapshot object as input and apply finalizers on top of it. So that means we shouldn't need "withAllFinalizers bool" as an input parameter for newSnapshot().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left "withFinalizers" as "withAllFinalizers" for the purpose of reducing the refactor required. Some tests require all finalizers while others require no finalizers, so pretty much every test would have the "withSnapFinalizers" wrapper.
I mainly introduced "func withSnapshotFinalizers()" to fine-tune which finalizers are added. i.e. for cases where only one finalizer is wanted.
20eb761
to
2409028
Compare
if withFinalizer { | ||
return withSnapshotFinalizer(&snapshot) | ||
if withAllFinalizers { | ||
return withSnapshotFinalizers([]*crdv1.VolumeSnapshot{&snapshot}, utils.VolumeSnapshotContentFinalizer, utils.VolumeSnapshotAsSourceFinalizer, utils.VolumeSnapshotBoundFinalizer)[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withSnapshotFinalizers() only adds finalizers on VolumeSnapshot API object, right? Why is utils.VolumeSnapshotContentFinalizer needed here? utils.VolumeSnapshotContentFinalizer is added on VolumeSnapshotContent only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, removed the contentFinalizer.
@@ -164,16 +164,17 @@ type reactorError struct { | |||
error error | |||
} | |||
|
|||
func withSnapshotFinalizer(snapshot *crdv1.VolumeSnapshot) *crdv1.VolumeSnapshot { | |||
snapshot.ObjectMeta.Finalizers = append(snapshot.ObjectMeta.Finalizers, utils.VolumeSnapshotContentFinalizer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see that utils.VolumeSnapshotContentFinalizer is added to VolumeSnapshot API object here. This is wrong. We only need utils.VolumeSnapshotContentFinalizer for VolumeSnapshotContent, not for VolumeSnapshot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, removed the contentFinalizer.
Signed-off-by: Grant Griffiths <[email protected]>
2409028
to
05efba2
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ggriffiths, xing-yang 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 |
Add GitHub Actions workflows
f40f0cc Merge pull request kubernetes-csi#256 from solumath/master cfa9210 Instruction update 379a1bb Merge pull request kubernetes-csi#255 from humblec/sidecar-md a5667bb fix typo in sidecar release process 4967685 Merge pull request kubernetes-csi#254 from bells17/add-github-actions d9bd160 Update skip list in codespell GitHub Action f5aebfc Add GitHub Actions workflows git-subtree-dir: release-tools git-subtree-split: f40f0cc
988496a1f Merge pull request kubernetes-csi#257 from jakobmoellerdev/csi-prow-sidecar-e2e-path 028f8c698 chore: bump to Go 1.22.5 69bd71e8a chore: add CSI_PROW_SIDECAR_E2E_PATH f40f0cc Merge pull request kubernetes-csi#256 from solumath/master cfa9210 Instruction update 379a1bb Merge pull request kubernetes-csi#255 from humblec/sidecar-md a5667bb fix typo in sidecar release process 4967685 Merge pull request kubernetes-csi#254 from bells17/add-github-actions d9bd160 Update skip list in codespell GitHub Action f5aebfc Add GitHub Actions workflows git-subtree-dir: release-tools git-subtree-split: 988496a1fc3849ed793e03012fdd56813d13d46c
Signed-off-by: Grant Griffiths [email protected]
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
refactor finalizer-specific test to use withSnapshotFinalizers function
Which issue(s) this PR fixes:
Fixes #253
Part of #196
Special notes for your reviewer:
n/a
Does this PR introduce a user-facing change?: