namespaces.go 773 B

123456789101112131415161718192021222324252627
  1. package oci // import "github.com/docker/docker/oci"
  2. import specs "github.com/opencontainers/runtime-spec/specs-go"
  3. // RemoveNamespace removes the `nsType` namespace from OCI spec `s`
  4. func RemoveNamespace(s *specs.Spec, nsType specs.LinuxNamespaceType) {
  5. if s.Linux == nil {
  6. return
  7. }
  8. for i, n := range s.Linux.Namespaces {
  9. if n.Type == nsType {
  10. s.Linux.Namespaces = append(s.Linux.Namespaces[:i], s.Linux.Namespaces[i+1:]...)
  11. return
  12. }
  13. }
  14. }
  15. // NamespacePath returns the configured Path of the first namespace in
  16. // s.Linux.Namespaces of type nsType.
  17. func NamespacePath(s *specs.Spec, nsType specs.LinuxNamespaceType) (path string, ok bool) {
  18. for _, n := range s.Linux.Namespaces {
  19. if n.Type == nsType {
  20. return n.Path, true
  21. }
  22. }
  23. return "", false
  24. }