github.com/containerd/containerd@v22.0.0-20200918172823-438c87b8e050+incompatible/containers/containers.go (about)

     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 containers
    18  
    19  import (
    20  	"context"
    21  	"time"
    22  
    23  	"github.com/gogo/protobuf/types"
    24  )
    25  
    26  // Container represents the set of data pinned by a container. Unless otherwise
    27  // noted, the resources here are considered in use by the container.
    28  //
    29  // The resources specified in this object are used to create tasks from the container.
    30  type Container struct {
    31  	// ID uniquely identifies the container in a namespace.
    32  	//
    33  	// This property is required and cannot be changed after creation.
    34  	ID string
    35  
    36  	// Labels provide metadata extension for a container.
    37  	//
    38  	// These are optional and fully mutable.
    39  	Labels map[string]string
    40  
    41  	// Image specifies the image reference used for a container.
    42  	//
    43  	// This property is optional and mutable.
    44  	Image string
    45  
    46  	// Runtime specifies which runtime should be used when launching container
    47  	// tasks.
    48  	//
    49  	// This property is required and immutable.
    50  	Runtime RuntimeInfo
    51  
    52  	// Spec should carry the runtime specification used to implement the
    53  	// container.
    54  	//
    55  	// This field is required but mutable.
    56  	Spec *types.Any
    57  
    58  	// SnapshotKey specifies the snapshot key to use for the container's root
    59  	// filesystem. When starting a task from this container, a caller should
    60  	// look up the mounts from the snapshot service and include those on the
    61  	// task create request.
    62  	//
    63  	// This field is not required but mutable.
    64  	SnapshotKey string
    65  
    66  	// Snapshotter specifies the snapshotter name used for rootfs
    67  	//
    68  	// This field is not required but immutable.
    69  	Snapshotter string
    70  
    71  	// CreatedAt is the time at which the container was created.
    72  	CreatedAt time.Time
    73  
    74  	// UpdatedAt is the time at which the container was updated.
    75  	UpdatedAt time.Time
    76  
    77  	// Extensions stores client-specified metadata
    78  	Extensions map[string]types.Any
    79  }
    80  
    81  // RuntimeInfo holds runtime specific information
    82  type RuntimeInfo struct {
    83  	Name    string
    84  	Options *types.Any
    85  }
    86  
    87  // Store interacts with the underlying container storage
    88  type Store interface {
    89  	// Get a container using the id.
    90  	//
    91  	// Container object is returned on success. If the id is not known to the
    92  	// store, an error will be returned.
    93  	Get(ctx context.Context, id string) (Container, error)
    94  
    95  	// List returns containers that match one or more of the provided filters.
    96  	List(ctx context.Context, filters ...string) ([]Container, error)
    97  
    98  	// Create a container in the store from the provided container.
    99  	Create(ctx context.Context, container Container) (Container, error)
   100  
   101  	// Update the container with the provided container object. ID must be set.
   102  	//
   103  	// If one or more fieldpaths are provided, only the field corresponding to
   104  	// the fieldpaths will be mutated.
   105  	Update(ctx context.Context, container Container, fieldpaths ...string) (Container, error)
   106  
   107  	// Delete a container using the id.
   108  	//
   109  	// nil will be returned on success. If the container is not known to the
   110  	// store, ErrNotFound will be returned.
   111  	Delete(ctx context.Context, id string) error
   112  }