userconfig

package module
v0.0.0-...-54ff494 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2016 License: Apache-2.0 Imports: 15 Imported by: 1

README

user-config

The datastructures behind the swarm.json format.

Used in the Giant Swarm CLI

Documentation

Overview

TODO this file should be called link.go

Index

Constants

View Source
const (
	GB = SizeUnit("GB")
)

Variables

View Source
var (
	// ByteSizeUnits maps sthg like "kb" to 1000 or "kib" to 1024.
	// Lookup & Keys should be lowercase.
	// See https://en.wikipedia.org/wiki/Kibibyte
	ByteSizeUnits = map[string]uint64{
		"": 1,

		"kb":  1000,
		"k":   1000,
		"kib": 1024,

		"m":   1000 * 1000,
		"mb":  1000 * 1000,
		"mib": 1024 * 1024,

		"g":   1000 * 1000 * 1000,
		"gb":  1000 * 1000 * 1000,
		"gib": 1024 * 1024 * 1024,

		"t":   1000 * 1000 * 1000 * 1000,
		"tb":  1000 * 1000 * 1000 * 1000,
		"tib": 1024 * 1024 * 1024 * 1024,
	}

	UnknownByteSizeUnitError                  = errgo.Newf("Unknown unit provided")
	InvalidByteSizeFormatNoDigitsError        = errgo.Newf("No digits found at beginning of input")
	InvalidByteSizeFormatUnexpectedTokenError = errgo.Newf("Unexpected token")
)
View Source
var (
	UnknownJSONFieldError           = errgo.New("unknown JSON field")
	MissingJSONFieldError           = errgo.New("missing JSON field")
	InvalidSizeError                = errgo.New("invalid size")
	DuplicateVolumePathError        = errgo.New("duplicate volume path")
	InvalidEnvListFormatError       = errgo.Newf("unable to parse 'env', objects or Array of strings expected")
	CrossServicePodError            = errgo.New("pod is used in different services")
	PodUsedOnlyOnceError            = errgo.New("pod is used in only 1 component")
	InvalidVolumeConfigError        = errgo.New("invalid volume configuration")
	InvalidDependencyConfigError    = errgo.New("invalid dependency configuration")
	InvalidScalingConfigError       = errgo.New("invalid scaling configuration")
	InvalidPortConfigError          = errgo.New("Invalid port configuration")
	InvalidDomainDefinitionError    = errgo.New("invalid domain definition")
	InvalidLinkDefinitionError      = errgo.New("invalid link definition")
	InvalidAppDefinitionError       = errgo.New("invalid service definition")
	InvalidComponentDefinitionError = errgo.New("invalid component definition")
	InvalidImageDefinitionError     = errgo.New("invalid image definition")
	InvalidServiceNameError         = errgo.New("invalid service name")
	InvalidComponentNameError       = errgo.New("invalid component name")
	InvalidPodConfigError           = errgo.New("invalid pod configuration")
	PortNotFoundError               = errgo.New("port not found")
	ComponentNotFoundError          = errgo.New("component not found")
	InternalError                   = errgo.New("internal error")
	MissingValidationContextError   = errgo.New("missing validation context")
	InvalidArgumentError            = errgo.New("invalid argument")
	VolumeCycleError                = errgo.New("cycle detected in volume configuration")
	WrongDiffOrderError             = errgo.New("wrong diff order")
	LinkCycleError                  = errgo.New("cycle detected in link definition")
	InvalidMemoryLimitError         = errgo.New("Invalid 'memory-limit' field")
)
View Source
var (
	// StatusOrder is used by AggregateStatus to determine the higher status.
	// Lower Index wins over higher Index
	StatusOrder = []Status{
		STATUS_FAILED,
		STATUS_DOWN,
		STATUS_STARTING,
		STATUS_STOPPING,
		STATUS_UP,
	}
)

Functions

func CheckForUnknownFields

func CheckForUnknownFields(b []byte, ac *ServiceDefinition) error

func FixFieldName

func FixFieldName(s string) string

FixFieldName transforms upper cased strings into underscore ones.

"appName"       => "app_name"
"Services"      => "services"
"ComponentName" => "component_name"

func FixJSONFieldNames

func FixJSONFieldNames(b []byte) ([]byte, error)

FixJSONFieldNames expects an byte array representing a valid JSON string. The given JSON field names will be transformed from upper cased to underscore.

func IsComponentNotFound

func IsComponentNotFound(err error) bool

