Skip to content

Commit f97d412

Browse files
committed
Rework functionality for detecting existing PVCs on cluster
Rename the checkForExistingPVC function to make functionality clearer and fix handling of common PVC when using DevWorkspaceWithConfig. This fixes an issue where DWO does not provision the default common PVC. Signed-off-by: Angel Misevski <[email protected]>
1 parent 41d8cf1 commit f97d412

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

pkg/provision/storage/asyncStorage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (p *AsyncStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdd
8989
return err
9090
}
9191

92-
pvcName, err := checkForExistingCommonPVC(workspace.Namespace, clusterAPI)
92+
usingAlternatePVC, pvcName, err := checkForAlternatePVC(workspace.Namespace, clusterAPI)
9393
if err != nil {
9494
return err
9595
}
@@ -107,7 +107,7 @@ func (p *AsyncStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAdd
107107
}
108108
}
109109

110-
if pvcName != "" {
110+
if !usingAlternatePVC {
111111
// Create common PVC if needed
112112
clusterPVC, err := syncCommonPVC(workspace.Namespace, workspace.Config, clusterAPI)
113113
if err != nil {

pkg/provision/storage/cleanup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func runCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, clusterAPI
117117
func getSpecCommonPVCCleanupJob(workspace *common.DevWorkspaceWithConfig, clusterAPI sync.ClusterAPI) (*batchv1.Job, error) {
118118
workspaceId := workspace.Status.DevWorkspaceId
119119

120-
pvcName, err := checkForExistingCommonPVC(workspace.Namespace, clusterAPI)
120+
_, pvcName, err := checkForAlternatePVC(workspace.Namespace, clusterAPI)
121121
if err != nil {
122122
return nil, err
123123
}

pkg/provision/storage/commonStorage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func (p *CommonStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAd
5353
return nil
5454
}
5555

56-
pvcName, err := checkForExistingCommonPVC(workspace.Namespace, clusterAPI)
56+
usingAlternatePVC, pvcName, err := checkForAlternatePVC(workspace.Namespace, clusterAPI)
5757
if err != nil {
5858
return err
5959
}
@@ -71,7 +71,7 @@ func (p *CommonStorageProvisioner) ProvisionStorage(podAdditions *v1alpha1.PodAd
7171
}
7272
}
7373

74-
if pvcName == "" {
74+
if !usingAlternatePVC {
7575
commonPVC, err := syncCommonPVC(workspace.Namespace, workspace.Config, clusterAPI)
7676
if err != nil {
7777
return err

pkg/provision/storage/shared.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,22 @@ func processProjectsVolume(workspace *dw.DevWorkspaceTemplateSpec) (projectsComp
219219
return
220220
}
221221

222-
// checkForExistingCommonPVC checks the current namespace for existing PVCs that may be used for workspace storage. If
222+
// checkForAlternatePVC checks the current namespace for existing PVCs that may be used for workspace storage. If
223223
// such a PVC is found, its name is returned and should be used in place of the configured common PVC. If no suitable
224224
// PVC is found, the returned PVC name is an empty string and a nil error is returned. If an error occurs during the lookup,
225225
// then an empty string is returned as well as the error.
226-
func checkForExistingCommonPVC(namespace string, api sync.ClusterAPI) (string, error) {
226+
// Currently, the only alternate PVC that can be used is named `claim-che-workspace`.
227+
func checkForAlternatePVC(namespace string, api sync.ClusterAPI) (exists bool, name string, err error) {
227228
existingPVC := &corev1.PersistentVolumeClaim{}
228229
namespacedName := types.NamespacedName{Name: constants.CheCommonPVCName, Namespace: namespace}
229-
err := api.Client.Get(api.Ctx, namespacedName, existingPVC)
230+
err = api.Client.Get(api.Ctx, namespacedName, existingPVC)
230231
if err != nil {
231232
if k8sErrors.IsNotFound(err) {
232-
return "", nil
233+
return false, "", nil
233234
}
234-
return "", err
235+
return false, "", err
235236
}
236-
return existingPVC.Name, nil
237+
return true, existingPVC.Name, nil
237238
}
238239

239240
// getSharedPVCWorkspaceCount returns the total number of workspaces which are using a shared PVC

0 commit comments

Comments
 (0)