Skip to content

csi-sanity panics instead of reporting proper failure if driver fails CreateVolume from Snapshot #569

Open
@ebblake

Description

@ebblake

I'm incrementally developing a CSI driver. So far, I have the snapshot creation/deletion side of CREATE_DELETE_SNAPSHOT working, but not yet the CreateVolume from an existing snapshot source, so my code intentionally fails with gRPC error UNIMPLEMENTED if it detects an attempt to create a volume from a snapshot source. I was hoping to see how close my partial implementation was to csi-sanity, and was surprised to see the test panic rather than report failure:

Controller Service [Controller Server] CreateVolume should create volume from an
 existing source snapshot
/csi-sanity/csi-test-5.3.0/pkg/sanity/controller.go:553
  STEP: reusing connection to CSI driver at /var/lib/kubelet/plugins/kubesan-nod
e/socket @ 01/20/25 21:49:35.745
  STEP: reusing connection to CSI driver controller at /var/lib/kubelet/plugins/
kubesan-controller/socket @ 01/20/25 21:49:35.745
  STEP: creating mount and staging directories @ 01/20/25 21:49:35.745
  STEP: creating a volume @ 01/20/25 21:49:35.746
  STEP: creating a snapshot from the volume @ 01/20/25 21:49:38.452
  STEP: creating a volume from source snapshot @ 01/20/25 21:49:41.121
  [PANICKED] in [It] - /usr/local/go/src/runtime/panic.go:261 @ 01/20/25 21:49:41.124
I0120 21:49:41.124952   13835 resources.go:301] deleting snapshot ID kubesan-snapshot-f8fa283110a8f6e8edcc00e66bc271be
<E2><80><A2> [PANICKED] [17.018 seconds]
Controller Service [Controller Server] CreateVolume [It] should create volume from an existing source snapshot
/csi-sanity/csi-test-5.3.0/pkg/sanity/controller.go:553

  [PANICKED] Test Panicked
  In [It] at: /usr/local/go/src/runtime/panic.go:261 @ 01/20/25 21:49:41.124

  runtime error: invalid memory address or nil pointer dereference

  Full Stack Trace
    github.com/kubernetes-csi/csi-test/v5/pkg/sanity.init.func1.6.9()
        /csi-sanity/csi-test-5.3.0/pkg/sanity/controller.go:584 +0x3b4

And reading the actual test in question, the cause of the panic is rather obvious:

			vol, err := r.CreateVolume(context.Background(), vol2Req)
			Expect(vol.GetVolume().ContentSource).NotTo(BeNil())
			Expect(err).NotTo(HaveOccurred())

https://github.com/kubernetes-csi/csi-test/blob/master/pkg/sanity/controller.go#L583

Tests should always inspect Expect(err) lines PRIOR to Expect(vol.GetVolume().XXX) calls, since vol.GetVolume() will be nil if the driver returns an (unexpected) error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lifecycle/rottenDenotes an issue or PR that has aged beyond stale and will be auto-closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions