const ( // AllCapabilities is a special value to add or drop all capabilities AllCapabilities = "ALL" // ResetCapabilities is a special value to reset capabilities when updating. // This value should only be used when updating, not used on "create". ResetCapabilities = "RESET" )
func CapabilitiesMap(caps []string) map[string]bool
CapabilitiesMap normalizes the given capabilities and converts them to a map.
func ConvertKVStringsToMap(values []string) map[string]string
ConvertKVStringsToMap converts ["key=value"] to {"key":"value"}
func ConvertKVStringsToMapWithNil(values []string) map[string]*string
ConvertKVStringsToMapWithNil converts ["key=value"] to {"key":"value"} but set unset keys to nil - meaning the ones with no "=" in them. We use this in cases where we need to distinguish between
FOO= and FOO
where the latter case just means FOO was mentioned but not given a value
func ConvertPortToPortConfig( port nat.Port, portBindings map[nat.Port][]nat.PortBinding, ) ([]swarm.PortConfig, error)
ConvertPortToPortConfig converts ports to the swarm type
func EffectiveCapAddCapDrop(add, drop []string) (capAdd, capDrop []string)
EffectiveCapAddCapDrop normalizes and sorts capabilities to "add" and "drop", and returns the effective capabilities to include in both.
"CapAdd" takes precedence over "CapDrop", so capabilities included in both lists are removed from the list of capabilities to drop. The special "ALL" capability is also taken into account.
Note that the special "RESET" value is only used when updating an existing service, and will be ignored.
Duplicates are removed, and the resulting lists are sorted.
func NormalizeCapability(capability string) string
NormalizeCapability normalizes a capability by upper-casing, trimming white space and adding a CAP_ prefix (if not yet present). This function also accepts the "ALL" magic-value, as used by CapAdd/CapDrop.
This function only handles rudimentary formatting; no validation is performed, as the list of available capabilities can be updated over time, thus should be handled by the daemon.
func ParseCPUs(value string) (int64, error)
ParseCPUs takes a string ratio and returns an integer value of nano cpus
func ParseEnvFile(filename string) ([]string, error)
ParseEnvFile reads a file with environment variables enumerated by lines
“Environment variable names used by the utilities in the Shell and Utilities volume of IEEE Std 1003.1-2001 consist solely of uppercase letters, digits, and the '_' (underscore) from the characters defined in Portable Character Set and do not begin with a digit. *But*, other characters may be permitted by an implementation; applications shall tolerate the presence of such names.” -- http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
As of #16585, it's up to application inside docker to validate or not environment variables, that's why we just strip leading whitespace and nothing more.
func ParseHost(defaultToTLS bool, val string) (string, error)
ParseHost and set defaults for a Daemon host string
func ParseLink(val string) (string, string, error)
ParseLink parses and validates the specified string as a link format (name:alias)
func ParseRestartPolicy(policy string) (container.RestartPolicy, error)
ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect
func ParseTCPAddr(tryAddr string, defaultAddr string) (string, error)
ParseTCPAddr parses and validates that the specified address is a valid TCP address. It returns a formatted TCP address, either using the address parsed from tryAddr, or the contents of defaultAddr if tryAddr is a blank string. tryAddr is expected to have already been Trim()'d defaultAddr must be in the full `tcp://host:port` form
func ReadKVEnvStrings(files []string, override []string) ([]string, error)
ReadKVEnvStrings reads a file of line terminated key=value pairs, and overrides any keys present in the file with additional pairs specified in the override parameter. If a key has no value, it will get the value from the environment.
func ReadKVStrings(files []string, override []string) ([]string, error)
ReadKVStrings reads a file of line terminated key=value pairs, and overrides any keys present in the file with additional pairs specified in the override parameter
func ValidateDNSSearch(val string) (string, error)
ValidateDNSSearch validates domain for resolvconf search configuration. A zero length domain is represented by a dot (.).
func ValidateEnv(val string) (string, error)
ValidateEnv validates an environment variable and returns it. If no value is specified, it obtains its value from the current environment
As on ParseEnvFile and related to #16585, environment variable names are not validated, and it's up to the application inside the container to validate them or not.
The only validation here is to check if name is empty, per #25099
func ValidateExtraHost(val string) (string, error)
ValidateExtraHost validates that the specified string is a valid extrahost and returns it. ExtraHost is in the form of name:ip or name=ip, where the ip has to be a valid ip (IPv4 or IPv6). The address may be enclosed in square brackets.
For example:
my-hostname:127.0.0.1 my-hostname:::1 my-hostname=::1 my-hostname:[::1]
For compatibility with the API server, this function normalises the given argument to use the ':' separator and strip square brackets enclosing the address.
func ValidateHost(val string) (string, error)
ValidateHost validates that the specified string is a valid host and returns it.
TODO(thaJeztah): ValidateHost appears to be unused; deprecate it.
func ValidateIPAddress(val string) (string, error)
ValidateIPAddress validates if the given value is a correctly formatted IP address, and returns the value in normalized form. Leading and trailing whitespace is allowed, but it does not allow IPv6 addresses surrounded by square brackets ("[::1]").
Refer to net.ParseIP for accepted formats.
func ValidateLabel(value string) (string, error)
ValidateLabel validates that the specified string is a valid label, and returns it.
Labels are in the form of key=value; key must be a non-empty string, and not contain whitespaces. A value is optional (defaults to an empty string if omitted).
Leading whitespace is removed during validation but values are kept as-is otherwise, so any string value is accepted for both, which includes whitespace (for values) and quotes (surrounding, or embedded in key or value).
TODO discuss if quotes (and other special characters) should be valid or invalid for keys TODO discuss if leading/trailing whitespace in keys should be preserved (and valid)
func ValidateLink(val string) (string, error)
ValidateLink validates that the specified string has a valid link format (containerName:alias).
func ValidateMACAddress(val string) (string, error)
ValidateMACAddress validates a MAC address.
func ValidateSysctl(val string) (string, error)
ValidateSysctl validates a sysctl and returns it.
func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, error)
ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format.
func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, error)
ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format.
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error)
ValidateWeightDevice validates that the specified string has a valid device-weight format.
ConfigOpt is a Value type for parsing configs
type ConfigOpt struct {
// contains filtered or unexported fields
}
func (o *ConfigOpt) Set(value string) error
Set a new config value
func (o *ConfigOpt) String() string
String returns a string repr of this option
func (o *ConfigOpt) Type() string
Type returns the type of this option
func (o *ConfigOpt) Value() []*swarmtypes.ConfigReference
Value returns the config requests
DurationOpt is an option type for time.Duration that uses a pointer. This allows us to get nil values outside, instead of defaulting to 0
type DurationOpt struct {
// contains filtered or unexported fields
}
func NewDurationOpt(value *time.Duration) *DurationOpt
NewDurationOpt creates a DurationOpt with the specified duration
func (d *DurationOpt) Set(s string) error
Set a new value on the option
func (d *DurationOpt) String() string
String returns a string repr of this option
func (d *DurationOpt) Type() string
Type returns the type of this option, which will be displayed in `--help` output
func (d *DurationOpt) Value() *time.Duration
Value returns the time.Duration
ErrBadKey typed error for bad environment variable
type ErrBadKey struct {
// contains filtered or unexported fields
}
func (e ErrBadKey) Error() string
FilterOpt is a flag type for validating filters
type FilterOpt struct {
// contains filtered or unexported fields
}
func NewFilterOpt() FilterOpt
NewFilterOpt returns a new FilterOpt
func (o *FilterOpt) Set(value string) error
Set sets the value of the opt by parsing the command line value
func (o *FilterOpt) String() string
func (o *FilterOpt) Type() string
Type returns the option type
func (o *FilterOpt) Value() filters.Args
Value returns the value of this option
GpuOpts is a Value type for parsing mounts
type GpuOpts struct {
// contains filtered or unexported fields
}
func (o *GpuOpts) Set(value string) error
Set a new mount value
func (o *GpuOpts) String() string
String returns a string repr of this option
func (o *GpuOpts) Type() string
Type returns the type of this option
func (o *GpuOpts) Value() []container.DeviceRequest
Value returns the mounts
ListOpts holds a list of values and a validation function.
type ListOpts struct {
// contains filtered or unexported fields
}
func NewListOpts(validator ValidatorFctType) ListOpts
NewListOpts creates a new ListOpts with the specified validator.
func NewListOptsRef(values *[]string, validator ValidatorFctType) *ListOpts
NewListOptsRef creates a new ListOpts with the specified values and validator.
func (opts *ListOpts) Delete(key string)
Delete removes the specified element from the slice.
func (opts *ListOpts) Get(key string) bool
Get checks the existence of the specified key.
func (opts *ListOpts) GetAll() []string
GetAll returns the values of slice.
func (opts *ListOpts) GetAllOrEmpty() []string
GetAllOrEmpty returns the values of the slice or an empty slice when there are no values.
func (opts *ListOpts) GetMap() map[string]struct{}
GetMap returns the content of values in a map in order to avoid duplicates.
func (opts *ListOpts) Len() int
Len returns the amount of element in the slice.
func (opts *ListOpts) Set(value string) error
Set validates if needed the input value and adds it to the internal slice.
func (opts *ListOpts) String() string
func (opts *ListOpts) Type() string
Type returns a string name for this Option type
func (opts *ListOpts) WithValidator(validator ValidatorFctType) *ListOpts
WithValidator returns the ListOpts with validator set.
MapOpts holds a map of values and a validation function.
type MapOpts struct {
// contains filtered or unexported fields
}
func NewMapOpts(values map[string]string, validator ValidatorFctType) *MapOpts
NewMapOpts creates a new MapOpts with the specified map of values and a validator.
func (opts *MapOpts) GetAll() map[string]string
GetAll returns the values of MapOpts as a map.
func (opts *MapOpts) Set(value string) error
Set validates if needed the input value and add it to the internal map, by splitting on '='.
func (opts *MapOpts) String() string
func (opts *MapOpts) Type() string
Type returns a string name for this Option type
MemBytes is a type for human readable memory bytes (like 128M, 2g, etc)
type MemBytes int64
func (m *MemBytes) Set(value string) error
Set sets the value of the MemBytes by passing a string
func (m *MemBytes) String() string
String returns the string format of the human readable memory bytes
func (m *MemBytes) Type() string
Type returns the type
func (m *MemBytes) UnmarshalJSON(s []byte) error
UnmarshalJSON is the customized unmarshaler for MemBytes
func (m *MemBytes) Value() int64
Value returns the value in int64
MemSwapBytes is a type for human readable memory bytes (like 128M, 2g, etc). It differs from MemBytes in that -1 is valid and the default.
type MemSwapBytes int64
func (m *MemSwapBytes) Set(value string) error
Set sets the value of the MemSwapBytes by passing a string
func (m *MemSwapBytes) String() string
func (m *MemSwapBytes) Type() string
Type returns the type
func (m *MemSwapBytes) UnmarshalJSON(s []byte) error
UnmarshalJSON is the customized unmarshaler for MemSwapBytes
func (m *MemSwapBytes) Value() int64
Value returns the value in int64
MountOpt is a Value type for parsing mounts
type MountOpt struct {
// contains filtered or unexported fields
}
func (m *MountOpt) Set(value string) error
Set a new mount value
func (m *MountOpt) String() string
String returns a string repr of this option
func (m *MountOpt) Type() string
Type returns the type of this option
func (m *MountOpt) Value() []mounttypes.Mount
Value returns the mounts
NamedListOpts is a ListOpts with a configuration name. This struct is useful to keep reference to the assigned field name in the internal configuration struct.
type NamedListOpts struct { ListOpts // contains filtered or unexported fields }
func NewNamedListOptsRef(name string, values *[]string, validator ValidatorFctType) *NamedListOpts
NewNamedListOptsRef creates a reference to a new NamedListOpts struct.
func (o *NamedListOpts) Name() string
Name returns the name of the NamedListOpts in the configuration.
NamedMapOpts is a MapOpts struct with a configuration name. This struct is useful to keep reference to the assigned field name in the internal configuration struct.
type NamedMapOpts struct { MapOpts // contains filtered or unexported fields }
func NewNamedMapOpts(name string, values map[string]string, validator ValidatorFctType) *NamedMapOpts
NewNamedMapOpts creates a reference to a new NamedMapOpts struct.
func (o *NamedMapOpts) Name() string
Name returns the name of the NamedMapOpts in the configuration.
NamedOption is an interface that list and map options with names implement.
type NamedOption interface { Name() string }
NanoCPUs is a type for fixed point fractional number.
type NanoCPUs int64
func (c *NanoCPUs) Set(value string) error
Set sets the value of the NanoCPU by passing a string
func (c *NanoCPUs) String() string
String returns the string format of the number
func (c *NanoCPUs) Type() string
Type returns the type
func (c *NanoCPUs) Value() int64
Value returns the value in int64
NetworkAttachmentOpts represents the network options for endpoint creation
type NetworkAttachmentOpts struct { Target string Aliases []string DriverOpts map[string]string Links []string // TODO add support for links in the csv notation of `--network` IPv4Address string IPv6Address string LinkLocalIPs []string MacAddress string }
NetworkOpt represents a network config in swarm mode.
type NetworkOpt struct {
// contains filtered or unexported fields
}
func (n *NetworkOpt) NetworkMode() string
NetworkMode return the network mode for the network option
func (n *NetworkOpt) Set(value string) error
Set networkopts value
func (n *NetworkOpt) String() string
String returns the network opts as a string
func (n *NetworkOpt) Type() string
Type returns the type of this option
func (n *NetworkOpt) Value() []NetworkAttachmentOpts
Value returns the networkopts
PortOpt represents a port config in swarm mode.
type PortOpt struct {
// contains filtered or unexported fields
}
func (p *PortOpt) Set(value string) error
Set a new port value
func (p *PortOpt) String() string
String returns a string repr of this option
func (p *PortOpt) Type() string
Type returns the type of this option
func (p *PortOpt) Value() []swarm.PortConfig
Value returns the ports
PositiveDurationOpt is an option type for time.Duration that uses a pointer. It behave similarly to DurationOpt but only allows positive duration values.
type PositiveDurationOpt struct { DurationOpt }
func (d *PositiveDurationOpt) Set(s string) error
Set a new value on the option. Setting a negative duration value will cause an error to be returned.
QuotedString is a string that may have extra quotes around the value. The quotes are stripped from the value.
type QuotedString struct {
// contains filtered or unexported fields
}
func NewQuotedString(value *string) *QuotedString
NewQuotedString returns a new quoted string option
func (s *QuotedString) Set(val string) error
Set sets a new value
func (s *QuotedString) String() string
func (s *QuotedString) Type() string
Type returns the type of the value
SecretOpt is a Value type for parsing secrets
type SecretOpt struct {
// contains filtered or unexported fields
}
func (o *SecretOpt) Set(value string) error
Set a new secret value
func (o *SecretOpt) String() string
String returns a string repr of this option
func (o *SecretOpt) Type() string
Type returns the type of this option
func (o *SecretOpt) Value() []*swarmtypes.SecretReference
Value returns the secret requests
ThrottledeviceOpt defines a map of ThrottleDevices
type ThrottledeviceOpt struct {
// contains filtered or unexported fields
}
func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt
NewThrottledeviceOpt creates a new ThrottledeviceOpt
func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice
GetList returns a slice of pointers to ThrottleDevices.
func (opt *ThrottledeviceOpt) Set(val string) error
Set validates a ThrottleDevice and sets its name as a key in ThrottledeviceOpt
func (opt *ThrottledeviceOpt) String() string
String returns ThrottledeviceOpt values as a string.
func (opt *ThrottledeviceOpt) Type() string
Type returns the option type
UlimitOpt defines a map of Ulimits
type UlimitOpt struct {
// contains filtered or unexported fields
}
func NewUlimitOpt(ref *map[string]*units.Ulimit) *UlimitOpt
NewUlimitOpt creates a new UlimitOpt. Ulimits are not validated.
func (o *UlimitOpt) GetList() []*units.Ulimit
GetList returns a slice of pointers to Ulimits. Values are sorted by name.
func (o *UlimitOpt) Set(val string) error
Set validates a Ulimit and sets its name as a key in UlimitOpt
func (o *UlimitOpt) String() string
String returns Ulimit values as a string. Values are sorted by name.
func (o *UlimitOpt) Type() string
Type returns the option type
ValidatorFctListType defines a validator function that returns a validated list of string and/or an error
type ValidatorFctListType func(val string) ([]string, error)
ValidatorFctType defines a validator function that returns a validated string and/or an error.
type ValidatorFctType func(val string) (string, error)
ValidatorThrottleFctType defines a validator function that returns a validated struct and/or an error.
type ValidatorThrottleFctType func(val string) (*blkiodev.ThrottleDevice, error)
ValidatorWeightFctType defines a validator function that returns a validated struct and/or an error.
type ValidatorWeightFctType func(val string) (*blkiodev.WeightDevice, error)
WeightdeviceOpt defines a map of WeightDevices
type WeightdeviceOpt struct {
// contains filtered or unexported fields
}
func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt
NewWeightdeviceOpt creates a new WeightdeviceOpt
func (opt *WeightdeviceOpt) GetList() []*blkiodev.WeightDevice
GetList returns a slice of pointers to WeightDevices.
func (opt *WeightdeviceOpt) Set(val string) error
Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt
func (opt *WeightdeviceOpt) String() string
String returns WeightdeviceOpt values as a string.
func (opt *WeightdeviceOpt) Type() string
Type returns the option type