Skip to content

Commit

Permalink
feat: stop carina controller from trying to expand/delete volume on a…
Browse files Browse the repository at this point in the history
… node removed from the cluster

Signed-off-by: Hao Fan <[email protected]>
  • Loading branch information
fanhaouu committed Sep 17, 2023
1 parent 960725d commit 2bbefcc
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pkg/csidriver/driver/k8s/logicvolume_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -249,6 +250,10 @@ func (s *LogicVolumeService) DeleteVolume(ctx context.Context, volumeID string)
return err
}

if !lv.GetDeletionTimestamp().IsZero() {
return errors.New("lv is being deleted")
}

err = s.Delete(ctx, lv)
if err != nil {
if apierrors.IsNotFound(err) {
Expand All @@ -257,6 +262,13 @@ func (s *LogicVolumeService) DeleteVolume(ctx context.Context, volumeID string)
return err
}

// if the node doesn't exist, return directly
existingNode := new(corev1.Node)
err = s.getter.Get(ctx, client.ObjectKey{Name: lv.Spec.NodeName}, existingNode)
if err != nil {
return err
}

// wait until delete the target volume
for {
log.Info("waiting for delete LogicalVolume name ", lv.Name)
Expand Down Expand Up @@ -286,6 +298,13 @@ func (s *LogicVolumeService) ExpandVolume(ctx context.Context, volumeID string,
return err
}

// if the node doesn't exist, return directly
existingNode := new(corev1.Node)
err = s.getter.Get(ctx, client.ObjectKey{Name: lv.Spec.NodeName}, existingNode)
if err != nil {
return err
}

err = s.UpdateLogicVolumeSpecSize(ctx, volumeID, resource.NewQuantity(requestGb<<30, resource.BinarySI))
if err != nil {
return err
Expand Down

0 comments on commit 2bbefcc

Please sign in to comment.