-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get rid of docker pause containers with a custom runtime #20017
Draft
apollo13
wants to merge
6
commits into
hashicorp:main
Choose a base branch
from
apollo13:no-docker-pause
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
93c0eee
Get rid of docker pause containers with a custom runtime. Closes #15086
apollo13 b87b6f1
Add very ugly runc command.
apollo13 c3a5780
Add error handling to runcshim and pass the "next runc" via runtime a…
apollo13 12dc8c7
Prefix runtimes with nomad- if nomad native networking is requested.
apollo13 5f77f6f
Added changelog.
apollo13 76a5f44
Added docs.
apollo13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
docker: Added support for running without pause containers when configuring networking | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package runcshim | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"slices" | ||
"syscall" | ||
|
||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
const ( | ||
ExitError = 1 | ||
) | ||
|
||
func exitWithMsg(msg string) { | ||
fmt.Fprintln(os.Stderr, msg) | ||
os.Exit(ExitError) | ||
} | ||
|
||
// This init() must be initialized last in package required by the child plugin | ||
// process. It's recommended to avoid any other `init()` or inline any necessary | ||
// calls here. See eeaa95d commit message for more details. | ||
func init() { | ||
if len(os.Args) > 1 && os.Args[1] == "runcshim" { | ||
if len(os.Args) <= 3 { | ||
exitWithMsg("expected path to runc compatible binary") | ||
} | ||
|
||
if slices.Contains(os.Args, "create") { | ||
var bundleRoot string | ||
if bundleIndex := slices.Index(os.Args, "--bundle"); bundleIndex != -1 { | ||
if !(bundleIndex+1 < len(os.Args)) { | ||
exitWithMsg("bundle directory not passed") | ||
} | ||
bundleRoot = os.Args[bundleIndex+1] | ||
} else { // Use cwd | ||
wd, err := os.Getwd() | ||
if err != nil { | ||
exitWithMsg(fmt.Sprint(err)) | ||
} | ||
bundleRoot = wd | ||
} | ||
configFile := fmt.Sprintf("%s/config.json", bundleRoot) | ||
jsonFile, err := os.Open(configFile) | ||
if err != nil { | ||
exitWithMsg(fmt.Sprintf("Could not open %q: %v", configFile, err)) | ||
} | ||
byteValue, err := io.ReadAll(jsonFile) | ||
if err != nil { | ||
jsonFile.Close() | ||
exitWithMsg(fmt.Sprintf("Could not read %q: %v", configFile, err)) | ||
} | ||
jsonFile.Close() | ||
|
||
var spec specs.Spec | ||
err = json.Unmarshal(byteValue, &spec) | ||
if err != nil { | ||
exitWithMsg(fmt.Sprintf("Could not unmarshal config: %v", err)) | ||
} | ||
|
||
annotation, ok := spec.Annotations["network_ns"] | ||
if !ok { | ||
exitWithMsg("Missing `network_ns` annotation. Are we called from Nomad?") | ||
} | ||
if spec.Linux == nil { | ||
exitWithMsg("Missing `linux` configuration, you are using linux are you?") | ||
} | ||
|
||
// If there is a network namespace, modify it | ||
foundNetworkNamespace := false | ||
for idx := range spec.Linux.Namespaces { | ||
if spec.Linux.Namespaces[idx].Type == "network" { | ||
spec.Linux.Namespaces[idx].Path = annotation | ||
foundNetworkNamespace = true | ||
break | ||
} | ||
} | ||
// if not add one | ||
if !foundNetworkNamespace { | ||
var namespace = specs.LinuxNamespace{Type: "network", Path: annotation} | ||
spec.Linux.Namespaces = append(spec.Linux.Namespaces, namespace) | ||
} | ||
|
||
jsonBytes, err := json.Marshal(spec) | ||
if err != nil { | ||
exitWithMsg(fmt.Sprintf("Could not marshal config: %v", err)) | ||
} | ||
err = os.WriteFile(configFile, jsonBytes, 0600) | ||
if err != nil { | ||
exitWithMsg(fmt.Sprintf("Failed writing config.json: %v", err)) | ||
} | ||
} | ||
|
||
runc_binary := os.Args[2] | ||
// Resolve full path via $PATH | ||
runc_binary, err := exec.LookPath(runc_binary) | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "Could not resolve full path for %q: %v", runc_binary, err) | ||
os.Exit(ExitError) | ||
} | ||
args := append([]string{filepath.Base(runc_binary)}, os.Args[3:]...) | ||
syscall.Exec(runc_binary, args, os.Environ()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might still be better to use "none" here and test if it still works? But the differences are probably marginal.
docker network inspect host/none
will show the containers either way, even if they are not really attached.