From 8dd1452d69c76d2c23f65e90698cde561c5dd1f7 Mon Sep 17 00:00:00 2001 From: David Trudgian Date: Fri, 2 Dec 2022 12:20:50 +0000 Subject: [PATCH] chore: move BindPath code out of runtime package Signed-off-by: Edita Kizinevic --- internal/pkg/checkpoint/dmtcp/checkpoint.go | 8 ++++---- internal/pkg/runtime/launcher/native/launcher_linux.go | 7 ++++--- pkg/runtime/engine/apptainer/config/config.go | 7 ++++--- .../engine/apptainer/config => util/bind}/bind.go | 4 ++-- .../engine/apptainer/config => util/bind}/bind_test.go | 4 ++-- .../engine/apptainer/config => util/bind}/mount.go | 2 +- .../engine/apptainer/config => util/bind}/mount_test.go | 4 ++-- 7 files changed, 19 insertions(+), 17 deletions(-) rename pkg/{runtime/engine/apptainer/config => util/bind}/bind.go (98%) rename pkg/{runtime/engine/apptainer/config => util/bind}/bind_test.go (98%) rename pkg/{runtime/engine/apptainer/config => util/bind}/mount.go (99%) rename pkg/{runtime/engine/apptainer/config => util/bind}/mount_test.go (98%) diff --git a/internal/pkg/checkpoint/dmtcp/checkpoint.go b/internal/pkg/checkpoint/dmtcp/checkpoint.go index 2f46df3c31..4556acb142 100644 --- a/internal/pkg/checkpoint/dmtcp/checkpoint.go +++ b/internal/pkg/checkpoint/dmtcp/checkpoint.go @@ -14,7 +14,7 @@ import ( "os" "path/filepath" - apptainerConfig "github.com/apptainer/apptainer/pkg/runtime/engine/apptainer/config" + "github.com/apptainer/apptainer/pkg/util/bind" ) type Entry struct { @@ -38,11 +38,11 @@ func (e *Entry) CoordinatorPort() (string, error) { return s.Text(), nil } -func (e *Entry) BindPath() apptainerConfig.BindPath { - return apptainerConfig.BindPath{ +func (e *Entry) BindPath() bind.BindPath { + return bind.BindPath{ Source: e.path, Destination: containerStatepath, - Options: map[string]*apptainerConfig.BindOption{ + Options: map[string]*bind.BindOption{ "rw": {}, }, } diff --git a/internal/pkg/runtime/launcher/native/launcher_linux.go b/internal/pkg/runtime/launcher/native/launcher_linux.go index 4a3ef4541b..9784996fe1 100644 --- a/internal/pkg/runtime/launcher/native/launcher_linux.go +++ b/internal/pkg/runtime/launcher/native/launcher_linux.go @@ -51,6 +51,7 @@ import ( "github.com/apptainer/apptainer/pkg/runtime/engine/config" "github.com/apptainer/apptainer/pkg/sylog" "github.com/apptainer/apptainer/pkg/util/apptainerconf" + "github.com/apptainer/apptainer/pkg/util/bind" "github.com/apptainer/apptainer/pkg/util/capabilities" "github.com/apptainer/apptainer/pkg/util/cryptkey" "github.com/apptainer/apptainer/pkg/util/fs/proc" @@ -654,14 +655,14 @@ func (l *Launcher) useSuid(insideUserNs bool) (useSuid bool) { // setBinds sets engine configuration for requested bind mounts. func (l *Launcher) setBinds(fakerootPath string) error { // First get binds from -B/--bind and env var - binds, err := apptainerConfig.ParseBindPath(l.cfg.BindPaths) + binds, err := bind.ParseBindPath(l.cfg.BindPaths) if err != nil { return fmt.Errorf("while parsing bind path: %w", err) } // Now add binds from one or more --mount and env var. // Note that these do not get exported for nested containers for _, m := range l.cfg.Mounts { - bps, err := apptainerConfig.ParseMountString(m) + bps, err := bind.ParseMountString(m) if err != nil { return fmt.Errorf("while parsing mount %q: %w", m, err) } @@ -675,7 +676,7 @@ func (l *Launcher) setBinds(fakerootPath string) error { if err != nil { return fmt.Errorf("while getting fakeroot bindpoints: %w", err) } - fakebinds, err := apptainerConfig.ParseBindPath(fakebindPaths) + fakebinds, err := bind.ParseBindPath(fakebindPaths) if err != nil { return fmt.Errorf("while parsing fakeroot bind paths: %w", err) } diff --git a/pkg/runtime/engine/apptainer/config/config.go b/pkg/runtime/engine/apptainer/config/config.go index 506c36c286..8239fd273b 100644 --- a/pkg/runtime/engine/apptainer/config/config.go +++ b/pkg/runtime/engine/apptainer/config/config.go @@ -17,6 +17,7 @@ import ( "github.com/apptainer/apptainer/internal/pkg/runtime/engine/config/oci" "github.com/apptainer/apptainer/pkg/image" "github.com/apptainer/apptainer/pkg/util/apptainerconf" + "github.com/apptainer/apptainer/pkg/util/bind" ) // Name is the name of the runtime. @@ -89,7 +90,7 @@ type JSONConfig struct { LibrariesPath []string `json:"librariesPath,omitempty"` FuseMount []FuseMount `json:"fuseMount,omitempty"` ImageList []image.Image `json:"imageList,omitempty"` - BindPath []BindPath `json:"bindpath,omitempty"` + BindPath []bind.BindPath `json:"bindpath,omitempty"` ApptainerEnv map[string]string `json:"apptainerEnv,omitempty"` UnixSocketPair [2]int `json:"unixSocketPair,omitempty"` OpenFd []int `json:"openFd,omitempty"` @@ -305,12 +306,12 @@ func (e *EngineConfig) GetCustomHome() bool { } // SetBindPath sets the paths to bind into container. -func (e *EngineConfig) SetBindPath(bindpath []BindPath) { +func (e *EngineConfig) SetBindPath(bindpath []bind.BindPath) { e.JSON.BindPath = bindpath } // GetBindPath retrieves the bind paths. -func (e *EngineConfig) GetBindPath() []BindPath { +func (e *EngineConfig) GetBindPath() []bind.BindPath { return e.JSON.BindPath } diff --git a/pkg/runtime/engine/apptainer/config/bind.go b/pkg/util/bind/bind.go similarity index 98% rename from pkg/runtime/engine/apptainer/config/bind.go rename to pkg/util/bind/bind.go index 24cb738669..86f1f37d47 100644 --- a/pkg/runtime/engine/apptainer/config/bind.go +++ b/pkg/util/bind/bind.go @@ -1,9 +1,9 @@ -// Copyright (c) 2019-2021, Sylabs Inc. All rights reserved. +// Copyright (c) 2019-2022, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE.md file distributed with the sources of this project regarding your // rights to use or distribute this software. -package apptainer +package bind import ( "fmt" diff --git a/pkg/runtime/engine/apptainer/config/bind_test.go b/pkg/util/bind/bind_test.go similarity index 98% rename from pkg/runtime/engine/apptainer/config/bind_test.go rename to pkg/util/bind/bind_test.go index 6431886b41..a1cc61f20a 100644 --- a/pkg/runtime/engine/apptainer/config/bind_test.go +++ b/pkg/util/bind/bind_test.go @@ -1,9 +1,9 @@ -// Copyright (c) 2021, Sylabs Inc. All rights reserved. +// Copyright (c) 2021-2022, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE.md file distributed with the sources of this project regarding your // rights to use or distribute this software. -package apptainer +package bind import ( "reflect" diff --git a/pkg/runtime/engine/apptainer/config/mount.go b/pkg/util/bind/mount.go similarity index 99% rename from pkg/runtime/engine/apptainer/config/mount.go rename to pkg/util/bind/mount.go index d4e2b35f78..959e40706f 100644 --- a/pkg/runtime/engine/apptainer/config/mount.go +++ b/pkg/util/bind/mount.go @@ -3,7 +3,7 @@ // LICENSE.md file distributed with the sources of this project regarding your // rights to use or distribute this software. -package apptainer +package bind import ( "encoding/csv" diff --git a/pkg/runtime/engine/apptainer/config/mount_test.go b/pkg/util/bind/mount_test.go similarity index 98% rename from pkg/runtime/engine/apptainer/config/mount_test.go rename to pkg/util/bind/mount_test.go index 46820cb732..a0ffce702a 100644 --- a/pkg/runtime/engine/apptainer/config/mount_test.go +++ b/pkg/util/bind/mount_test.go @@ -1,9 +1,9 @@ -// Copyright (c) 2021, Sylabs Inc. All rights reserved. +// Copyright (c) 2022, Sylabs Inc. All rights reserved. // This software is licensed under a 3-clause BSD license. Please consult the // LICENSE.md file distributed with the sources of this project regarding your // rights to use or distribute this software. -package apptainer +package bind import ( "reflect"