Skip to content

Commit

Permalink
Enable experimentalNetwork by default
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf authored and roboquat committed Dec 7, 2021
1 parent 17823cf commit 537672b
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 48 deletions.
2 changes: 1 addition & 1 deletion components/gitpod-protocol/data/gitpod-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
},
"experimentalNetwork": {
"type": "boolean",
"description": "Experimental network configuration in workspaces"
"description": "Experimental network configuration in workspaces (deprecated). Enabled by default"
}
},
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ export interface WorkspaceConfig {
github?: GithubAppConfig;
vscode?: VSCodeConfig;

/** tailscale demo */
/** deprecated. Enabled by default **/
experimentalNetwork?: boolean;

/**
Expand Down
7 changes: 0 additions & 7 deletions components/server/src/workspace/workspace-starter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,6 @@ export class WorkspaceStarter {
vsxRegistryUrl.setValue(this.config.vsxRegistryUrl);
envvars.push(vsxRegistryUrl);

if (workspace.config.experimentalNetwork) {
const useNetnsVar = new EnvironmentVariable();
useNetnsVar.setName("WORKSPACEKIT_USE_NETNS");
useNetnsVar.setValue("true");
envvars.push(useNetnsVar);
}

const createGitpodTokenPromise = (async () => {
const scopes = this.createDefaultGitpodAPITokenScopes(workspace, instance);
const token = crypto.randomBytes(30).toString('hex');
Expand Down
69 changes: 30 additions & 39 deletions components/workspacekit/cmd/rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ var ring1Cmd = &cobra.Command{
}

var (
wrapNetns = os.Getenv("WORKSPACEKIT_USE_NETNS") == "true"
slirp4netnsSocket string
)

Expand Down Expand Up @@ -308,17 +307,15 @@ var ring1Cmd = &cobra.Command{
)
}

if wrapNetns {
f, err := ioutil.TempDir("", "wskit-slirp4netns")
if err != nil {
log.WithError(err).Error("cannot create slirp4netns socket tempdir")
return
}

slirp4netnsSocket = filepath.Join(f, "slirp4netns.sock")
mnts = append(mnts, mnte{Target: "/.supervisor/slirp4netns.sock", Source: f, Flags: unix.MS_BIND | unix.MS_REC})
f, err := ioutil.TempDir("", "wskit-slirp4netns")
if err != nil {
log.WithError(err).Error("cannot create slirp4netns socket tempdir")
return
}

slirp4netnsSocket = filepath.Join(f, "slirp4netns.sock")
mnts = append(mnts, mnte{Target: "/.supervisor/slirp4netns.sock", Source: f, Flags: unix.MS_BIND | unix.MS_REC})

for _, m := range mnts {
dst := filepath.Join(ring2Root, m.Target)
_ = os.MkdirAll(dst, 0644)
Expand Down Expand Up @@ -358,9 +355,8 @@ var ring1Cmd = &cobra.Command{
}
env = append(env, e)
}
if wrapNetns {
env = append(env, "WORKSPACEKIT_WRAP_NETNS=true")
}

env = append(env, "WORKSPACEKIT_WRAP_NETNS=true")

socketFN := filepath.Join(os.TempDir(), fmt.Sprintf("workspacekit-ring1-%d.unix", time.Now().UnixNano()))
skt, err := net.Listen("unix", socketFN)
Expand All @@ -371,11 +367,8 @@ var ring1Cmd = &cobra.Command{
defer skt.Close()

var (
cloneFlags uintptr = syscall.CLONE_NEWNS | syscall.CLONE_NEWPID
cloneFlags uintptr = syscall.CLONE_NEWNS | syscall.CLONE_NEWPID | syscall.CLONE_NEWNET
)
if wrapNetns {
cloneFlags = cloneFlags | syscall.CLONE_NEWNET
}

cmd := exec.Command("/proc/self/exe", "ring2", socketFN)
cmd.SysProcAttr = &syscall.SysProcAttr{
Expand Down Expand Up @@ -463,30 +456,28 @@ var ring1Cmd = &cobra.Command{
return
}

if wrapNetns {
slirpCmd := exec.Command(filepath.Join(filepath.Dir(ring2Opts.SupervisorPath), "slirp4netns"),
"--configure",
"--mtu=65520",
"--disable-host-loopback",
"--api-socket", slirp4netnsSocket,
strconv.Itoa(cmd.Process.Pid),
"tap0",
)
slirpCmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
slirpCmd.Stdin = os.Stdin
slirpCmd.Stdout = os.Stdout
slirpCmd.Stderr = os.Stderr
slirpCmd := exec.Command(filepath.Join(filepath.Dir(ring2Opts.SupervisorPath), "slirp4netns"),
"--configure",
"--mtu=65520",
"--disable-host-loopback",
"--api-socket", slirp4netnsSocket,
strconv.Itoa(cmd.Process.Pid),
"tap0",
)
slirpCmd.SysProcAttr = &syscall.SysProcAttr{
Pdeathsig: syscall.SIGKILL,
}
slirpCmd.Stdin = os.Stdin
slirpCmd.Stdout = os.Stdout
slirpCmd.Stderr = os.Stderr

err = slirpCmd.Start()
if err != nil {
log.WithError(err).Error("cannot start slirp4netns")
return
}
//nolint:errcheck
defer slirpCmd.Process.Kill()
err = slirpCmd.Start()
if err != nil {
log.WithError(err).Error("cannot start slirp4netns")
return
}
//nolint:errcheck
defer slirpCmd.Process.Kill()

log.Info("signaling to child process")
_, err = msgutil.MarshalToWriter(ring2Conn, ringSyncMsg{
Expand Down

0 comments on commit 537672b

Please sign in to comment.