func IsCrossServicePod

func IsCrossServicePod(err error) bool

func IsDuplicateVolumePath

func IsDuplicateVolumePath(err error) bool

func IsInternal

func IsInternal(err error) bool

func IsInvalidAppDefinition

func IsInvalidAppDefinition(err error) bool

func IsInvalidArgument

func IsInvalidArgument(err error) bool

func IsInvalidByteSizeFormatNoDigits

func IsInvalidByteSizeFormatNoDigits(err error) bool

func IsInvalidByteSizeFormatUnexpectedToken

func IsInvalidByteSizeFormatUnexpectedToken(err error) bool

func IsInvalidComponentDefinition

func IsInvalidComponentDefinition(err error) bool

func IsInvalidComponentName

func IsInvalidComponentName(err error) bool

func IsInvalidDependencyConfig

func IsInvalidDependencyConfig(err error) bool

func IsInvalidDomainDefinition

func IsInvalidDomainDefinition(err error) bool

func IsInvalidEnvListFormat

func IsInvalidEnvListFormat(err error) bool

func IsInvalidImageDefinition

func IsInvalidImageDefinition(err error) bool

func IsInvalidLinkDefinition

func IsInvalidLinkDefinition(err error) bool

func IsInvalidMemoryLimitError

func IsInvalidMemoryLimitError(err error) bool

func IsInvalidPodConfig

func IsInvalidPodConfig(err error) bool

func IsInvalidPortConfig

func IsInvalidPortConfig(err error) bool

func IsInvalidScalingConfig

func IsInvalidScalingConfig(err error) bool

func IsInvalidServiceName

func IsInvalidServiceName(err error) bool

func IsInvalidSize

func IsInvalidSize(err error) bool

func IsInvalidVolumeConfig

func IsInvalidVolumeConfig(err error) bool

IsInvalidVolumeConfig returns true if the given error is of type InvalidVolumeConfigError, VolumeCycleError or DuplicateVolumePathError. False otherwise.

func IsLinkCycle

func IsLinkCycle(err error) bool

func IsMissingJsonField

func IsMissingJsonField(err error) bool

func IsMissingValidationContext

func IsMissingValidationContext(err error) bool

func IsPodUsedOnlyOnce

func IsPodUsedOnlyOnce(err error) bool

func IsPortNotFound

func IsPortNotFound(err error) bool

func IsStatusFinal

func IsStatusFinal(status Status) bool

IsStatusFinal returns whether the given status is a final status and should not change upon itself. E.g. A unit with a status STARTING will after some time either switch to UP or FAILED, thus the state is not final. Final states are UP, DOWN or FAILED.

func IsStatusInactive

func IsStatusInactive(status Status) bool

Inactive means an app is failed or down.

func IsSyntax

func IsSyntax(err error) bool

IsSyntax returns true if the cause of the given error in a json.SyntaxError

func IsUnknownByteSizeUnit

func IsUnknownByteSizeUnit(err error) bool

func IsUnknownJsonField

func IsUnknownJsonField(err error) bool

func IsVolumeCycle

func IsVolumeCycle(err error) bool

func ParseDependency

func ParseDependency(serviceName, dependency string) (string, string)

input: "serviceName", "session", output: "serviceName" "session" input: "serviceName", "session-service/session", output: "session-service" "session"

func ParseServiceName

func ParseServiceName(b []byte) (string, error)

ParseServiceName returns the name of the given definition if it exists. It is does not exist, it generates an service name.

func ScanDigits

