github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/libcontainerd/remote/client_windows.go (about)

     1  package remote // import "github.com/Prakhar-Agarwal-byte/moby/libcontainerd/remote"
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"path/filepath"
     8  
     9  	"github.com/Microsoft/hcsshim/cmd/containerd-shim-runhcs-v1/options"
    10  	"github.com/containerd/containerd"
    11  	"github.com/containerd/containerd/cio"
    12  	"github.com/containerd/containerd/containers"
    13  	"github.com/containerd/log"
    14  	libcontainerdtypes "github.com/Prakhar-Agarwal-byte/moby/libcontainerd/types"
    15  	specs "github.com/opencontainers/runtime-spec/specs-go"
    16  	"github.com/pkg/errors"
    17  )
    18  
    19  func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) {
    20  	switch pd := i.(type) {
    21  	case *options.ProcessDetails:
    22  		return &libcontainerdtypes.Summary{
    23  			ImageName:                    pd.ImageName,
    24  			CreatedAt:                    pd.CreatedAt,
    25  			KernelTime_100Ns:             pd.KernelTime_100Ns,
    26  			MemoryCommitBytes:            pd.MemoryCommitBytes,
    27  			MemoryWorkingSetPrivateBytes: pd.MemoryWorkingSetPrivateBytes,
    28  			MemoryWorkingSetSharedBytes:  pd.MemoryWorkingSetSharedBytes,
    29  			ProcessID:                    pd.ProcessID,
    30  			UserTime_100Ns:               pd.UserTime_100Ns,
    31  			ExecID:                       pd.ExecID,
    32  		}, nil
    33  	default:
    34  		return nil, errors.Errorf("Unknown process details type %T", pd)
    35  	}
    36  }
    37  
    38  // WithBundle creates the bundle for the container
    39  func WithBundle(bundleDir string, ociSpec *specs.Spec) containerd.NewContainerOpts {
    40  	return func(ctx context.Context, client *containerd.Client, c *containers.Container) error {
    41  		// TODO: (containerd) Determine if we need to use system.MkdirAllWithACL here
    42  		if c.Labels == nil {
    43  			c.Labels = make(map[string]string)
    44  		}
    45  		c.Labels[DockerContainerBundlePath] = bundleDir
    46  		return os.MkdirAll(bundleDir, 0o755)
    47  	}
    48  }
    49  
    50  func withLogLevel(level log.Level) containerd.NewTaskOpts {
    51  	// Make sure we set the runhcs options to debug if we are at debug level.
    52  	return func(_ context.Context, _ *containerd.Client, info *containerd.TaskInfo) error {
    53  		if level == log.DebugLevel {
    54  			info.Options = &options.Options{Debug: true}
    55  		}
    56  		return nil
    57  	}
    58  }
    59  
    60  func pipeName(containerID, processID, name string) string {
    61  	return fmt.Sprintf(`\\.\pipe\containerd-%s-%s-%s`, containerID, processID, name)
    62  }
    63  
    64  func newFIFOSet(bundleDir, processID string, withStdin, withTerminal bool) *cio.FIFOSet {
    65  	containerID := filepath.Base(bundleDir)
    66  	config := cio.Config{
    67  		Terminal: withTerminal,
    68  		Stdout:   pipeName(containerID, processID, "stdout"),
    69  	}
    70  
    71  	if withStdin {
    72  		config.Stdin = pipeName(containerID, processID, "stdin")
    73  	}
    74  
    75  	if !config.Terminal {
    76  		config.Stderr = pipeName(containerID, processID, "stderr")
    77  	}
    78  
    79  	return cio.NewFIFOSet(config, nil)
    80  }
    81  
    82  func (c *client) newDirectIO(ctx context.Context, fifos *cio.FIFOSet) (*cio.DirectIO, error) {
    83  	pipes, err := c.newStdioPipes(fifos)
    84  	if err != nil {
    85  		return nil, err
    86  	}
    87  	return cio.NewDirectIOFromFIFOSet(ctx, pipes.stdin, pipes.stdout, pipes.stderr, fifos), nil
    88  }
    89  
    90  func (t *task) UpdateResources(ctx context.Context, resources *libcontainerdtypes.Resources) error {
    91  	// TODO: (containerd): Not implemented, but don't error.
    92  	return nil
    93  }
    94  
    95  func getSpecUser(ociSpec *specs.Spec) (int, int) {
    96  	// TODO: (containerd): Not implemented, but don't error.
    97  	return 0, 0
    98  }