Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#154 from ddebroy/inline2
Browse files Browse the repository at this point in the history
Add support for attachment of inline volumes migrated to CSI
  • Loading branch information
k8s-ci-robot authored Jun 12, 2019
2 parents 08983ee + 16260ee commit b73cf2a
Show file tree
Hide file tree
Showing 73 changed files with 5,534 additions and 2,825 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 2 additions & 19 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,11 @@
name = "github.com/json-iterator/go"
version = "1.1.4"

[[constraint]]
[[override]]
name = "k8s.io/api"
version = "kubernetes-1.14.0"

[[constraint]]
name = "k8s.io/csi-translation-lib"
version = "kubernetes-1.14.0"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.14.0"

[[constraint]]
name = "k8s.io/client-go"
version = "kubernetes-1.14.0"

[[constraint]]
name = "github.com/kubernetes-csi/csi-lib-utils"
version = ">=0.6.1"
branch = "release-1.15"

[prune]
non-go = true
go-tests = true
unused-packages = true

87 changes: 56 additions & 31 deletions pkg/controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package controller

import (
"context"
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -256,26 +257,41 @@ func (h *csiHandler) csiAttach(va *storage.VolumeAttachment) (*storage.VolumeAtt
// Check as much as possible before adding VA finalizer - it would block
// deletion of VA on error.

if va.Spec.Source.PersistentVolumeName == nil {
return va, nil, fmt.Errorf("VolumeAttachment.spec.persistentVolumeName is empty")
}
var csiSource *v1.CSIPersistentVolumeSource
var pvSpec *v1.PersistentVolumeSpec
if va.Spec.Source.PersistentVolumeName != nil {
if va.Spec.Source.InlineVolumeSpec != nil {
return va, nil, errors.New("both InlineCSIVolumeSource and PersistentVolumeName specified in VA source")
}
pv, err := h.pvLister.Get(*va.Spec.Source.PersistentVolumeName)
if err != nil {
return va, nil, err
}
// Refuse to attach volumes that are marked for deletion.
if pv.DeletionTimestamp != nil {
return va, nil, fmt.Errorf("PersistentVolume %q is marked for deletion", pv.Name)
}
pv, err = h.addPVFinalizer(pv)
if err != nil {
return va, nil, fmt.Errorf("could not add PersistentVolume finalizer: %s", err)
}

pv, err := h.pvLister.Get(*va.Spec.Source.PersistentVolumeName)
if err != nil {
return va, nil, err
}
// Refuse to attach volumes that are marked for deletion.
if pv.DeletionTimestamp != nil {
return va, nil, fmt.Errorf("PersistentVolume %q is marked for deletion", pv.Name)
}
pv, err = h.addPVFinalizer(pv)
if err != nil {
return va, nil, fmt.Errorf("could not add PersistentVolume finalizer: %s", err)
}
csiSource, err = getCSISource(pv)
if err != nil {
return va, nil, err
}

csiSource, err := getCSISource(pv)
if err != nil {
return va, nil, err
pvSpec = &pv.Spec
} else if va.Spec.Source.InlineVolumeSpec != nil {
if va.Spec.Source.InlineVolumeSpec.CSI != nil {
csiSource = va.Spec.Source.InlineVolumeSpec.CSI
} else {
return va, nil, errors.New("inline volume spec contains nil CSI source")
}

pvSpec = va.Spec.Source.InlineVolumeSpec
} else {
return va, nil, errors.New("neither InlineCSIVolumeSource nor PersistentVolumeName specified in VA source")
}

attributes, err := GetVolumeAttributes(csiSource)
Expand All @@ -293,7 +309,7 @@ func (h *csiHandler) csiAttach(va *storage.VolumeAttachment) (*storage.VolumeAtt
readOnly = false
}

volumeCapabilities, err := GetVolumeCapabilities(pv, csiSource)
volumeCapabilities, err := GetVolumeCapabilities(pvSpec, csiSource)
if err != nil {
return va, nil, err
}
Expand Down Expand Up @@ -330,18 +346,27 @@ func (h *csiHandler) csiAttach(va *storage.VolumeAttachment) (*storage.VolumeAtt
}

func (h *csiHandler) csiDetach(va *storage.VolumeAttachment) (*storage.VolumeAttachment, error) {
if va.Spec.Source.PersistentVolumeName == nil {
return va, fmt.Errorf("VolumeAttachment.spec.persistentVolumeName is empty")
}

pv, err := h.pvLister.Get(*va.Spec.Source.PersistentVolumeName)
if err != nil {
return va, err
}

csiSource, err := getCSISource(pv)
if err != nil {
return va, err
var csiSource *v1.CSIPersistentVolumeSource
if va.Spec.Source.PersistentVolumeName != nil {
if va.Spec.Source.InlineVolumeSpec != nil {
return va, errors.New("both InlineCSIVolumeSource and PersistentVolumeName specified in VA source")
}
pv, err := h.pvLister.Get(*va.Spec.Source.PersistentVolumeName)
if err != nil {
return va, err
}
csiSource, err = getCSISource(pv)
if err != nil {
return va, err
}
} else if va.Spec.Source.InlineVolumeSpec != nil {
if va.Spec.Source.InlineVolumeSpec.CSI != nil {
csiSource = va.Spec.Source.InlineVolumeSpec.CSI
} else {
return va, errors.New("inline volume spec contains nil CSI source")
}
} else {
return va, errors.New("neither InlineCSIVolumeSource nor PersistentVolumeName specified in VA source")
}

volumeHandle, _, err := GetVolumeHandle(csiSource)
Expand Down
Loading

0 comments on commit b73cf2a

Please sign in to comment.