From fbc265dff790ce1939002ee9cc0da547ec63d8c4 Mon Sep 17 00:00:00 2001 From: Lin Yiming Date: Fri, 22 Jan 2021 09:20:22 +0800 Subject: [PATCH] If bucket is not created by csi-s3, it will not be deleted by csi-s3 automatically --- pkg/s3/controllerserver.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/pkg/s3/controllerserver.go b/pkg/s3/controllerserver.go index f19709b..9351421 100644 --- a/pkg/s3/controllerserver.go +++ b/pkg/s3/controllerserver.go @@ -145,9 +145,18 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol return nil, err } if exists { - if err := s3.removeBucket(volumeID); err != nil { - glog.V(3).Infof("Failed to remove volume %s: %v", volumeID, err) - return nil, err + b, err := s3.getBucket(volumeID) + if err != nil { + return nil, fmt.Errorf("Failed to get metadata of buckect %s", volumeID) + } + if b.CreatedByCsi { + if err := s3.removeBucket(volumeID); err != nil { + glog.V(3).Infof("Failed to remove volume %s: %v", volumeID, err) + return nil, err + } + glog.V(4).Infof("Bucket %s removed", volumeID) + } else { + glog.V(4).Infof("Bucket %s is not created by csi-s3, will not be deleted by csi-s3 automatically.", volumeID) } } else { glog.V(5).Infof("Bucket %s does not exist, ignoring request", volumeID)