mirror of
https://github.com/NVIDIA/nvidia-container-toolkit
synced 2025-05-09 22:31:59 +00:00
Merge branch 'fix-container-root' into 'main'
Fix bug in update-ldcache hook when OCI spec contains a relative root See merge request nvidia/container-toolkit/container-toolkit!147
This commit is contained in:
commit
d2516cb5d5
@ -86,14 +86,9 @@ func (m command) run(c *cli.Context, cfg *config) error {
|
|||||||
return fmt.Errorf("failed to load container state: %v", err)
|
return fmt.Errorf("failed to load container state: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, err := s.LoadSpec()
|
containerRoot, err := s.GetContainerRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to load OCI spec: %v", err)
|
return fmt.Errorf("failed to determined container root: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
var containerRoot string
|
|
||||||
if spec.Root != nil {
|
|
||||||
containerRoot = spec.Root.Path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
csvFiles := cfg.filenames.Value()
|
csvFiles := cfg.filenames.Value()
|
||||||
|
@ -79,14 +79,9 @@ func (m command) run(c *cli.Context, cfg *config) error {
|
|||||||
return fmt.Errorf("failed to load container state: %v", err)
|
return fmt.Errorf("failed to load container state: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
spec, err := s.LoadSpec()
|
containerRoot, err := s.GetContainerRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to load OCI spec: %v", err)
|
return fmt.Errorf("failed to determined container root: %v", err)
|
||||||
}
|
|
||||||
|
|
||||||
var containerRoot string
|
|
||||||
if spec.Root != nil {
|
|
||||||
containerRoot = spec.Root.Path
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = m.createConfig(containerRoot, cfg.folders.Value())
|
err = m.createConfig(containerRoot, cfg.folders.Value())
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
)
|
)
|
||||||
@ -56,7 +57,7 @@ func ReadContainerState(reader io.Reader) (*State, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// LoadSpec loads the OCI spec associated with the container state
|
// LoadSpec loads the OCI spec associated with the container state
|
||||||
func (s State) LoadSpec() (*specs.Spec, error) {
|
func (s *State) LoadSpec() (*specs.Spec, error) {
|
||||||
specFilePath := GetSpecFilePath(s.Bundle)
|
specFilePath := GetSpecFilePath(s.Bundle)
|
||||||
specFile, err := os.Open(specFilePath)
|
specFile, err := os.Open(specFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,6 +69,25 @@ func (s State) LoadSpec() (*specs.Spec, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
return nil, fmt.Errorf("failed to load OCI spec: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return spec, nil
|
return spec, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetContainerRoot returns the root for the container from the associated spec. If the spec is not yet loaded, it is
|
||||||
|
// loaded and cached.
|
||||||
|
func (s *State) GetContainerRoot() (string, error) {
|
||||||
|
spec, err := s.LoadSpec()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
var containerRoot string
|
||||||
|
if spec.Root != nil {
|
||||||
|
containerRoot = spec.Root.Path
|
||||||
|
}
|
||||||
|
|
||||||
|
if filepath.IsAbs(containerRoot) {
|
||||||
|
return containerRoot, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return filepath.Join(s.Bundle, containerRoot), nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user