...

Source file src/github.com/containerd/containerd/runtime/task.go

Documentation: github.com/containerd/containerd/runtime

     1  /*
     2     Copyright The containerd Authors.
     3  
     4     Licensed under the Apache License, Version 2.0 (the "License");
     5     you may not use this file except in compliance with the License.
     6     You may obtain a copy of the License at
     7  
     8         http://www.apache.org/licenses/LICENSE-2.0
     9  
    10     Unless required by applicable law or agreed to in writing, software
    11     distributed under the License is distributed on an "AS IS" BASIS,
    12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13     See the License for the specific language governing permissions and
    14     limitations under the License.
    15  */
    16  
    17  package runtime
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	"github.com/containerd/containerd/protobuf/types"
    24  )
    25  
    26  // TaskInfo provides task specific information
    27  type TaskInfo struct {
    28  	ID        string
    29  	Runtime   string
    30  	Spec      []byte
    31  	Namespace string
    32  }
    33  
    34  // Process is a runtime object for an executing process inside a container
    35  type Process interface {
    36  	// ID of the process
    37  	ID() string
    38  	// State returns the process state
    39  	State(ctx context.Context) (State, error)
    40  	// Kill signals a container
    41  	Kill(ctx context.Context, signal uint32, all bool) error
    42  	// ResizePty resizes the processes pty/console
    43  	ResizePty(ctx context.Context, size ConsoleSize) error
    44  	// CloseIO closes the processes IO
    45  	CloseIO(ctx context.Context) error
    46  	// Start the container's user defined process
    47  	Start(ctx context.Context) error
    48  	// Wait for the process to exit
    49  	Wait(ctx context.Context) (*Exit, error)
    50  }
    51  
    52  // ExecProcess is a process spawned in container via Task.Exec call.
    53  // The only difference from a regular `Process` is that exec process can delete self,
    54  // while task process requires slightly more complex logic and needs to be deleted through the task manager.
    55  type ExecProcess interface {
    56  	Process
    57  
    58  	// Delete deletes the process
    59  	Delete(ctx context.Context) (*Exit, error)
    60  }
    61  
    62  // Task is the runtime object for an executing container
    63  type Task interface {
    64  	Process
    65  
    66  	// PID of the process
    67  	PID(ctx context.Context) (uint32, error)
    68  	// Namespace that the task exists in
    69  	Namespace() string
    70  	// Pause pauses the container process
    71  	Pause(ctx context.Context) error
    72  	// Resume unpauses the container process
    73  	Resume(ctx context.Context) error
    74  	// Exec adds a process into the container
    75  	Exec(ctx context.Context, id string, opts ExecOpts) (ExecProcess, error)
    76  	// Pids returns all pids
    77  	Pids(ctx context.Context) ([]ProcessInfo, error)
    78  	// Checkpoint checkpoints a container to an image with live system data
    79  	Checkpoint(ctx context.Context, path string, opts *types.Any) error
    80  	// Update sets the provided resources to a running task
    81  	Update(ctx context.Context, resources *types.Any, annotations map[string]string) error
    82  	// Process returns a process within the task for the provided id
    83  	Process(ctx context.Context, id string) (ExecProcess, error)
    84  	// Stats returns runtime specific metrics for a task
    85  	Stats(ctx context.Context) (*types.Any, error)
    86  }
    87  
    88  // ExecOpts provides additional options for additional processes running in a task
    89  type ExecOpts struct {
    90  	Spec *types.Any
    91  	IO   IO
    92  }
    93  
    94  // ConsoleSize of a pty or windows terminal
    95  type ConsoleSize struct {
    96  	Width  uint32
    97  	Height uint32
    98  }
    99  
   100  // Status is the runtime status of a task and/or process
   101  type Status int
   102  
   103  const (
   104  	// CreatedStatus when a process has been created
   105  	CreatedStatus Status = iota + 1
   106  	// RunningStatus when a process is running
   107  	RunningStatus
   108  	// StoppedStatus when a process has stopped
   109  	StoppedStatus
   110  	// DeletedStatus when a process has been deleted
   111  	DeletedStatus
   112  	// PausedStatus when a process is paused
   113  	PausedStatus
   114  	// PausingStatus when a process is currently pausing
   115  	PausingStatus
   116  )
   117  
   118  // State information for a process
   119  type State struct {
   120  	// Status is the current status of the container
   121  	Status Status
   122  	// Pid is the main process id for the container
   123  	Pid uint32
   124  	// ExitStatus of the process
   125  	// Only valid if the Status is Stopped
   126  	ExitStatus uint32
   127  	// ExitedAt is the time at which the process exited
   128  	// Only valid if the Status is Stopped
   129  	ExitedAt time.Time
   130  	Stdin    string
   131  	Stdout   string
   132  	Stderr   string
   133  	Terminal bool
   134  }
   135  
   136  // ProcessInfo holds platform specific process information
   137  type ProcessInfo struct {
   138  	// Pid is the process ID
   139  	Pid uint32
   140  	// Info includes additional process information
   141  	// Info varies by platform
   142  	Info interface{}
   143  }
   144  

View as plain text