Skip to content

Commit

Permalink
Fix in VolumeAttachment reconciler
Browse files Browse the repository at this point in the history
  • Loading branch information
yuga711 committed Aug 6, 2020
1 parent 298cb96 commit c7cbd33
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
27 changes: 23 additions & 4 deletions pkg/controller/csi_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,13 @@ func (h *csiHandler) ReconcileVA() error {
}
attachedStatus := va.Status.Attached

volumeHandle, err = h.translator.RepairVolumeHandle(source.Driver, volumeHandle, nodeID)
if err != nil {
klog.Warningf("Failed to repair volume handle %s for driver %s: %v", volumeHandle, source.Driver, err)
continue
// If volume driver has corresponding in-tree plugin, generate a correct volumehandle
if h.isMigratable(va) {
volumeHandle, err = h.translator.RepairVolumeHandle(source.Driver, volumeHandle, nodeID)
if err != nil {
klog.Warningf("Failed to repair volume handle %s for driver %s: %v", volumeHandle, source.Driver, err)
continue
}
}

// Check whether the volume is published to this node
Expand Down Expand Up @@ -354,6 +357,22 @@ func (h *csiHandler) hasVAFinalizer(va *storage.VolumeAttachment) bool {
return false
}

// Checks if the PV (or) the inline-volume corresponding to the VA could have migrated from
// in-tree to CSI.
func (h *csiHandler) isMigratable(va *storage.VolumeAttachment) bool {
if va.Spec.Source.PersistentVolumeName != nil {
pv, err := h.pvLister.Get(*va.Spec.Source.PersistentVolumeName)
if err != nil {
return false
}
return h.translator.IsPVMigratable(pv)
} else if va.Spec.Source.InlineVolumeSpec != nil {
return va.Spec.Source.InlineVolumeSpec.CSI != nil
} else {
return false
}
}

func getCSISource(pvSpec *v1.PersistentVolumeSpec) (*v1.CSIPersistentVolumeSource, error) {
if pvSpec == nil {
return nil, errors.New("could not get CSI source, pv spec was nil")
Expand Down
34 changes: 34 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ github.com/beorn7/perks/quantile
# github.com/blang/semver v3.5.0+incompatible
github.com/blang/semver
# github.com/container-storage-interface/spec v1.2.0
## explicit
github.com/container-storage-interface/spec/lib/go/csi
# github.com/davecgh/go-spew v1.1.1
## explicit
github.com/davecgh/go-spew/spew
# github.com/evanphx/json-patch v4.5.0+incompatible
## explicit
github.com/evanphx/json-patch
# github.com/go-logr/logr v0.2.0
github.com/go-logr/logr
Expand All @@ -16,8 +19,10 @@ github.com/gogo/protobuf/sortkeys
# github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7
github.com/golang/groupcache/lru
# github.com/golang/mock v1.4.3
## explicit
github.com/golang/mock/gomock
# github.com/golang/protobuf v1.4.2
## explicit
github.com/golang/protobuf/descriptor
github.com/golang/protobuf/proto
github.com/golang/protobuf/protoc-gen-go/descriptor
Expand All @@ -42,16 +47,19 @@ github.com/googleapis/gnostic/openapiv2
github.com/hashicorp/golang-lru
github.com/hashicorp/golang-lru/simplelru
# github.com/imdario/mergo v0.3.9
## explicit
github.com/imdario/mergo
# github.com/json-iterator/go v1.1.10
github.com/json-iterator/go
# github.com/kubernetes-csi/csi-lib-utils v0.7.0
## explicit
github.com/kubernetes-csi/csi-lib-utils/connection
github.com/kubernetes-csi/csi-lib-utils/leaderelection
github.com/kubernetes-csi/csi-lib-utils/metrics
github.com/kubernetes-csi/csi-lib-utils/protosanitizer
github.com/kubernetes-csi/csi-lib-utils/rpc
# github.com/kubernetes-csi/csi-test/v3 v3.1.0
## explicit
github.com/kubernetes-csi/csi-test/v3/driver
github.com/kubernetes-csi/csi-test/v3/utils
# github.com/matttproud/golang_protobuf_extensions v1.0.1
Expand Down Expand Up @@ -113,6 +121,7 @@ google.golang.org/appengine/urlfetch
# google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/genproto/googleapis/rpc/status
# google.golang.org/grpc v1.28.0
## explicit
google.golang.org/grpc
google.golang.org/grpc/attributes
google.golang.org/grpc/backoff
Expand Down Expand Up @@ -192,6 +201,7 @@ gopkg.in/inf.v0
# gopkg.in/yaml.v2 v2.2.8
gopkg.in/yaml.v2
# k8s.io/api v0.19.0-rc.2
## explicit
k8s.io/api/admissionregistration/v1
k8s.io/api/admissionregistration/v1beta1
k8s.io/api/apps/v1
Expand Down Expand Up @@ -234,6 +244,7 @@ k8s.io/api/storage/v1
k8s.io/api/storage/v1alpha1
k8s.io/api/storage/v1beta1
# k8s.io/apimachinery v0.19.0-rc.2
## explicit
k8s.io/apimachinery/pkg/api/equality
k8s.io/apimachinery/pkg/api/errors
k8s.io/apimachinery/pkg/api/meta
Expand Down Expand Up @@ -278,6 +289,7 @@ k8s.io/apimachinery/pkg/watch
k8s.io/apimachinery/third_party/forked/golang/json
k8s.io/apimachinery/third_party/forked/golang/reflect
# k8s.io/client-go v0.19.0-rc.2
## explicit
k8s.io/client-go/discovery
k8s.io/client-go/discovery/fake
k8s.io/client-go/informers
Expand Down Expand Up @@ -494,11 +506,13 @@ k8s.io/cloud-provider/volume
k8s.io/component-base/metrics
k8s.io/component-base/version
# k8s.io/csi-translation-lib v0.19.0-rc.2
## explicit
k8s.io/csi-translation-lib
k8s.io/csi-translation-lib/plugins
# k8s.io/klog v1.0.0
k8s.io/klog
# k8s.io/klog/v2 v2.2.0
## explicit
k8s.io/klog/v2
# k8s.io/kube-openapi v0.0.0-20200427153329-656914f816f9
k8s.io/kube-openapi/pkg/util/proto
Expand All @@ -510,3 +524,23 @@ k8s.io/utils/trace
sigs.k8s.io/structured-merge-diff/v3/value
# sigs.k8s.io/yaml v1.2.0
sigs.k8s.io/yaml
# k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.17.0
# k8s.io/apiserver => k8s.io/apiserver v0.17.0
# k8s.io/cli-runtime => k8s.io/cli-runtime v0.17.0
# k8s.io/cloud-provider => k8s.io/cloud-provider v0.17.0
# k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.17.0
# k8s.io/code-generator => k8s.io/code-generator v0.17.1-beta.0
# k8s.io/component-base => k8s.io/component-base v0.17.0
# k8s.io/cri-api => k8s.io/cri-api v0.17.1-beta.0
# k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.17.0
# k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.17.0
# k8s.io/kube-proxy => k8s.io/kube-proxy v0.17.0
# k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.17.0
# k8s.io/kubectl => k8s.io/kubectl v0.17.0
# k8s.io/kubelet => k8s.io/kubelet v0.17.0
# k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.17.0
# k8s.io/metrics => k8s.io/metrics v0.17.0
# k8s.io/node-api => k8s.io/node-api v0.17.0
# k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.17.0
# k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.17.0
# k8s.io/sample-controller => k8s.io/sample-controller v0.17.0

0 comments on commit c7cbd33

Please sign in to comment.