From ef62b580a00b262f4642b76c853578dfc249d44b Mon Sep 17 00:00:00 2001 From: Angel Misevski Date: Thu, 2 Jun 2022 16:54:28 -0400 Subject: [PATCH] Don't count terminating workspaces when checking shared PVC count 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 --- pkg/provision/storage/shared.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/provision/storage/shared.go b/pkg/provision/storage/shared.go index 641c37bec..22e186236 100644 --- a/pkg/provision/storage/shared.go +++ b/pkg/provision/storage/shared.go @@ -238,6 +238,7 @@ 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}) @@ -245,8 +246,12 @@ func getSharedPVCWorkspaceCount(namespace string, api sync.ClusterAPI) (total in 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++ }