diff --git a/components/ws-daemon/pkg/content/hooks.go b/components/ws-daemon/pkg/content/hooks.go index 2997bc479c42f1..015e38d6a38589 100644 --- a/components/ws-daemon/pkg/content/hooks.go +++ b/components/ws-daemon/pkg/content/hooks.go @@ -29,6 +29,9 @@ func workspaceLifecycleHooks(cfg Config, kubernetesNamespace string, workspaceEx hookSetupWorkspaceLocation, startIWS, // workspacekit is waiting for starting IWS, so it needs to start as soon as possible. hookSetupRemoteStorage(cfg), + // When starting a workspace, use soft limit for the following reason to ensure content is restored + // - workspacekit needs to generate some temporary file when starting a workspace + // - when extracting tar file, tar command create some symlinks following a original content hookInstallQuota(xfs, false), }, session.WorkspaceReady: { @@ -98,17 +101,24 @@ func hookInstallQuota(xfs *quota.XFS, isHard bool) session.WorkspaceLivecycleHoo if xfs == nil { return nil } - size := quota.Size(ws.StorageQuota) - if size == 0 { + + if ws.StorageQuota == 0 { return nil } + size := quota.Size(ws.StorageQuota) + + var ( + prj int + err error + ) if ws.XFSProjectID != 0 { xfs.RegisterProject(ws.XFSProjectID) - return nil + prj, err = xfs.SetQuotaWithPrjId(ws.Location, size, ws.XFSProjectID, isHard) + } else { + prj, err = xfs.SetQuota(ws.Location, size, isHard) } - prj, err := xfs.SetQuota(ws.Location, size, isHard) if err != nil { log.WithFields(ws.OWI()).WithError(err).Warn("cannot enforce workspace size limit") } diff --git a/components/ws-daemon/pkg/quota/xfs.go b/components/ws-daemon/pkg/quota/xfs.go index cd4ee1f5b27722..a1272cb085e11c 100644 --- a/components/ws-daemon/pkg/quota/xfs.go +++ b/components/ws-daemon/pkg/quota/xfs.go @@ -113,6 +113,15 @@ func (xfs *XFS) SetQuota(path string, quota Size, isHard bool) (projectID int, e } }() + _, err = xfs.SetQuotaWithPrjId(path, quota, prjID, isHard) + if err != nil { + return 0, err + } + + return prjID, nil +} + +func (xfs *XFS) SetQuotaWithPrjId(path string, quota Size, prjID int, isHard bool) (projectID int, err error) { _, err = xfs.exec(xfs.Dir, fmt.Sprintf("project -s -d 1 -p %s %d", path, prjID)) if err != nil { return 0, err @@ -121,7 +130,7 @@ func (xfs *XFS) SetQuota(path string, quota Size, isHard bool) (projectID int, e if isHard { _, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bhard=%d %d", quota, prjID)) } else { - _, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bsoft=%d bhard=%d %d", quota, quota, prjID)) + _, err = xfs.exec(xfs.Dir, fmt.Sprintf("limit -p bsoft=%d %d", quota, prjID)) } if err != nil { diff --git a/components/ws-daemon/pkg/quota/xfs_test.go b/components/ws-daemon/pkg/quota/xfs_test.go index b734d4b254994e..0bd0b3fc6e2354 100644 --- a/components/ws-daemon/pkg/quota/xfs_test.go +++ b/components/ws-daemon/pkg/quota/xfs_test.go @@ -116,7 +116,7 @@ func TestSetQuota(t *testing.T) { ProjectIDs: []int{1000}, Execs: []string{ "project -s -d 1 -p /foo 1000", - "limit -p bsoft=102400 bhard=102400 1000", + "limit -p bsoft=102400 1000", }, }, },