Skip to content

Commit

Permalink
Don't count terminating workspaces when checking shared PVC count
Browse files Browse the repository at this point in the history
Since terminating workspaces can't use the shared PVC for storage, it's
safe to ignore them when checking the shared PVC workspace count. This
allows deleting all workspaces in a namespace to work more quickly,
especially when there are a lot of workspaces.

Signed-off-by: Angel Misevski <[email protected]>
  • Loading branch information
amisevsk authored and ibuziuk committed Jun 6, 2022
1 parent a69ed55 commit cbd3fd1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/provision/storage/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,20 @@ func checkForExistingCommonPVC(namespace string, api sync.ClusterAPI) (string, e

// getSharedPVCWorkspaceCount returns the total number of workspaces which are using a shared PVC
// (i.e the workspaces storage-class attribute is set to "common", "async", or unset which defaults to "common")
// Note that workspaces that are have been deleted (i.e. have a deletion timestamp) are not counted.
func getSharedPVCWorkspaceCount(namespace string, api sync.ClusterAPI) (total int, err error) {
workspaces := &dw.DevWorkspaceList{}
err = api.Client.List(api.Ctx, workspaces, &client.ListOptions{Namespace: namespace})
if err != nil {
return 0, err
}
for _, workspace := range workspaces.Items {
if workspace.DeletionTimestamp != nil {
// Ignore terminating workspaces
continue
}
storageClass := workspace.Spec.Template.Attributes.GetString(constants.DevWorkspaceStorageTypeAttribute, nil)
// Note, if the storageClass attribute isin't set (ie. storageClass == ""), then the storage class being used is "common"
// Note, if the storageClass attribute isn't set (ie. storageClass == ""), then the storage class being used is "common"
if storageClass == constants.AsyncStorageClassType || storageClass == constants.CommonStorageClassType || storageClass == "" {
total++
}
Expand Down

0 comments on commit cbd3fd1

Please sign in to comment.