Skip to content

Commit e7d8d59

Browse files
author
Abhishek Agarwal
committed
Merge branch 'develop' of github.com:openebs/cstor-csi into develop
2 parents 68d25d3 + 2cf154a commit e7d8d59

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

buildscripts/cstor-csi-driver/cstor-csi-driver.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
FROM golang:1.14.7 as build
15+
FROM golang:1.16.5 as build
1616

1717
ARG BRANCH
1818
ARG RELEASE_TAG

pkg/driver/node_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ func (ns *node) prepareVolumeForNode(
409409
return err
410410
}
411411

412-
if err = utils.DeleteOldCStorVolumeAttachmentCRs(volumeID); err != nil {
412+
if err = utils.DeleteOldCStorVolumeAttachmentCRs(volumeID, nodeID); err != nil {
413413
return status.Error(codes.Internal, err.Error())
414414
}
415415
if err = utils.CreateCStorVolumeAttachmentCR(vol, nodeID); err != nil {

pkg/utils/kubernetes.go

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@
1515
package utils
1616

1717
import (
18+
"strings"
19+
"time"
20+
1821
apis "github.com/openebs/api/v3/pkg/apis/cstor/v1"
19-
csv "github.com/openebs/cstor-csi/pkg/cstor/volume"
20-
csivolume "github.com/openebs/cstor-csi/pkg/cstor/volumeattachment"
21-
node "github.com/openebs/cstor-csi/pkg/kubernetes/node"
22-
pv "github.com/openebs/cstor-csi/pkg/kubernetes/persistentvolume"
2322
errors "github.com/pkg/errors"
2423
"github.com/sirupsen/logrus"
2524
corev1 "k8s.io/api/core/v1"
25+
k8serrors "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
28+
csv "github.com/openebs/cstor-csi/pkg/cstor/volume"
29+
csivolume "github.com/openebs/cstor-csi/pkg/cstor/volumeattachment"
30+
node "github.com/openebs/cstor-csi/pkg/kubernetes/node"
31+
pv "github.com/openebs/cstor-csi/pkg/kubernetes/persistentvolume"
2732
)
2833

2934
const (
@@ -37,6 +42,12 @@ const (
3742
VOLNAME = "Volname"
3843
)
3944

45+
var (
46+
// loopCount is the no of times cStor volume attachment's successful deletion check
47+
// will be performed
48+
loopCount = 5
49+
)
50+
4051
// getNodeDetails fetches the nodeInfo for the current node
4152
func getNodeDetails(name string) (*corev1.Node, error) {
4253
return node.NewKubeClient().Get(name, metav1.GetOptions{})
@@ -145,7 +156,10 @@ func UpdateCStorVolumeAttachmentCR(csivol *apis.CStorVolumeAttachment) (*apis.CS
145156
// gets deleted or replaced or updated
146157

147158
// DeleteOldCStorVolumeAttachmentCRs removes the CStorVolumeAttachmentCR for the specified path
148-
func DeleteOldCStorVolumeAttachmentCRs(volumeID string) error {
159+
func DeleteOldCStorVolumeAttachmentCRs(volumeID, nodeID string) error {
160+
// nodeCVA contains the name of the cStor volume attachment for the current node
161+
var nodeCVA string
162+
149163
csivols, err := GetVolList(volumeID)
150164
if err != nil {
151165
return err
@@ -158,7 +172,35 @@ func DeleteOldCStorVolumeAttachmentCRs(volumeID string) error {
158172
if err != nil {
159173
return err
160174
}
175+
176+
// Extract only the CVA which belongs to the current node
177+
if strings.HasSuffix(csivol.Name, nodeID) {
178+
nodeCVA = csivol.Name
179+
}
180+
}
181+
182+
if nodeCVA != "" {
183+
var err error
184+
for i := 1; i <= loopCount; i++ {
185+
_, err = csivolume.NewKubeclient().
186+
WithNamespace(OpenEBSNamespace).Get(nodeCVA, metav1.GetOptions{})
187+
if err != nil {
188+
// If the error is an error of type "not found" then break out
189+
// of the loop since the deletion is succeeded
190+
if k8serrors.IsNotFound(err) {
191+
err = nil
192+
break
193+
}
194+
}
195+
time.Sleep(1 * time.Second)
196+
}
197+
// If error still exists, simply log that here. Since the deletion of CVA
198+
// will be taken care of its corresponding create request when it happens
199+
if err != nil {
200+
logrus.Infof("cStor volume attachment: {%v} not deleted. Error: {%v}", nodeCVA, err)
201+
}
161202
}
203+
162204
return nil
163205
}
164206

0 commit comments

Comments
 (0)