kata namespace

Posted dream397

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kata namespace相关的知识,希望对你有一定的参考价值。

 

 

// setupPersistentNs creates persistent namespace without switchin to it.
// Note, pid namespaces cannot be persisted.
func setupPersistentNs(namespaceType nsType) (*namespace, error) {

        err := os.MkdirAll(persistentNsDir, 0755)
        if err != nil {
                return nil, err
        }

        // Create an empty file at the mount point.
        nsPath := filepath.Join(persistentNsDir, string(namespaceType))

        mountFd, err := os.Create(nsPath)
        if err != nil {
                return nil, err
        }
        mountFd.Close()

        var wg sync.WaitGroup
        wg.Add(1)

        go (func() {
                defer wg.Done()
                runtime.LockOSThread()

                var origNsFd *os.File
                origNsPath := getCurrentThreadNSPath(namespaceType)
                origNsFd, err = os.Open(origNsPath)
                if err != nil {
                        return
                }
                defer origNsFd.Close()

                // Create a new netns on the current thread.
                err = unix.Unshare(cloneFlagsTable[namespaceType])
                if err != nil {
                        return
                }

                // Bind mount the new namespace from the current thread onto the mount point to persist it.
                err = unix.Mount(getCurrentThreadNSPath(namespaceType), nsPath, "none", unix.MS_BIND, "")
                if err != nil {
                        return
                }

                // Switch back to original namespace.
                if err = unix.Setns(int(origNsFd.Fd()), cloneFlagsTable[namespaceType]); err != nil {
                        return
                }

        })()
        wg.Wait()

        if err != nil {
                unix.Unmount(nsPath, unix.MNT_DETACH)
                return nil, fmt.Errorf("failed to create namespace: %v", err)
        }

        return &namespace{path: nsPath}, nil
}

 

以上是关于kata namespace的主要内容,如果未能解决你的问题,请参考以下文章

Kata Container — Overview

这个 Java Kata 的更好的函数式解决方案

Kata 架构

认识kata-containers

从kata中学习编程

kata rootfs