mirror of https://github.com/k3s-io/k3s
Merge pull request #71095 from msau42/csi-devicepath
Remove devicePath dependency for CSI volumespull/58/head
commit
4821291398
|
@ -119,16 +119,19 @@ func (c *csiAttacher) Attach(spec *volume.Spec, nodeName types.NodeName) (string
|
|||
|
||||
klog.V(4).Info(log("attacher.Attach finished OK with VolumeAttachment object [%s]", attachID))
|
||||
|
||||
// TODO(71164): In 1.15, return empty devicePath
|
||||
return attachID, nil
|
||||
}
|
||||
|
||||
func (c *csiAttacher) WaitForAttach(spec *volume.Spec, attachID string, pod *v1.Pod, timeout time.Duration) (string, error) {
|
||||
func (c *csiAttacher) WaitForAttach(spec *volume.Spec, _ string, pod *v1.Pod, timeout time.Duration) (string, error) {
|
||||
source, err := getCSISourceFromSpec(spec)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.WaitForAttach failed to extract CSI volume source: %v", err))
|
||||
return "", err
|
||||
}
|
||||
|
||||
attachID := getAttachmentName(source.VolumeHandle, source.Driver, string(c.plugin.host.GetNodeName()))
|
||||
|
||||
skip, err := c.plugin.skipAttach(source.Driver)
|
||||
if err != nil {
|
||||
klog.Error(log("attacher.Attach failed to find if driver is attachable: %v", err))
|
||||
|
|
|
@ -332,6 +332,73 @@ func TestAttacherWaitForVolumeAttachmentWithCSIDriver(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestAttacherWaitForAttach(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
driver string
|
||||
makeAttachment func() *storage.VolumeAttachment
|
||||
expectedAttachID string
|
||||
expectError bool
|
||||
}{
|
||||
{
|
||||
name: "successful attach",
|
||||
driver: "attachable",
|
||||
makeAttachment: func() *storage.VolumeAttachment {
|
||||
|
||||
testAttachID := getAttachmentName("test-vol", "attachable", "node")
|
||||
successfulAttachment := makeTestAttachment(testAttachID, "node", "test-pv")
|
||||
successfulAttachment.Status.Attached = true
|
||||
return successfulAttachment
|
||||
},
|
||||
expectedAttachID: getAttachmentName("test-vol", "attachable", "node"),
|
||||
expectError: false,
|
||||
},
|
||||
{
|
||||
name: "failed attach",
|
||||
driver: "attachable",
|
||||
expectError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
plug, _, tmpDir, _ := newTestWatchPlugin(t, nil)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
attacher, err := plug.NewAttacher()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create new attacher: %v", err)
|
||||
}
|
||||
csiAttacher := attacher.(*csiAttacher)
|
||||
spec := volume.NewSpecFromPersistentVolume(makeTestPV("test-pv", 10, test.driver, "test-vol"), false)
|
||||
|
||||
if test.makeAttachment != nil {
|
||||
attachment := test.makeAttachment()
|
||||
_, err = csiAttacher.k8s.StorageV1beta1().VolumeAttachments().Create(attachment)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create VolumeAttachment: %v", err)
|
||||
}
|
||||
gotAttachment, err := csiAttacher.k8s.StorageV1beta1().VolumeAttachments().Get(attachment.Name, meta.GetOptions{})
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get created VolumeAttachment: %v", err)
|
||||
}
|
||||
t.Logf("created test VolumeAttachment %+v", gotAttachment)
|
||||
}
|
||||
|
||||
attachID, err := csiAttacher.WaitForAttach(spec, "", nil, time.Second)
|
||||
if err != nil && !test.expectError {
|
||||
t.Errorf("Unexpected error: %s", err)
|
||||
}
|
||||
if err == nil && test.expectError {
|
||||
t.Errorf("Expected error, got none")
|
||||
}
|
||||
if attachID != test.expectedAttachID {
|
||||
t.Errorf("Expected attachID %q, got %q", test.expectedAttachID, attachID)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAttacherWaitForVolumeAttachment(t *testing.T) {
|
||||
nodeName := "test-node"
|
||||
testCases := []struct {
|
||||
|
|
Loading…
Reference in New Issue