func ScanDigits(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanDigits implements bufio.SplitFunc for digits (0-9). Leading whitespaces (unicode.IsSpace) are ignored. May return an empty token, if no digits are found at the beginning.

Types

type ByteSize

type ByteSize string

func (ByteSize) Bytes

func (b ByteSize) Bytes() (uint64, error)

Bytes parses the number of bytes describes by this ByteSize. If the value of b is unparsable, an error is returned. On success, the value in bytes is returend. Example: if the value contains "3 kb", 3000 will be returned.

func (ByteSize) Equals

func (b ByteSize) Equals(other ByteSize) bool

func (ByteSize) IsEmpty

func (b ByteSize) IsEmpty() bool

IsEmpty returns true if the underlying string is empty

func (ByteSize) Parse

func (b ByteSize) Parse() (uint64, string, error)

parse splits b into (uint, unit, error)

func (ByteSize) String

func (b ByteSize) String() string

String returns the string value of this ByteSize as initially provided.

func (ByteSize) Valid

func (b ByteSize) Valid() bool

Valid returns a bool indicating whether this ByteSize value can successfully be parsed.

type ComponentDefinition

type ComponentDefinition struct {
	// Name of a docker image to use when running a container. The image includes
	// tags. E.g. dockerfile/redis:latest.
	Image *ImageDefinition `json:"image,omitempty" description:"Name of a docker image to use when running a container. The image includes tags."`

	// If given, overwrite the entrypoint of the docker image.
	EntryPoint string `json:"entrypoint,omitempty" description:"If given, overwrite the entrypoint of the docker image."`

	// List of ports a service exposes. E.g. 6379/tcp
	Ports PortDefinitions `json:"ports,omitempty" description:"List of ports this service exposes."`

	// Docker env to inject into docker containers.
	Env EnvList `json:"env,omitempty" description:"List of environment variables used by this service."`

	// Docker volumes to inject into docker containers.
	Volumes VolumeDefinitions `json:"volumes,omitempty" description:"List of volumes to attach to this service."`

	// Arguments for processes inside docker containers.
	Args []string `json:"args,omitempty" description:"List of arguments passed to the entry point of this service."`

	// Domains to bind the port to:  domainName => port, e.g. "www.heise.de" => "80"
	Domains V2DomainDefinitions `json:"domains,omitempty" description:"List of domains to bind exposed ports to."`

	// Service names required by a service.
	Links LinkDefinitions `json:"links,omitempty" description:"List of dependencies of this service."`

	Expose ExposeDefinitions `json:"expose,omitempty" description:"List of port mappings to define a stable API."`

	Scale *ScaleDefinition `json:"scale,omitempty" description:"Scaling settings of the component."`

	Pod PodEnum `json:"pod,omitempty" description:"Pod behavior of this component and its children."`

	// If true, user needs to send a signal to indicate that the container is ready is should be considered running.
	SignalReady bool `json:"signal-ready,omitempty" description:"If true, user has to notify when the component is ready."`

	// How much memory to give the container. If empty, the server may decide on a default limit.
	MemoryLimit ByteSize `` /* 134-byte string literal not displayed */

}

ComponentDefinition represents either a runnable service inside a container or a component configuration

func (*ComponentDefinition) IsComponent

func (nd *ComponentDefinition) IsComponent() bool

IsComponent returns true if the component has a defined container image, false otherwise.

func (*ComponentDefinition) IsPodRoot

func (nd *ComponentDefinition) IsPodRoot() bool

IsPodRoot returns true if Pod is set to children or inherit.

type ComponentDefinitions

type ComponentDefinitions map[ComponentName]*ComponentDefinition

func (*ComponentDefinitions) AllDefsPerPod

func (nds *ComponentDefinitions) AllDefsPerPod(names ComponentNames) ([]ComponentDefinitions, error)

AllDefsPerPod tries to group component definitions, based on this rules:

  • group component definitions that share same pod
  • prevent duplicated lists, once a component definition is present in one list, it is not present in other lists.

The resulting maps are sorted such that components that link to other components are found after the component that they link to.

func (*ComponentDefinitions) ChildComponents

func (nds *ComponentDefinitions) ChildComponents(name ComponentName) ComponentDefinitions

ChildComponents returns a map of all components that are a direct child of a component with the given name.

func (*ComponentDefinitions) ChildComponentsRecursive

func (nds *ComponentDefinitions) ChildComponentsRecursive(name ComponentName) ComponentDefinitions

ChildComponentsRecursive returns a list of all components that are a direct child of a component with the given name and all child components of this children (recursive).

func (*ComponentDefinitions) ComponentByName

func (nds *ComponentDefinitions) ComponentByName(name ComponentName) (*ComponentDefinition, error)

func (*ComponentDefinitions) ComponentNames

func (nds *ComponentDefinitions) ComponentNames() ComponentNames

func (*ComponentDefinitions) Contains

func (nds *ComponentDefinitions) Contains(name ComponentName) bool

func (*ComponentDefinitions) FilterComponents

func (nds *ComponentDefinitions) FilterComponents(predicate func(componentName ComponentName, componentDef ComponentDefinition) bool) ComponentDefinitions

FilterComponents returns a set of all my components for which the given predicate returns true.

func (*ComponentDefinitions) IsLeaf

func (nds *ComponentDefinitions) IsLeaf(name ComponentName) bool

IsLeaf returns true if the component with the given name has no children, false otherwise.

func (*ComponentDefinitions) IsPartOfPod

func (nds *ComponentDefinitions) IsPartOfPod(name ComponentName) bool

IsPartOfPod returns true in case the given component is part of a pod, otherwise false.

func (*ComponentDefinitions) IsRoot

func (nds *ComponentDefinitions) IsRoot(name ComponentName) bool

IsRoot returns true if the given component name has no more parent components in this set of components.

func (*ComponentDefinitions) Map

func (*ComponentDefinitions) MountPoints

func (nds *ComponentDefinitions) MountPoints(name ComponentName) ([]string, error)

MountPoints returns a list of all mount points of a component, that is given by name

func (*ComponentDefinitions) ParentOf

ParentOf returns the closest parent of the component with the given name. If there is no such component, a ComponentNotFoundError is returned.

func (*ComponentDefinitions) PodComponents

func (nds *ComponentDefinitions) PodComponents(name ComponentName) (ComponentDefinitions, error)

PodComponents returns a map of all components that are part of the pod specified by a component with the given name.

func (*ComponentDefinitions) PodComponentsRecursive

func (nds *ComponentDefinitions) PodComponentsRecursive(name ComponentName) (ComponentDefinitions, error)

PodComponentsRecursive returns a map of all components that are part of the pod specified by a component with the given name. Other than ComponentDefinitions.PodComponents, this method does at first reverse lookup the pod root.

func (*ComponentDefinitions) PodRoot

PodRoot returns the component that defines the pod the component with given name is a part of. If there is no such component, ComponentNotFoundError is returned.

type ComponentName

type ComponentName string

func (ComponentName) Empty

func (cn ComponentName) Empty() bool

Empty returns true if the given ComponentName is empty, false otherwise.

func (ComponentName) Equals

func (cn ComponentName) Equals(other ComponentName) bool

Equals returns true if the given ComponentName is equal to the other given component name, false otherwise.

func (ComponentName) IsChildOf

func (childName ComponentName) IsChildOf(parentName ComponentName) bool

IsChildOf returns true if the given child name is a child (recursive) of the given parent name. E.g. - "a/b".IsChildOf("a") -> true - "a/b/c".IsChildOf("a") -> true

func (ComponentName) IsDirectChildOf

func (childName ComponentName) IsDirectChildOf(parentName ComponentName) bool

IsDirectChildOf returns true if the given child name is a direct child of the given parent name. E.g. - "a/b".IsDirectChildOf("a") -> true - "a/b/c".IsDirectChildOf("a") -> false

func (ComponentName) IsSiblingOf

func (name ComponentName) IsSiblingOf(otherName ComponentName) bool

IsSiblingOf returns true if the given other name is a sibling of the given name. E.g. - "a/b".IsSiblingOf("a") -> false - "a/c".IsSiblingOf("a/b") -> true - "a/b/c".IsSiblingOf("a/b") -> false

func (ComponentName) LocalName

func (cn ComponentName) LocalName() ComponentName

LocalName returns the last part of the given name.

func (ComponentName) ParentName

func (cn ComponentName) ParentName() (ComponentName, error)

ParentName returns the parent name of the given name, or InvalidArgumentError if the name has no parent.

func (ComponentName) String

func (cn ComponentName) String() string

String returns a string version of the given ComponentName.

func (ComponentName) Validate

func (cn ComponentName) Validate() error

Validate checks that the given ComponentName is a valid ComponentName.

type ComponentNames

type ComponentNames []ComponentName

func (ComponentNames) Contain

func (cns ComponentNames) Contain(name ComponentName) bool

func (ComponentNames) ContainAny

func (cns ComponentNames) ContainAny(names ComponentNames) bool

func (ComponentNames) Filter

func (cns ComponentNames) Filter(names ComponentNames) ComponentNames

func (ComponentNames) ToJSONString

func (cns ComponentNames) ToJSONString() string

NamesToJSONString returns a JSON marshaled string of component names.

func (ComponentNames) Unique

func (cns ComponentNames) Unique() ComponentNames

type DiffInfo

type DiffInfo struct {
	Type DiffType

	Component ComponentName

	Key string
	Old string
	New string
}

type DiffInfos

type DiffInfos []DiffInfo

func ComponentDiff

func ComponentDiff(oldDef, newDef ComponentDefinition, componentName ComponentName) DiffInfos

ComponentDiff checks the difference between two component definitions. The returned list of diff infos can contain the following diff types.

  • DiffTypeComponentImageUpdated
  • DiffTypeComponentEntrypointUpdated
  • DiffTypeComponentPortsUpdated
  • DiffTypeComponentEnvUpdated
  • DiffTypeComponentVolumesUpdated
  • DiffTypeComponentArgsUpdated
  • DiffTypeComponentDomainsUpdated
  • DiffTypeComponentLinksUpdated
  • DiffTypeComponentExposeUpdated
  • DiffTypeComponentScalePlacementUpdated
  • DiffTypeComponentScaleMinUpdated
  • DiffTypeComponentScaleMaxUpdated
  • DiffTypeComponentPodUpdated
  • DiffTypeComponentSignalReadyUpdated
  • DiffTypeComponentMemoryLimitUpdated

func DiffInfosByType

func DiffInfosByType(diffInfos DiffInfos, t DiffType) DiffInfos

DiffInfosByType returns a copied list of diff infos, only containing the given diff type.

func FilterDiffType

func FilterDiffType(diffInfos DiffInfos, diffType DiffType) DiffInfos

FilterDiffType returns a copied list of diff infos, having the given diff type removed.

func ServiceDiff

func ServiceDiff(oldDef, newDef ServiceDefinition) DiffInfos

ServiceDiff checks the difference between two service definitions. The returned list of diff infos can contain the following diff types. For more details check documentation of ComponentDiff.

  • DiffTypeServiceNameUpdated
  • DiffTypeComponentAdded
  • DiffTypeComponentRemoved

func (DiffInfos) ComponentNames

func (dis DiffInfos) ComponentNames() ComponentNames

ComponentNames returns a list of unique component names. Each diff type is expected to have a component name assigned. In case this is not true, this method panics.

type DiffType

type DiffType string
const (
	// DiffTypeServiceNameUpdated
	DiffTypeServiceNameUpdated DiffType = "service-name-updated"

	// DiffTypeComponentAdded
	DiffTypeComponentAdded DiffType = "component-added"

	// DiffTypeComponentRemoved
	DiffTypeComponentRemoved DiffType = "component-removed"

	// DiffTypeComponentImageUpdated
	DiffTypeComponentImageUpdated DiffType = "component-image-updated"

	// DiffTypeComponentEntrypointUpdated
	DiffTypeComponentEntrypointUpdated DiffType = "component-entrypoint-updated"

	// DiffTypeComponentPortsUpdated
	DiffTypeComponentPortsUpdated DiffType = "component-ports-updated"

	// DiffTypeComponentEnvUpdated
	DiffTypeComponentEnvUpdated DiffType = "component-env-updated"

	// DiffTypeComponentVolumesUpdated
	DiffTypeComponentVolumesUpdated DiffType = "component-volumes-updated"

	// DiffTypeComponentArgsUpdated
	DiffTypeComponentArgsUpdated DiffType = "component-args-updated"

	// DiffTypeComponentDomainsUpdated
	DiffTypeComponentDomainsUpdated DiffType = "component-domains-updated"

	// DiffTypeComponentLinksUpdated
	DiffTypeComponentLinksUpdated DiffType = "component-links-updated"

	// DiffTypeComponentExposeUpdated
	DiffTypeComponentExposeUpdated DiffType = "component-expose-updated"

	// DiffTypeComponentScalePlacementUpdated
	DiffTypeComponentScalePlacementUpdated DiffType = "component-scale-placement-updated"

	// DiffTypeComponentScaleMinUpdated
	DiffTypeComponentScaleMinUpdated DiffType = "component-scale-min-updated"

	// DiffTypeComponentScaleMaxUpdated
	DiffTypeComponentScaleMaxUpdated DiffType = "component-scale-max-updated"

	// DiffTypeComponentPodUpdated
	DiffTypeComponentPodUpdated DiffType = "component-pod-updated"

	// DiffTypeComponentSignalReadyUpdated
	DiffTypeComponentSignalReadyUpdated DiffType = "component-signal-ready-updated"

	// DiffTypeComponentMemoryLimitUpdated
	DiffTypeComponentMemoryLimitUpdated DiffType = "component-memory-limit-updated"
)

type EnvList

type EnvList []string

TODO this should be named EnvDefinition List of environment settings like "KEY=VALUE", "KEY2=VALUE2"

func (*EnvList) String

func (eds *EnvList) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two EnvList when creating a diff. See diff.go

func (*EnvList) UnmarshalJSON

func (this *EnvList) UnmarshalJSON(data []byte) error

UnmarshalJSON supports parsing an EnvList as array and as structure

type ExposeDefinition

type ExposeDefinition struct {
	Port       generictypes.DockerPort `json:"port" description:"Port of the stable API."`
	Component  ComponentName           `json:"component,omitempty" description:"Name of the component that implements the stable API."`
	TargetPort generictypes.DockerPort `json:"target_port,omitempty" description:"Port of the given component that implements the stable API."`
}

func (*ExposeDefinition) ImplementationComponentName

func (ed *ExposeDefinition) ImplementationComponentName(containingComponentName ComponentName) ComponentName

ImplementationComponentName returns the name of the component that implements the stable API exposed by this definition.

func (*ExposeDefinition) ImplementationPort

func (ed *ExposeDefinition) ImplementationPort() generictypes.DockerPort

ImplementationPort returns the port on the component that implements the stable API exposed by this definition.

func (*ExposeDefinition) Resolve

func (ed *ExposeDefinition) Resolve(containingComponentName ComponentName, nds ComponentDefinitions) (ComponentName, generictypes.DockerPort, error)

resolve resolves the implementation of the given Expose definition in the context of the given component definitions. Resolve returns the name of the component the implements this expose and its implementation port. If this expose definition cannot be resolved, an error is returned.

func (*ExposeDefinition) String

func (ed *ExposeDefinition) String() string

String returns the string represantion of the current incarnation.

type ExposeDefinitions

type ExposeDefinitions []ExposeDefinition

func (ExposeDefinitions) String

func (eds ExposeDefinitions) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two ExposeDefinitions when creating a diff. See diff.go

type ImageDefinition

type ImageDefinition struct {
	generictypes.DockerImage
}

func MustParseImageDefinition

func MustParseImageDefinition(id string) *ImageDefinition

func (ImageDefinition) GenericDockerImage

func (id ImageDefinition) GenericDockerImage() generictypes.DockerImage

func (ImageDefinition) Validate

func (id ImageDefinition) Validate(valCtx *ValidationContext) error

type LinkDefinition

type LinkDefinition struct {
	Service ServiceName `json:"service,omitempty" description:"Name of the service that is linked to"`

	// Name of a required component
	Component ComponentName `json:"component,omitempty" description:"Name of a component that is linked to"`

	// The name how this dependency should appear in the container
	Alias string `json:"alias,omitempty" description:"The name how this dependency should appear in the container"`

	// Port of the required component
	TargetPort generictypes.DockerPort `json:"target_port" description:"Port on the component that is linked to"`
}

func (LinkDefinition) LinkName

func (ld LinkDefinition) LinkName() (string, error)

LinkName returns the name of this link as it will be used inside the component. This defaults to the alias. If that is not specified, the local name of the Component name will be used, or if that is also empty, the app name.

func (LinkDefinition) LinksToOtherService

func (ld LinkDefinition) LinksToOtherService() bool

LinksToOtherService returns true if this definition defines a link between a component an another service.

func (LinkDefinition) LinksToSameService

func (ld LinkDefinition) LinksToSameService() bool

LinksToSameService returns true if this definition defines a link between a component and another component within the same service.

func (LinkDefinition) Resolve

func (link LinkDefinition) Resolve(nds ComponentDefinitions) (ComponentName, generictypes.DockerPort, error)

Resolve resolves the implementation of the given link in the context of the given component definitions. Resolve returns the name of the component that implements this link and its implementation port. If this link cannot be resolved, an error is returned.

func (LinkDefinition) String

func (ld LinkDefinition) String() string

String returns the string represantion of the current incarnation.

func (LinkDefinition) Validate

func (ld LinkDefinition) Validate(valCtx *ValidationContext) error

type LinkDefinitions

type LinkDefinitions []LinkDefinition

func (LinkDefinitions) String

func (lds LinkDefinitions) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two LinkDefinitions when creating a diff. See diff.go

func (LinkDefinitions) Validate

func (lds LinkDefinitions) Validate(valCtx *ValidationContext) error

type MetaDataConfig

type MetaDataConfig struct {
	Stack string `json:"stack"`
}

type Placement

type Placement string
const (
	DefaultPlacement       Placement = "simple"
	OnePerMachinePlacement Placement = "one-per-machine"
)

func (*Placement) UnmarshalJSON

func (pl *Placement) UnmarshalJSON(data []byte) error

UnmarshalJSON performs a validation during unmarshaling.

func (Placement) Validate

func (pl Placement) Validate() error

Validate checks that the given enum is a valid value.

type PodEnum

type PodEnum string

Type of the "pod" field in a component definition.

const (
	PodNone     PodEnum = "none"     // No pod is created and no resources are shared.
	PodChildren PodEnum = "children" // A component defining this only configures its direct children to be placed into a pod.
	PodInherit  PodEnum = "inherit"  // A component defining this configures all its children and grand-children to be placed into a pod.
)

func (PodEnum) String

func (pe PodEnum) String() string

func (*PodEnum) UnmarshalJSON

func (pe *PodEnum) UnmarshalJSON(data []byte) error

UnmarshalJSON performs a validation during unmarshaling.

func (PodEnum) Validate

func (pe PodEnum) Validate() error

Validate checks that the given enum is a valid value.

type PortDefinitions

type PortDefinitions []generictypes.DockerPort

func (*PortDefinitions) String

func (pds *PortDefinitions) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two PortDefinitions when creating a diff. See diff.go

func (*PortDefinitions) UnmarshalJSON

func (pds *PortDefinitions) UnmarshalJSON(data []byte) error

UnmarshalJSON performs custom unmarshalling to support smart data types.

func (PortDefinitions) Validate

func (pds PortDefinitions) Validate(valCtx *ValidationContext) error

Validate tries to validate the current PortDefinitions. If valCtx is nil, nothing can be validated. The given valCtx must provide at least one protocol, or Validate returns an error. The currently valid one should only be TCP.

type ScaleDefinition

type ScaleDefinition struct {
	// Minimum instances to launch.
	Min int `json:"min,omitempty" description:"Minimum number of instances to launch"`

	// Maximum instances to launch.
	Max int `json:"max,omitempty" description:"Maximum number of instances to launch"`

	Placement Placement `json:"placement,omitempty" description:"Placement strategy when scaling a component. Can be empty or one-per-machine"`
}

func (*ScaleDefinition) String

func (sd *ScaleDefinition) String() string

type ServiceConfig

type ServiceConfig struct {
	MetaData MetaDataConfig `json:"meta_data"`
}

type ServiceDefinition

type ServiceDefinition struct {
	// Optional service name
	ServiceName ServiceName `json:"name,omitempty"`

	// Components
	Components ComponentDefinitions `json:"components"`
}

func ParseServiceDefinition

func ParseServiceDefinition(b []byte) (ServiceDefinition, error)

ParseServiceDefinition tries to parse the v2 service definition.

func (*ServiceDefinition) HideDefaults

func (sd *ServiceDefinition) HideDefaults(valCtx *ValidationContext) (*ServiceDefinition, error)

HideDefaults uses the given validation context to determine what definition details should be hidden. The caller can clean the definition that way to not confuse the user with information he has not set by himself.

func (*ServiceDefinition) Name

func (sd *ServiceDefinition) Name() (string, error)

Name returns the name of the given definition if it exists. It is does not exist, it generates an service name.

func (*ServiceDefinition) SetDefaults

func (sd *ServiceDefinition) SetDefaults(valCtx *ValidationContext) error

SetDefaults sets necessary default values if not given by the user.

func (*ServiceDefinition) UnmarshalJSON

func (sd *ServiceDefinition) UnmarshalJSON(data []byte) error

func (*ServiceDefinition) Validate

func (sd *ServiceDefinition) Validate(valCtx *ValidationContext) error

validate performs semantic validations of this ServiceDefinition. Return the first possible error.

type ServiceName

type ServiceName string

func (ServiceName) Empty

func (an ServiceName) Empty() bool

Empty returns true if the given ServiceName is empty, false otherwise.

func (ServiceName) Equals

func (an ServiceName) Equals(other ServiceName) bool

Equals returns true if the given ServiceName is equal to the other given service name, false otherwise.

func (ServiceName) String

func (an ServiceName) String() string

String returns a string version of the given ServiceName.

func (ServiceName) Validate

func (an ServiceName) Validate() error

Validate checks that the given ServiceName is a valid ServiceName.

type SizeUnit

type SizeUnit string

type Status

type Status string
const (
	STATUS_FAILED   Status = "failed"
	STATUS_DOWN     Status = "down"
	STATUS_STARTING Status = "starting"
	STATUS_UP       Status = "up"
	STATUS_STOPPING Status = "stopping"
)

func AggregateStatus

func AggregateStatus(status1, status2 Status) Status

AggregateStatus returns the 'higher' of the two status, given the following order:

ok < stopping < starting < down < failed

func (*Status) String

func (s *Status) String() string

type V2DomainDefinitions

type V2DomainDefinitions map[generictypes.Domain]PortDefinitions

func (V2DomainDefinitions) MarshalJSON

func (dds V2DomainDefinitions) MarshalJSON() ([]byte, error)

MarshalJSON performs custom marshalling to generate the reverse format: port: domainList

func (V2DomainDefinitions) String

func (dds V2DomainDefinitions) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two V2DomainDefinitions when creating a diff. See diff.go

func (*V2DomainDefinitions) UnmarshalJSON

func (dds *V2DomainDefinitions) UnmarshalJSON(data []byte) error

UnmarshalJSON performs custom unmarshalling to support smart data types.

type ValidationContext

type ValidationContext struct {
	Org       string
	Protocols []string

	MinScaleSize int
	MaxScaleSize int
	Placement    Placement

	MinVolumeSize VolumeSize
	MaxVolumeSize VolumeSize

	EnableUserMemoryLimit bool // If false, the component definition MUST NOT have a memory-limit configured
	MinMemoryLimit        ByteSize
	MaxMemoryLimit        ByteSize

	// RestrictedRegistries contains the registry names, where the validator should throw an error, if the repository
	// namespace does not contain the Org
	RestrictedRegistries []string
}

type VolumeConfig

type VolumeConfig struct {
	// Path of the volume to mount, e.g. "/opt/service/".
	Path string `json:"path,omitempty" description:"Path of the volume to mount (inside the container)`

	// Storage size in GB, e.g. "5 GB".
	Size VolumeSize `json:"size,omitempty" description:"Size of the volume. e.g. '5 GB'"`

	// Name of another component to map all volumes from
	VolumesFrom string `json:"volumes-from,omitempty" description:"Name of another component (in same pod) to share volumes with"`

	// Name of another component to map a specific volumes from
	VolumeFrom string `json:"volume-from,omitempty" description:"Name of another component (in same pod) to share a specific volume with"`

	// Path inside the other component to share
	VolumePath string `json:"volume-path,omitempty" description:"Path in another component to share"`

	// Shared controls whether all instances of the parent component will get the same volume (true) or each gets their own (false). Defaults to false.
	Shared bool `json:"shared,omitempty" description:"Share this volume across all instances"`
}

func (VolumeConfig) String

func (vd VolumeConfig) String() string

func (VolumeConfig) V2Validate

func (vc VolumeConfig) V2Validate(valCtx *ValidationContext) error

type VolumeDefinitions

type VolumeDefinitions []VolumeConfig

func (VolumeDefinitions) Contains

func (vds VolumeDefinitions) Contains(path string) bool

Contains returns true if the volumes contain a volume with the given path, or false otherwise.

func (VolumeDefinitions) Empty

func (vds VolumeDefinitions) Empty() bool

func (VolumeDefinitions) String

func (vds VolumeDefinitions) String() string

String returns the marshalled and ordered string represantion of its own incarnation. It is important to have the string represantion ordered, since we use it to compare two VolumeDefinitions when creating a diff. See diff.go

type VolumeSize

type VolumeSize string

func NewVolumeSize

func NewVolumeSize(size int, unit SizeUnit) VolumeSize

NewVolumeSize creates a new VolumeSize with given parameters

func (VolumeSize) Empty

func (this VolumeSize) Empty() bool

Empty returns true if the given volume size in "empty" (unspecified), false otherwise.

func (VolumeSize) Size

func (this VolumeSize) Size() (int, error)

Size gets the size part of a volume size as an integer. E.g. "5 GB" -> 5

func (VolumeSize) SizeInGB

func (this VolumeSize) SizeInGB() (int, error)

Size gets the size part of a volume size as an integer in GB. E.g. "5 GB" -> 5

func (VolumeSize) Unit

func (this VolumeSize) Unit() (SizeUnit, error)

Size gets the unit part of a volume size. E.g. "5 GB" -> GB

func (*VolumeSize) UnmarshalJSON

func (this *VolumeSize) UnmarshalJSON(data []byte) error

UnmarshalJSON performs a format friendly parsing of volume sizes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL