Checking for waitforfirstConsumer if pvc's storage class has that set as volumebindingmode.
@@ -16,13 +16,16 @@ import (
"github.com/libopenstorage/stork/pkg/crypto"
"github.com/libopenstorage/stork/pkg/objectstore"
"github.com/portworx/sched-ops/k8s/core"
+ "github.com/portworx/sched-ops/k8s/storage"
"github.com/sirupsen/logrus"
"gocloud.dev/blob"
"gocloud.dev/gcerrors"
v1 "k8s.io/api/core/v1"
+ storagev1 "k8s.io/api/storage/v1"
k8s_errors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/rest"
+ k8shelper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
)
const (
@@ -362,6 +365,10 @@ func (c *csiDriver) RestoreStatus(pvcName, namespace string) (RestoreInfo, error
}
switch {
+ case c.pvcWaitingForFirstConsumer(pvc):
+ restoreInfo.VolumeName = pvc.Spec.VolumeName
+ restoreInfo.Size = size
+ restoreInfo.Status = StatusReady
case c.pvcBindFinished(pvc):
restoreInfo.VolumeName = pvc.Spec.VolumeName
restoreInfo.Size = size
@@ -527,6 +534,21 @@ func (c *csiDriver) pvcBindFinished(pvc *v1.PersistentVolumeClaim) bool {
return pvc.Status.Phase == v1.ClaimBound && bindCompleted == "yes" && boundByController == "yes"
}
+func (c *csiDriver) pvcWaitingForFirstConsumer(pvc *v1.PersistentVolumeClaim) bool {
+ var sc *storagev1.StorageClass
+ var err error
+ storageClassName := k8shelper.GetPersistentVolumeClaimClass(pvc)
+ if storageClassName != "" {
+ sc, err = storage.Instance().GetStorageClass(storageClassName)
+ if err != nil {
+ logrus.Warnf("did not get the storageclass %s for pvc %s/%s, err: %v", storageClassName, pvc.Namespace, pvc.Name, err)
+ return false
+ }
+ return *sc.VolumeBindingMode == storagev1.VolumeBindingWaitForFirstConsumer
+ }
+ return false
+}
+
func (c *csiDriver) getSnapshotContentError(vscName string) string {
if vsc, err := c.snapshotClient.SnapshotV1beta1().VolumeSnapshotContents().Get(context.TODO(), vscName, metav1.GetOptions{}); err == nil && vsc != nil {
if vsc.Status != nil && vsc.Status.Error != nil && vsc.Status.Error.Message != nil {
