Skip to content

Commit

Permalink
fix(csi-node): return error for orphaned volume during unpublish event
Browse files Browse the repository at this point in the history
There will be unpublish events request in each ~60s periods for
stale/orphaned volume which was causing node driver crash
due to NO csiVolume resource exists for the requested volumeID.

Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and kmova committed Nov 8, 2019
1 parent 11789d7 commit 84a4bd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions pkg/service/v1alpha1/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
apis "github.com/openebs/cstor-csi/pkg/apis/openebs.io/core/v1alpha1"
iscsi "github.com/openebs/cstor-csi/pkg/iscsi/v1alpha1"
"github.com/openebs/cstor-csi/pkg/utils/v1alpha1"
utils "github.com/openebs/cstor-csi/pkg/utils/v1alpha1"
csivol "github.com/openebs/cstor-csi/pkg/volume/v1alpha1"
"golang.org/x/net/context"
"google.golang.org/grpc/codes"
Expand Down Expand Up @@ -270,7 +270,7 @@ func (ns *node) NodeUnpublishVolume(
return nil, status.Error(codes.Internal, err.Error())
}
if unmountRequired {
if vol, err = utils.GetCSIVolume(volumeID); (err != nil) || (vol == nil) {
if vol, err = utils.GetCSIVolume(volumeID); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/utils/v1alpha1/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
corev1 "k8s.io/api/core/v1"
k8serror "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
Expand All @@ -52,7 +51,7 @@ func FetchPVDetails(name string) (*corev1.PersistentVolume, error) {
// getVolStatus fetches the current VolumeStatus which specifies if the volume
// is ready to serve IOs
func getVolStatus(volumeID string) (string, error) {
listOptions := v1.ListOptions{
listOptions := metav1.ListOptions{
LabelSelector: "openebs.io/persistent-volume=" + volumeID,
}

Expand All @@ -75,7 +74,7 @@ func getVolStatus(volumeID string) (string, error) {

// GetVolListForNode fetches the current Published Volume list
func GetVolListForNode() (*apis.CSIVolumeList, error) {
listOptions := v1.ListOptions{
listOptions := metav1.ListOptions{
LabelSelector: NODEID + "=" + NodeIDENV,
}

Expand All @@ -86,10 +85,9 @@ func GetVolListForNode() (*apis.CSIVolumeList, error) {

// GetVolList fetches the current Published Volume list
func GetVolList(volume string) (*apis.CSIVolumeList, error) {
listOptions := v1.ListOptions{
listOptions := metav1.ListOptions{
LabelSelector: VOLNAME + "=" + volume,
}

return csivolume.NewKubeclient().
WithNamespace(OpenEBSNamespace).List(listOptions)

Expand All @@ -101,8 +99,10 @@ func GetCSIVolume(volumeID string) (*apis.CSIVolume, error) {
if err != nil {
return nil, err
}

if len(volList.Items) == 0 {
return nil, nil
return nil, k8serror.NewNotFound(apis.Resource("csivolumes"), volumeID)

}

if len(volList.Items) != 1 {
Expand All @@ -114,7 +114,7 @@ func GetCSIVolume(volumeID string) (*apis.CSIVolume, error) {
// GetVolumeIP fetches the cstor target IP Address
func GetVolumeIP(volumeID string) (string, error) {
cstorvolume, err := csv.NewKubeclient().
WithNamespace(OpenEBSNamespace).Get(volumeID, v1.GetOptions{})
WithNamespace(OpenEBSNamespace).Get(volumeID, metav1.GetOptions{})
if err != nil {
return "", err
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func CreateOrUpdateCSIVolumeCR(csivol *apis.CSIVolume) error {
return err
}

csivol.OwnerReferences = []v1.OwnerReference{
csivol.OwnerReferences = []metav1.OwnerReference{
{
APIVersion: "v1",
Kind: "Node",
Expand All @@ -175,7 +175,7 @@ func UpdateCSIVolumeCR(csivol *apis.CSIVolume) error {

oldcsivol, err := csivolume.NewKubeclient().
WithNamespace(OpenEBSNamespace).
Get(csivol.Name, v1.GetOptions{})
Get(csivol.Name, metav1.GetOptions{})
if err != nil {
return err
}
Expand Down

0 comments on commit 84a4bd6

Please sign in to comment.