Documentation ¶
Overview ¶
Package podtask maps Kubernetes pods to Mesos tasks.
Index ¶
- Constants
- func InstallDebugHandlers(reg Registry, mux *http.ServeMux)
- func MakePodKey(ctx api.Context, id string) (string, error)
- func ParsePodStatusResult(taskStatus *mesos.TaskStatus) (result api.PodStatusResult, err error)
- type AllOrNothingProcurement
- type DuplicateHostPortError
- type FlagType
- type HostPortMapper
- type HostPortMapperFunc
- type HostPortMapping
- type Port
- type PortAllocationError
- type ProcureState
- type Procurement
- func NewDefaultProcurement(prototype *mesos.ExecutorInfo, eir executorinfo.Registry) Procurement
- func NewExecutorResourceProcurer(resources []*mesos.Resource, registry executorinfo.Registry) Procurement
- func NewNodeProcurement() Procurement
- func NewPodResourcesProcurement() Procurement
- func NewPortsProcurement() Procurement
- type ProcurementFunc
- type Registry
- type Spec
- type StateType
- type T
- func (t *T) BuildTaskInfo() (*mesos.TaskInfo, error)
- func (t *T) Clone() *T
- func (t *T) GetOfferId() string
- func (t *T) Has(f FlagType) (exists bool)
- func (t *T) HasAcceptedOffer() bool
- func (t *T) Reset()
- func (t *T) Roles() (result []string)
- func (t *T) SaveRecoveryInfo(dict map[string]string)
- func (t *T) Set(f FlagType)
Constants ¶
const ( Launched = FlagType("launched") Bound = FlagType("bound") Deleted = FlagType("deleted") )
const ( // maps a Container.HostPort to the same exact offered host port, ignores .HostPort = 0 HostPortMappingFixed = "fixed" // same as HostPortMappingFixed, except that .HostPort of 0 are mapped to any port offered HostPortMappingWildcard = "wildcard" )
const (
//TODO(jdef) move this somewhere else
PodPath = "/pods"
)
Variables ¶
This section is empty.
Functions ¶
func InstallDebugHandlers ¶
TODO(jdef) we use a Locker to guard against concurrent task state changes, but it would be really, really nice to avoid doing this. Maybe someday the registry won't return data ptrs but plain structs instead.
func MakePodKey ¶
makePodKey constructs etcd paths to pod items enforcing namespace rules.
func ParsePodStatusResult ¶
func ParsePodStatusResult(taskStatus *mesos.TaskStatus) (result api.PodStatusResult, err error)
Types ¶
type AllOrNothingProcurement ¶
type AllOrNothingProcurement []Procurement
AllOrNothingProcurement provides a convenient wrapper around multiple Procurement objectives: the failure of any Procurement in the set results in Procure failing. see AllOrNothingProcurement.Procure
func (AllOrNothingProcurement) Procure ¶
func (a AllOrNothingProcurement) Procure(t *T, n *api.Node, ps *ProcureState) error
Procure runs each Procurement in the receiver list. The first Procurement func that fails triggers T.Reset() and the error is returned, otherwise returns nil.
type DuplicateHostPortError ¶
type DuplicateHostPortError struct {
// contains filtered or unexported fields
}
func (*DuplicateHostPortError) Error ¶
func (err *DuplicateHostPortError) Error() string
type HostPortMapper ¶
type HostPortMapper interface { // Map maps the given pod task and the given mesos offer // and returns a slice of port mappings // or an error if the mapping failed Map(t *T, offer *mesos.Offer) ([]HostPortMapping, error) }
Objects implementing the HostPortMapper interface generate port mappings from k8s container ports to ports offered by mesos
func NewHostPortMapper ¶ added in v0.3.0
func NewHostPortMapper(pod *api.Pod) HostPortMapper
NewHostPortMapper returns a new mapper based based on the port mapping key value
type HostPortMapperFunc ¶ added in v0.3.0
type HostPortMapperFunc func(*T, *mesos.Offer) ([]HostPortMapping, error)
HostPortMapperFunc is a function adapter to the HostPortMapper interface
func (HostPortMapperFunc) Map ¶ added in v0.3.0
func (f HostPortMapperFunc) Map(t *T, offer *mesos.Offer) ([]HostPortMapping, error)
Map calls f(t, offer)
type HostPortMapping ¶
type HostPortMapping struct { ContainerIdx int // index of the container in the pod spec PortIdx int // index of the port in a container's port spec OfferPort uint64 // the port offered by mesos Role string // the role asssociated with the offered port }
A HostPortMapping represents the mapping between k8s container ports ports offered by mesos. It references the k8s' container and port and specifies the offered mesos port and the offered port's role
func FixedMapper ¶ added in v0.3.0
func FixedMapper(t *T, offer *mesos.Offer) ([]HostPortMapping, error)
FixedMapper maps k8s host ports to offered ports ignoring hostPorts == 0 (remaining pod-private)
func WildcardMapper ¶ added in v0.3.0
func WildcardMapper(t *T, offer *mesos.Offer) ([]HostPortMapping, error)
WildcardMapper maps k8s wildcard ports (hostPort == 0) to any available offer port
type PortAllocationError ¶
func (*PortAllocationError) Error ¶
func (err *PortAllocationError) Error() string
type ProcureState ¶ added in v0.3.0
type ProcureState struct {
// contains filtered or unexported fields
}
ProcureState holds the current state of the procurement pipeline. It contains the pod launch specification and the Mesos offer from which resources are being procured.
func NewProcureState ¶ added in v0.3.0
func NewProcureState(offer *mesos.Offer) *ProcureState
NewProcureState returns an ProcureState containing an empty Spec and a deep copy of the given offer.
type Procurement ¶
type Procurement interface {
Procure(*T, *api.Node, *ProcureState) error
}
Procurement is the interface that implements resource procurement.
Procure procurs offered resources for a given pod task T on a given node and stores the procurement result.
Initially the procurement pipe contains an initial empty Spec and the the complete Mesos offer. As the procurement pipeline progresses the specified resources go up as they are being procured while the remaining Mesos offer resources go down until they are depleted.
It returns an error if the procurement failed.
Note that the T struct also includes a Spec field. This differs from the procured Spec which is meant to be filled by a chain of Procure invocations (procurement pipeline).
In contrast T.Spec is meant not to be filled by the procurement chain but rather by a final scheduler instance.
func NewDefaultProcurement ¶
func NewDefaultProcurement(prototype *mesos.ExecutorInfo, eir executorinfo.Registry) Procurement
NewDefaultProcurement returns the default procurement strategy that combines validation and responsible Mesos resource procurement. c and m are resource quantities written into k8s api.Pod.Spec's that don't declare resources (all containers in k8s-mesos require cpu and memory limits).
func NewExecutorResourceProcurer ¶ added in v0.3.0
func NewExecutorResourceProcurer(resources []*mesos.Resource, registry executorinfo.Registry) Procurement
NewExecutorResourceProcurer returns a Procurement procuring executor resources If a given offer has no executor IDs set, the given prototype executor resources are considered for procurement. If a given offer has one executor ID set, only pod resources are being procured. An offer with more than one executor ID implies an invariant violation and the first executor ID is being considered.
func NewNodeProcurement ¶ added in v0.3.0
func NewNodeProcurement() Procurement
NewNodeProcurement returns a Procurement that checks whether the given pod task and offer have valid node informations available and wehther the pod spec node selector matches the pod labels. If the check is successfull the slave ID and assigned slave is set in the given Spec.
func NewPodResourcesProcurement ¶ added in v0.3.0
func NewPodResourcesProcurement() Procurement
NewPodResourcesProcurement converts k8s pod cpu and memory resource requirements into mesos resource allocations.
func NewPortsProcurement ¶ added in v0.3.0
func NewPortsProcurement() Procurement
NewPortsProcurement returns a Procurement procuring ports
type ProcurementFunc ¶ added in v0.3.0
type ProcurementFunc func(*T, *api.Node, *ProcureState) error
The ProcurementFunc type is an adapter to use ordinary functions as Procurement implementations.
func (ProcurementFunc) Procure ¶ added in v0.3.0
func (p ProcurementFunc) Procure(t *T, n *api.Node, ps *ProcureState) error
type Registry ¶
type Registry interface { // register the specified task with this registry, as long as the current error // condition is nil. if no errors occur then return a copy of the registered task. Register(*T) (*T, error) // unregister the specified task from this registry Unregister(*T) // update state for the registered task identified by task.ID, returning a copy of // the updated task, if any. Update(task *T) error // return the task registered for the specified task ID and its current state. // if there is no such task then StateUnknown is returned. Get(taskId string) (task *T, currentState StateType) // return the non-terminal task corresponding to the specified pod ID ForPod(podID string) (task *T, currentState StateType) // update the task status given the specified mesos task status update, returning a // copy of the updated task (if any) and its state. UpdateStatus(status *mesos.TaskStatus) (*T, StateType) // return a list of task ID's that match the given filter, or all task ID's if filter == nil. List(filter func(*T) bool) []*T }
state store for pod tasks
func NewInMemoryRegistry ¶
func NewInMemoryRegistry() Registry
type Spec ¶
type Spec struct { SlaveID string AssignedSlave string Resources []*mesos.Resource PortMap []HostPortMapping Data []byte Executor *mesos.ExecutorInfo }
type T ¶
type T struct { ID string Pod api.Pod // Stores the final procurement result, once set read-only. // Meant to be set by algorith.SchedulerAlgorithm only. Spec *Spec Offer offers.Perishable // thread-safe State StateType Flags map[FlagType]struct{} CreateTime time.Time UpdatedTime time.Time // time of the most recent StatusUpdate we've seen from the mesos master // contains filtered or unexported fields }
A struct that describes a pod task.
func RecoverFrom ¶
reconstruct a task from metadata stashed in a pod entry. there are limited pod states that support reconstruction. if we expect to be able to reconstruct state but encounter errors in the process then those errors are returned. if the pod is in a seemingly valid state but otherwise does not support task reconstruction return false. if we're able to reconstruct state then return a reconstructed task and true.
at this time task reconstruction is only supported for pods that have been annotated with binding metadata, which implies that they've previously been associated with a task and that mesos knows about it.
assumes that the pod data comes from the k8s registry and reflects the desired state.
func (*T) Clone ¶
mostly-clone this pod task. the clone will actually share the some fields:
- executor // OK because it's read only
- Offer // OK because it's guarantees safe concurrent access
func (*T) GetOfferId ¶
func (*T) HasAcceptedOffer ¶
func (*T) Reset ¶
func (t *T) Reset()
Clear offer-related details from the task, should be called if/when an offer has already been assigned to a task but for some reason is no longer valid.
func (*T) Roles ¶ added in v0.3.0
Roles returns the valid roles under which this pod task can be scheduled. If the pod has roles annotations defined they are being used else default pod roles are being returned.