podtask

package
v1.2.0-alpha.1....-877bfa6 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2015 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package podtask maps Kubernetes pods to Mesos tasks.

Index

Constants

View Source
const (
	Launched = FlagType("launched")
	Bound    = FlagType("bound")
	Deleted  = FlagType("deleted")
)
View Source
const (
	//TODO(jdef) move this somewhere else
	PodPath = "/pods"
)
View Source
const PortMappingLabelKey = "k8s.mesosphere.io/portMapping"

Variables

Functions

func InstallDebugHandlers

func InstallDebugHandlers(reg Registry, mux *http.ServeMux)

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

func MakePodKey(ctx api.Context, id string) (string, error)

makePodKey constructs etcd paths to pod items enforcing namespace rules.

func MinimalPodResourcesPredicate

func MinimalPodResourcesPredicate(t *T, offer *mesos.Offer, _ *api.Node) bool

func MinimalPodResourcesProcurement

func MinimalPodResourcesProcurement(t *T, details *mesos.Offer) error

func NewPodFitsResourcesPredicate

func NewPodFitsResourcesPredicate(c mresource.CPUShares, m mresource.MegaBytes) func(t *T, offer *mesos.Offer, _ *api.Node) bool

func NodeProcurement

func NodeProcurement(t *T, offer *mesos.Offer) error

NodeProcurement updates t.Spec in preparation for the task to be launched on the slave associated with the offer.

func NodeSelectorPredicate

func NodeSelectorPredicate(t *T, offer *mesos.Offer, n *api.Node) bool

func ParsePodStatusResult

func ParsePodStatusResult(taskStatus *mesos.TaskStatus) (result api.PodStatusResult, err error)

func PodResourcesProcurement

func PodResourcesProcurement(t *T, offer *mesos.Offer) error

PodResourcesProcurement converts k8s pod cpu and memory resource requirements into mesos resource allocations.

func PortsPredicate

func PortsPredicate(t *T, offer *mesos.Offer, _ *api.Node) bool

func PortsProcurement

func PortsProcurement(t *T, offer *mesos.Offer) error

PortsProcurement convert host port mappings into mesos port resource allocations.

func ValidateProcurement

func ValidateProcurement(t *T, offer *mesos.Offer) error

ValidateProcurement checks that the offered resources are kosher, and if not panics. If things check out ok, t.Spec is cleared and nil is returned.

func ValidationPredicate

func ValidationPredicate(t *T, offer *mesos.Offer, _ *api.Node) bool

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, offer *mesos.Offer) 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 FitPredicate

type FitPredicate func(*T, *mesos.Offer, *api.Node) bool

FitPredicate implementations determine if the given task "fits" into offered Mesos resources. Neither the task or offer should be modified. Note that the node can be nil.

type FlagType

type FlagType string

type HostPortMapper

type HostPortMapper interface {
	// abstracts the way that host ports are mapped to pod container ports
	Generate(t *T, offer *mesos.Offer) ([]HostPortMapping, error)
}

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
}

type HostPortMappingType

type HostPortMappingType string
const (
	// maps a Container.HostPort to the same exact offered host port, ignores .HostPort = 0
	HostPortMappingFixed HostPortMappingType = "fixed"
	// same as HostPortMappingFixed, except that .HostPort of 0 are mapped to any port offered
	HostPortMappingWildcard = "wildcard"
)

func MappingTypeForPod

func MappingTypeForPod(pod *api.Pod) HostPortMappingType

func (HostPortMappingType) Generate

func (self HostPortMappingType) Generate(t *T, offer *mesos.Offer) ([]HostPortMapping, error)

type PortAllocationError

type PortAllocationError struct {
	PodId string
	Ports []uint64
}

func (*PortAllocationError) Error

func (err *PortAllocationError) Error() string

type Procurement

type Procurement func(*T, *mesos.Offer) error

Procurement funcs allocate resources for a task from an offer. Both the task and/or offer may be modified.

func NewDefaultProcurement

func NewDefaultProcurement(c mresource.CPUShares, m mresource.MegaBytes) 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).

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, error) (*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 RequireAllPredicate

type RequireAllPredicate []FitPredicate

func (RequireAllPredicate) Fit

func (f RequireAllPredicate) Fit(t *T, offer *mesos.Offer, n *api.Node) bool

type RequireSomePodResources

type RequireSomePodResources struct {
	// contains filtered or unexported fields
}

func (*RequireSomePodResources) Procure

func (r *RequireSomePodResources) Procure(t *T, offer *mesos.Offer) error

type Spec

type Spec struct {
	SlaveID       string
	AssignedSlave string
	CPU           mresource.CPUShares
	Memory        mresource.MegaBytes
	PortMap       []HostPortMapping
	Ports         []uint64
	Data          []byte
}

type StateType

type StateType int
const (
	StatePending StateType = iota
	StateRunning
	StateFinished
	StateUnknown
)

type T

type T struct {
	ID          string
	Pod         api.Pod
	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 New

func New(ctx api.Context, id string, pod api.Pod, executor *mesos.ExecutorInfo) (*T, error)

func RecoverFrom

func RecoverFrom(pod api.Pod) (*T, bool, error)

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) BuildTaskInfo

func (t *T) BuildTaskInfo() *mesos.TaskInfo

func (*T) Clone

func (t *T) Clone() *T

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 *T) GetOfferId() string

func (*T) Has

func (t *T) Has(f FlagType) (exists bool)

func (*T) HasAcceptedOffer

func (t *T) HasAcceptedOffer() bool

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) SaveRecoveryInfo

func (t *T) SaveRecoveryInfo(dict map[string]string)

func (*T) Set

func (t *T) Set(f FlagType)

Jump to

Keyboard shortcuts

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