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

Fix panic when source PVC does not exist #381

Merged
merged 1 commit into from
Sep 30, 2020

Conversation

jsafrane
Copy link
Contributor

@jsafrane jsafrane commented Sep 29, 2020

checkAndUpdateSnapshotClass must always return a snapshot, even though it fails somewhere in ctrl.SetDefaultSnapshotClass - syncSnapshotByKey panics with nil return. I tried to fix syncSnapshotByKey to allow nil return, but the resulting code was just ugly.

While the real fix is one-liner in snapshot_controller_base.go, the PR is bigger due to test refactoring - testCall must have an opportunity to return a "fatal" error, even though a "normal" error is expected.

/kind bug

Fixed crash of snapshot-controller when source PVC of a snapshot to take does not exist.

Fixes: #380

checkAndUpdateSnapshotClass must always return a snapshot, even though it
fails somewhere in ctrl.SetDefaultSnapshotClass.

Add unit tests for that.
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 29, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 29, 2020
@jsafrane
Copy link
Contributor Author

/retest

@xing-yang xing-yang self-assigned this Sep 29, 2020
@@ -317,6 +317,7 @@ func (ctrl *csiSnapshotCommonController) syncContentByKey(key string) error {

// checkAndUpdateSnapshotClass gets the VolumeSnapshotClass from VolumeSnapshot. If it is not set,
// gets it from default VolumeSnapshotClass and sets it.
// On error, it returns the original snapshot.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you change to the following?

On error, it must return the original snapshot, not nil, because the caller syncContentByKey needs to check snapshot's timestamp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@jsafrane jsafrane force-pushed the fix-nil-default-class branch from 3bc4aea to 73f72bd Compare September 30, 2020 11:03
@xing-yang
Copy link
Collaborator

/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 Sep 30, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jsafrane, 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 /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 Sep 30, 2020
@k8s-ci-robot k8s-ci-robot merged commit 9b5b601 into kubernetes-csi:master Sep 30, 2020
xing-yang added a commit to xing-yang/external-snapshotter that referenced this pull request Oct 31, 2020
Cherry-pick kubernetes-csi#381.
Fixed crash of snapshot-controller when source PVC of a snapshot to
take does not exist.
k8s-ci-robot added a commit that referenced this pull request Dec 11, 2020
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. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

snapshot-controller panics when source PVC does not exist
3 participants