github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/volume/service/opts/opts.go (about)

     1  package opts
     2  
     3  // CreateOption is used to pass options in when creating a volume
     4  type CreateOption func(*CreateConfig)
     5  
     6  // CreateConfig is the set of config options that can be set when creating
     7  // a volume
     8  type CreateConfig struct {
     9  	Options   map[string]string
    10  	Labels    map[string]string
    11  	Reference string
    12  }
    13  
    14  // WithCreateLabels creates a CreateOption which sets the labels to the
    15  // passed in value
    16  func WithCreateLabels(labels map[string]string) CreateOption {
    17  	return func(cfg *CreateConfig) {
    18  		cfg.Labels = labels
    19  	}
    20  }
    21  
    22  // WithCreateOptions creates a CreateOption which sets the options passed
    23  // to the volume driver when creating a volume to the options passed in.
    24  func WithCreateOptions(opts map[string]string) CreateOption {
    25  	return func(cfg *CreateConfig) {
    26  		cfg.Options = opts
    27  	}
    28  }
    29  
    30  // WithCreateReference creats a CreateOption which sets a reference to use
    31  // when creating a volume. This ensures that the volume is created with a reference
    32  // already attached to it to prevent race conditions with Create and volume cleanup.
    33  func WithCreateReference(ref string) CreateOption {
    34  	return func(cfg *CreateConfig) {
    35  		cfg.Reference = ref
    36  	}
    37  }
    38  
    39  // GetConfig is used with `GetOption` to set options for the volumes service's
    40  // `Get` implementation.
    41  type GetConfig struct {
    42  	Driver        string
    43  	Reference     string
    44  	ResolveStatus bool
    45  }
    46  
    47  // GetOption is passed to the service `Get` add extra details on the get request
    48  type GetOption func(*GetConfig)
    49  
    50  // WithGetDriver provides the driver to get the volume from
    51  // If no driver is provided to `Get`, first the available metadata is checked
    52  // to see which driver it belongs to, if that is not available all drivers are
    53  // probed to find the volume.
    54  func WithGetDriver(name string) GetOption {
    55  	return func(o *GetConfig) {
    56  		o.Driver = name
    57  	}
    58  }
    59  
    60  // WithGetReference indicates to `Get` to increment the reference count for the
    61  // retrieved volume with the provided reference ID.
    62  func WithGetReference(ref string) GetOption {
    63  	return func(o *GetConfig) {
    64  		o.Reference = ref
    65  	}
    66  }
    67  
    68  // WithGetResolveStatus indicates to `Get` to also fetch the volume status.
    69  // This can cause significant overhead in the volume lookup.
    70  func WithGetResolveStatus(cfg *GetConfig) {
    71  	cfg.ResolveStatus = true
    72  }
    73  
    74  // RemoveConfig is used by `RemoveOption` to store config options for remove
    75  type RemoveConfig struct {
    76  	PurgeOnError bool
    77  }
    78  
    79  // RemoveOption is used to pass options to the volumes service `Remove` implementation
    80  type RemoveOption func(*RemoveConfig)
    81  
    82  // WithPurgeOnError is an option passed to `Remove` which will purge all cached
    83  // data about a volume even if there was an error while attempting to remove the
    84  // volume.
    85  func WithPurgeOnError(b bool) RemoveOption {
    86  	return func(o *RemoveConfig) {
    87  		o.PurgeOnError = b
    88  	}
    89  }