[ARVADOS] updated: 2.1.0-488-g0a27815bd
Git user
git at public.arvados.org
Tue Mar 16 18:13:24 UTC 2021
Summary of changes:
lib/crunchrun/container_exec_types.go | 31 +++++++++++++++++++++----
lib/crunchrun/crunchrun.go | 19 ++++++----------
lib/crunchrun/docker_adapter.go | 43 +++++++++++++++++++++++++++++++++--
lib/crunchrun/singularity.go | 13 +++++++++++
4 files changed, 88 insertions(+), 18 deletions(-)
via 0a27815bdf3f1d1bc1eb3771bcee9294b6f4136f (commit)
from bd175fc5207cfa7bf30ca62e2ef830192059ba68 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit 0a27815bdf3f1d1bc1eb3771bcee9294b6f4136f
Author: Nico Cesar <nico at nicocesar.com>
Date: Tue Mar 16 14:13:05 2021 -0400
moving HostConfig into the ThinContainerExecRunner interface
Arvados-DCO-1.1-Signed-off-by: Nico Cesar <nico at curii.com>
diff --git a/lib/crunchrun/container_exec_types.go b/lib/crunchrun/container_exec_types.go
index fc865af73..1b8f8876a 100644
--- a/lib/crunchrun/container_exec_types.go
+++ b/lib/crunchrun/container_exec_types.go
@@ -32,6 +32,23 @@ type ContainerConfig struct {
Volumes map[string]struct{}
}
+// LogConfig represents the logging configuration of the container.
+type LogConfig struct {
+ Type string
+ Config map[string]string
+}
+
+// Resources contains container's resources (cgroups config, ulimits...)
+type Resources struct {
+ Memory int64 // Memory limit (in bytes)
+ NanoCPUs int64 `json:"NanoCpus"` // CPU quota in units of 10<sup>-9</sup> CPUs.
+ CgroupParent string // Parent cgroup.
+ MemorySwap int64 // Total memory usage (memory + swap); set `-1` to enable unlimited swap
+ KernelMemory int64 // Kernel memory limit (in bytes)
+}
+
+type NetworkMode string
+
// HostConfig holds all values needed for Docker and Singularity
// to run a container related to the host. In the case of docker is
// similar to github.com/docker/docker/api/types/container/HostConfig
@@ -39,11 +56,13 @@ type ContainerConfig struct {
// "dependent of the host we are running on".
// and for Singularity TBD
type HostConfig struct {
+ NetworkMode NetworkMode
+ Binds []string // List of volume bindings for this container
//important bits:
- // - Binds:
- // LogConfig
- // Resources: see dockercontainer.Resources
- // NetworkMode: see dockercontainer.NetworkMode
+ LogConfig LogConfig // Configuration of the logs for this container
+
+ // Contains container's resources (cgroups, ulimits)
+ Resources
}
// ---- NETROWKING STUFF
@@ -284,6 +303,10 @@ type ThinContainerExecRunner interface {
GetImage() (imageID string)
SetImage(imageID string)
+ SetHostConfig(hostConfig HostConfig) error
+ GetNetworkMode() (networkMode NetworkMode)
+ SetNetworkMode(networkMode NetworkMode)
+
ContainerAttach(ctx context.Context, container string, options ContainerAttachOptions) (HijackedResponse, error)
ContainerCreate(ctx context.Context, config ContainerConfig, hostConfig HostConfig, networkingConfig *NetworkingConfig, containerName string) (ContainerCreateResponse, error)
ContainerStart(ctx context.Context, container string, options ContainerStartOptions) error
diff --git a/lib/crunchrun/crunchrun.go b/lib/crunchrun/crunchrun.go
index ad10b6f9c..8c989d533 100644
--- a/lib/crunchrun/crunchrun.go
+++ b/lib/crunchrun/crunchrun.go
@@ -97,11 +97,6 @@ type PsProcess interface {
type ContainerRunner struct {
ContainerExecRunner ThinContainerExecRunner
- //Docker ThinDockerClient
- //ContainerConfig dockercontainer.Config //FIXME: translate this to the ThinContainerRunner interface
- HostConfig dockercontainer.HostConfig //FIXME: translate this to the ThinContainerRunner interface
- //--------------
-
// Dispatcher client is initialized with the Dispatcher token.
// This is a privileged token used to manage container status
// and logs.
@@ -1086,12 +1081,12 @@ func (runner *ContainerRunner) CreateContainer() error {
// Docker daemon won't let you set a limit less than ~10 MiB
maxRAM = minDockerRAM * 1024 * 1024
}
- runner.HostConfig = dockercontainer.HostConfig{
+ hostConfig = HostConfig{
Binds: runner.Binds,
- LogConfig: dockercontainer.LogConfig{
+ LogConfig: LogConfig{
Type: "none",
},
- Resources: dockercontainer.Resources{
+ Resources: Resources{
CgroupParent: runner.setCgroupParent,
NanoCPUs: int64(runner.Container.RuntimeConstraints.VCPUs) * 1000000000,
Memory: maxRAM, // RAM
@@ -1099,7 +1094,7 @@ func (runner *ContainerRunner) CreateContainer() error {
KernelMemory: maxRAM, // kernel portion
},
}
-
+ runner.ContainerExecRunner.SetHostConfig(hostConfig)
if runner.Container.RuntimeConstraints.API {
tok, err := runner.ContainerToken()
if err != nil {
@@ -1110,12 +1105,12 @@ func (runner *ContainerRunner) CreateContainer() error {
"ARVADOS_API_HOST="+os.Getenv("ARVADOS_API_HOST"),
"ARVADOS_API_HOST_INSECURE="+os.Getenv("ARVADOS_API_HOST_INSECURE"),
)
- runner.HostConfig.NetworkMode = dockercontainer.NetworkMode(runner.networkMode)
+ runner.ContainerExecRunner.SetNetworkMode(NetworkMode(runner.networkMode))
} else {
if runner.enableNetwork == "always" {
- runner.HostConfig.NetworkMode = dockercontainer.NetworkMode(runner.networkMode)
+ runner.ContainerExecRunner.SetNetworkMode(NetworkMode(runner.networkMode))
} else {
- runner.HostConfig.NetworkMode = dockercontainer.NetworkMode("none")
+ runner.ContainerExecRunner.SetNetworkMode("none")
}
}
diff --git a/lib/crunchrun/docker_adapter.go b/lib/crunchrun/docker_adapter.go
index 1019e7df7..f6c1a1a61 100644
--- a/lib/crunchrun/docker_adapter.go
+++ b/lib/crunchrun/docker_adapter.go
@@ -16,7 +16,7 @@ import (
type DockerAdapter struct {
docker ThinDockerClient
containerConfig ContainerConfig
- hostConfig HostConfig
+ hostConfig dockercontainer.HostConfig
}
func (a *DockerAdapter) ContainerAttach(ctx context.Context, container string, options ContainerAttachOptions) (HijackedResponse, error) {
@@ -209,8 +209,40 @@ func (a *DockerAdapter) GetContainerConfig() (ContainerConfig, error) {
}
func (a *DockerAdapter) GetHostConfig() (HostConfig, error) {
- return a.hostConfig, nil
+ adapterHostConfig := HostConfig{
+ Binds: a.hostConfig.Binds,
+ LogConfig: LogConfig{
+ Type: a.hostConfig.LogConfig.Type,
+ },
+ Resources: Resources{
+ CgroupParent: a.hostConfig.CgroupParent,
+ NanoCPUs: a.hostConfig.NanoCPUs,
+ Memory: a.hostConfig.Memory,
+ MemorySwap: a.hostConfig.MemorySwap,
+ KernelMemory: a.hostConfig.KernelMemory,
+ },
+ }
+ return adapterHostConfig, nil
+}
+
+func (a *DockerAdapter) SetHostConfig(adapterHostConfig HostConfig) error {
+ dockerHostConfig := dockercontainer.HostConfig{
+ Binds: adapterHostConfig.Binds,
+ LogConfig: dockercontainer.LogConfig{
+ Type: adapterHostConfig.LogConfig.Type,
+ },
+ Resources: dockercontainer.Resources{
+ CgroupParent: adapterHostConfig.CgroupParent,
+ NanoCPUs: adapterHostConfig.NanoCPUs,
+ Memory: adapterHostConfig.Memory,
+ MemorySwap: adapterHostConfig.MemorySwap,
+ KernelMemory: adapterHostConfig.KernelMemory,
+ },
+ }
+ a.hostConfig = dockerHostConfig
+ return nil
}
+
func (a *DockerAdapter) GetImage() (imageID string) {
return a.containerConfig.Image
}
@@ -218,6 +250,13 @@ func (a *DockerAdapter) GetImage() (imageID string) {
func (a *DockerAdapter) SetImage(imageID string) {
a.containerConfig.Image = imageID
}
+func (a *DockerAdapter) GetNetworkMode() (networkMode NetworkMode) {
+ return NetworkMode(a.hostConfig.NetworkMode)
+}
+
+func (a *DockerAdapter) SetNetworkMode(networkMode NetworkMode) {
+ a.hostConfig.NetworkMode = dockercontainer.NetworkMode(networkMode)
+}
func adapter(docker ThinDockerClient) ThinContainerExecRunner {
return_object := &DockerAdapter{docker: docker}
diff --git a/lib/crunchrun/singularity.go b/lib/crunchrun/singularity.go
index 6b36e6866..d83cf2804 100644
--- a/lib/crunchrun/singularity.go
+++ b/lib/crunchrun/singularity.go
@@ -32,6 +32,19 @@ func (c SingularityClient) SetImage(imageID string) {
c.containerConfig.Image = imageID
}
+func (c SingularityClient) GetNetworkMode() (networkMode NetworkMode) {
+ return c.hostConfig.NetworkMode
+}
+
+func (c SingularityClient) SetNetworkMode(networkMode NetworkMode) {
+ c.hostConfig.NetworkMode = networkMode
+}
+
+func (c SingularityClient) SetHostConfig(hostConfig HostConfig) error {
+ c.hostConfig = hostConfig
+ return nil
+}
+
func (c SingularityClient) ContainerAttach(ctx context.Context, container string, options ContainerAttachOptions) (HijackedResponse, error) {
fmt.Printf("placeholder for container ContainerAttach %s", container)
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list