fix: delete instance data and remove legacy shared workspace support
This commit is contained in:
+6
-54
@@ -20,7 +20,7 @@ import (
|
||||
|
||||
const upgradeSnapshotLimit int64 = 1 << 30
|
||||
|
||||
func upgradeWorkspace(config, host map[string]json.RawMessage, recipe, home, shared string) error {
|
||||
func upgradeWorkspace(config, host map[string]json.RawMessage, recipe, home string) error {
|
||||
var mounts []map[string]json.RawMessage
|
||||
if err := json.Unmarshal(host["Mounts"], &mounts); err != nil {
|
||||
return errors.New("unsupported runtime mounts")
|
||||
@@ -30,53 +30,11 @@ func upgradeWorkspace(config, host map[string]json.RawMessage, recipe, home, sha
|
||||
_ = json.Unmarshal(m[key], &value)
|
||||
return value
|
||||
}
|
||||
homeIndex, sharedIndex := -1, -1
|
||||
for n, m := range mounts {
|
||||
target, source := get(m, "Target"), get(m, "Source")
|
||||
if target != "/workspace" && target != "/data/dsh-home" && target != "/shared" {
|
||||
continue
|
||||
}
|
||||
if get(m, "Type") != "bind" {
|
||||
return errors.New("unsupported runtime mount type")
|
||||
}
|
||||
switch {
|
||||
case source == home && (target == "/workspace" || target == "/data/dsh-home") && homeIndex == -1:
|
||||
homeIndex = n
|
||||
case source == shared && (target == "/workspace" || target == "/shared") && sharedIndex == -1:
|
||||
sharedIndex = n
|
||||
default:
|
||||
return errors.New("ambiguous runtime mounts")
|
||||
}
|
||||
}
|
||||
if homeIndex == -1 {
|
||||
return errors.New("instance home mount required")
|
||||
}
|
||||
if !supportedLayout(recipe) {
|
||||
return errors.New("unsupported template layout")
|
||||
return errors.New("unsupported template layout; template 7 required")
|
||||
}
|
||||
if recipe != "7" {
|
||||
if get(mounts[homeIndex], "Target") == "/workspace" {
|
||||
return errors.New("workspace home cannot be downgraded to legacy shared layout")
|
||||
}
|
||||
if sharedIndex == -1 || get(mounts[sharedIndex], "Target") != "/workspace" {
|
||||
return errors.New("legacy shared workspace mount required")
|
||||
}
|
||||
var env []string
|
||||
if raw := config["Env"]; len(raw) != 0 {
|
||||
if err := json.Unmarshal(raw, &env); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
kept := []string{}
|
||||
for _, entry := range env {
|
||||
key, _, _ := strings.Cut(entry, "=")
|
||||
if key != "DSH_HOME" && key != "HOME" && key != "XDG_DATA_HOME" && key != "XDG_CONFIG_HOME" {
|
||||
kept = append(kept, entry)
|
||||
}
|
||||
}
|
||||
kept = append(kept, "DSH_HOME=/data/dsh-home", "HOME=/data/dsh-home", "XDG_DATA_HOME=/data/dsh-home/.local/share", "XDG_CONFIG_HOME=/data/dsh-home/.config")
|
||||
config["Env"], _ = json.Marshal(kept)
|
||||
return nil
|
||||
if len(mounts) != 1 || get(mounts[0], "Type") != "bind" || get(mounts[0], "Source") != home || get(mounts[0], "Target") != "/workspace" {
|
||||
return errors.New("independent instance home at /workspace required")
|
||||
}
|
||||
for _, key := range []string{"Binds", "VolumesFrom"} {
|
||||
var values []string
|
||||
@@ -102,11 +60,6 @@ func upgradeWorkspace(config, host map[string]json.RawMessage, recipe, home, sha
|
||||
}
|
||||
}
|
||||
kept = append(kept, "DSH_HOME=/workspace", "HOME=/workspace", "XDG_DATA_HOME=/workspace/.local/share", "XDG_CONFIG_HOME=/workspace/.config")
|
||||
mounts[homeIndex]["Target"], _ = json.Marshal("/workspace")
|
||||
if sharedIndex != -1 {
|
||||
mounts = append(mounts[:sharedIndex], mounts[sharedIndex+1:]...)
|
||||
}
|
||||
host["Mounts"], _ = json.Marshal(mounts)
|
||||
config["Env"], _ = json.Marshal(kept)
|
||||
return nil
|
||||
}
|
||||
@@ -373,12 +326,11 @@ func (a *API) upgrade(w http.ResponseWriter, r *http.Request, i store.Instance)
|
||||
hostRoot = a.root
|
||||
}
|
||||
homeSource, homeErr := toHostPath(a.root, hostRoot, filepath.Join(root.Name(), "home"))
|
||||
sharedSource, sharedErr := toHostPath(a.root, hostRoot, filepath.Join(a.root, "workspaces", i.UID, "files"))
|
||||
if homeErr != nil || sharedErr != nil {
|
||||
if homeErr != nil {
|
||||
fail(w, 500, "host storage unavailable")
|
||||
return
|
||||
}
|
||||
if err = upgradeWorkspace(old.Config, old.HostConfig, image.Config.Labels["dsh-mgr.recipe"], homeSource, sharedSource); err != nil {
|
||||
if err = upgradeWorkspace(old.Config, old.HostConfig, image.Config.Labels["dsh-mgr.recipe"], homeSource); err != nil {
|
||||
fail(w, 409, "incompatible runtime workspace layout")
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user