Skip to content

Commit

Permalink
Check the volume before creating
Browse files Browse the repository at this point in the history
  • Loading branch information
hwchiu committed Aug 27, 2018
1 parent 9a87329 commit 994f912
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/storageprovider/nfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ func (nfs NFSStorageProvider) ValidateBeforeCreating(sp *serviceprovider.Contain
if path == "" || path[0] != '/' {
return fmt.Errorf("Invalid NFS export path %s", path)
}

//If the storage is used by some volume, we can't delete it.
q := bson.M{"storageName": storage.Name}
session := sp.Mongo.NewSession()
defer session.Close()

count, err := session.Count(entity.VolumeCollectionName, q)
if err != nil {
return err
} else if count > 0 {
return fmt.Errorf("The StorageName %s can't be deleted, since there're some volume still use it", storage.Name)
}

return nil
}

Expand Down Expand Up @@ -129,18 +142,6 @@ func (nfs NFSStorageProvider) DeleteStorage(sp *serviceprovider.Container, stora
deployName := NFSProvisionerPrefix + storage.ID.Hex()
storageName := NFSStorageClassPrefix + storage.ID.Hex()

//If the storage is used by some volume, we can't delete it.
q := bson.M{"storageName": storage.Name}
session := sp.Mongo.NewSession()
defer session.Close()

count, err := session.Count(entity.VolumeCollectionName, q)
if err != nil {
return err
} else if count > 0 {
return fmt.Errorf("The StorageName %s can't be deleted, since there're some volume still use it", storage.Name)
}

//Delete StorageClass
if err := sp.KubeCtl.DeleteStorageClass(storageName); err != nil {
return err
Expand Down

0 comments on commit 994f912

Please sign in to comment.