kubernetes-csi / external-snapshotter

Sidecar container that watches Kubernetes Snapshot CRD objects and triggers CreateSnapshot/DeleteSnapshot against a CSI endpoint.
Apache License 2.0
484 stars 369 forks source link

Add nil check for groupSnapshotContent in deleteCSIGroupSnapshotOperaion and unit tests #1152

Open manishym opened 1 month ago

manishym commented 1 month ago

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change /kind bug /kind cleanup /kind design /kind documentation /kind failing-test /kind feature /kind flake

What this PR does / why we need it: Before fix:

[Running: /usr/local/go/bin/go test -timeout 30s -run ^TestDeleteCSIGroupSnapshotOperation$ [github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller)]
--- FAIL: TestDeleteCSIGroupSnapshotOperation (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
        panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x105c44fd4]
goroutine 7 [running]:
testing.tRunner.func1.2({0x1060d4860, 0x107102300})
        /Users/manish/.gvm/pkgsets/go1.22.5/global/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1631 +0x1c4
testing.tRunner.func1()
        /Users/manish/.gvm/pkgsets/go1.22.5/global/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1634 +0x33c
panic({0x1060d4860?, 0x107102300?})
        /Users/manish/.gvm/pkgsets/go1.22.5/global/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/runtime/panic.go:770 +0x124
[github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller.(*csiSnapshotSideCarController).deleteCSIGroupSnapshotOperation(0x14000094e48](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller.(*csiSnapshotSideCarController).deleteCSIGroupSnapshotOperation(0x14000094e48), 0x140000d65a0)
        /Users/manish/work/openshift/external-snapshotter/pkg/sidecar-controller/groupsnapshot_helper.go:263 +0x404
[github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller.TestDeleteCSIGroupSnapshotOperation(0x140002df520)](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller.TestDeleteCSIGroupSnapshotOperation(0x140002df520))
        /Users/manish/work/openshift/external-snapshotter/pkg/sidecar-controller/groupsnapshot_helper_test.go:50 +0x1d4
testing.tRunner(0x140002df520, 0x10634dda8)
        /Users/manish/.gvm/pkgsets/go1.22.5/global/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1689 +0xec
created by testing.(*T).Run in goroutine 1
        /Users/manish/.gvm/pkgsets/go1.22.5/global/pkg/mod/golang.org/toolchain@v0.0.1-go1.22.5.darwin-arm64/src/testing/testing.go:1742 +0x318
FAIL    [github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller)        1.298s
FAIL
[Command exited with 1]

After fix:

[Running: /usr/local/go/bin/go test -timeout 30s -run ^TestDeleteCSIGroupSnapshotOperation$ [github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller)]
ok      [github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller](http://github.com/kubernetes-csi/external-snapshotter/v8/pkg/sidecar-controller) 

Which issue(s) this PR fixes:

Fixes #1123

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE
k8s-ci-robot commented 1 month ago

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: manishym Once this PR has been reviewed and has the lgtm label, please assign jsafrane for approval. 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: - **[OWNERS](https://github.com/kubernetes-csi/external-snapshotter/blob/master/OWNERS)** 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 commented 1 month ago

Hi @manishym. Thanks for your PR.

I'm waiting for a kubernetes-csi member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
xing-yang commented 1 month ago

/ok-to-test

manishym commented 3 weeks ago

/retest

xing-yang commented 2 weeks ago

Can you please rebase?