k8sclient

package
v0.0.0-...-2c9fce1 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: Apache-2.0 Imports: 33 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// CreatedByAnnotation represents the original Kubernetes `kubernetes.io/created-by` annotation.
	CreatedByAnnotation      = "kubernetes.io/created-by"
	GangSchedulingAnnotation = "firmament-gang-scheduling"
)

Redefine below Annotation key as that is deprecated from original Kubernetes.

Variables

View Source
var BindChannel chan BindInfo
View Source
var NodeMux *sync.RWMutex

NodeMux is used to guard access to the node and resource related maps.

NodeToRTND maps node name to firmament resource topology node descriptor.

View Source
var PodMux *sync.RWMutex

PodMux is used to guard access to the pod, task and job related maps.

View Source
var PodToK8sPod map[PodIdentifier]*v1.Pod
View Source
var PodToK8sPodLock *sync.Mutex

PodToTD maps Kubernetes pod identifier(namespace + name) to firmament task descriptor.

View Source
var ProcessedPodEvents map[PodIdentifier]*v1.Pod // map will have all the pods whose failure/unscheduled events are processed

PodToTD maps Kubernetes pod identifier(namespace + name) to firmament task descriptor.

View Source
var ProcessedPodEventsLock *sync.Mutex
View Source
var ResIDToNode map[string]string

ResIDToNode maps resource ID to node name.

View Source
var TaskIDToPod map[uint64]PodIdentifier

TaskIDToPod maps firmament task ID to Kubernetes pod identifier(namespace + name).

Functions

func BindPodToNode

func BindPodToNode()

BindPodToNode call Kubernetes API to place a pod on a node.

func BindPodWorkers

func BindPodWorkers(stopCh <-chan struct{}, nWorkers int)

Run starts a pod watcher.

func DeletePod

func DeletePod(podName string, namespace string)

DeletePod calls Kubernetes API to delete a Pod by its namespace and name.

func GenerateUUID

func GenerateUUID(seed string) string

GenerateUUID is used to generate a UUID.

func GetAvoidPodsFromNodeAnnotations

func GetAvoidPodsFromNodeAnnotations(annotations map[string]string) ([]*firmament.AvoidPodsAnnotation, error)

func GetClientConfig

func GetClientConfig(kubeconfig string) (*rest.Config, error)

GetClientConfig returns a kubeconfig object which to be passed to a Kubernetes client on initialization.

func GetOwnerReference

func GetOwnerReference(pod *v1.Pod) string

GetOwnerReference to get the parent object reference

func GetOwnersKindandUid

func GetOwnersKindandUid(pod *v1.Pod) (string, string)

GetOwnerReference to get the parent object reference

func GetPodCondition

func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodConditionFromList

func GetPodConditionFromList(conditions []v1.PodCondition, conditionType v1.PodConditionType) (int, *v1.PodCondition)

GetPodConditionFromList extracts the provided condition from the given list of condition and returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.

func HashCombine

func HashCombine(valueOne, valueTwo interface{}) uint64

HashCombine combines two values into a new hash code.

func New

func New(schedulerName string, kubeConfig string, kubeVersionMajor, kubeVersionMinor int, firmamentAddress string)

New initializes a firmament and Kubernetes client and starts watching Pod and Node.

func NodeInfoUpdated

func NodeInfoUpdated() bool

NodeInfoUpdated wait till the nodes info are updated by the node watcher can also be replaces with the wait package poll methods

func SortNodeSelectorsKey

func SortNodeSelectorsKey(nodeSelector NodeSelectors) []string

SortNodeSelectorsKey sort node selectors keys and return an slice of sorted keys.

func Update

func Update(pw kubernetes.Interface, pod *v1.Pod, condition *v1.PodCondition) error

func UpdatePodCondition

func UpdatePodCondition(status *v1.PodStatus, condition *v1.PodCondition) bool

Updates existing pod condition or creates a new one. Sets LastTransitionTime to now if the status has changed. Returns true if pod condition has changed or has been added.

Types

type Affinity

type Affinity struct {
	NodeAffinity    *NodeAffinity
	PodAffinity     *PodAffinity
	PodAntiAffinity *PodAffinity
}

type BindInfo

type BindInfo struct {
	Name      string
	Namespace string
	Nodename  string
}

BindInfo

type K8sPodWatcher

type K8sPodWatcher struct {
	K8sPods map[string]*firmament.TaskInfo
	sync.Mutex
	// contains filtered or unexported fields
}

PodWatcher is a Kubernetes pod watcher.

func NewK8sPodWatcher

func NewK8sPodWatcher(kubeVerMajor, kubeVerMinor int, schedulerName string, client kubernetes.Interface, fc firmament.FirmamentSchedulerClient) *K8sPodWatcher

NewK8sPodWatcher initialize a PodWatcher.

func (*K8sPodWatcher) CheckAndUpdateK8sPodMap

func (pw *K8sPodWatcher) CheckAndUpdateK8sPodMap(taskinfo *firmament.TaskInfo) bool

CheckAndUpdateK8sPodMap will return true if a new object added else will return false

func (*K8sPodWatcher) CheckOpType

func (pw *K8sPodWatcher) CheckOpType(taskinfo *firmament.TaskInfo, optype firmament.TaskInfoType) bool

CheckOpType return true if the optype match

func (*K8sPodWatcher) RemoveTaskfromK8sPodMap

func (pw *K8sPodWatcher) RemoveTaskfromK8sPodMap(taskinfo *firmament.TaskInfo) bool

RemoveTaskfromK8sPodMap return true if remove was successful

type Node

type Node struct {
	Hostname         string
	Phase            NodePhase
	IsReady          bool
	IsOutOfDisk      bool
	CPUCapacity      int64
	CPUAllocatable   int64
	MemCapacityKb    int64
	MemAllocatableKb int64
	EphemeralCapKb   int64
	EphemeralAllocKb int64
	PodAllocatable   int64
	Labels           map[string]string
	Annotations      map[string]string
	Taints           []Taint
}

Node is an internal structure for a Kubernetes node.

type NodeAffinity

type NodeAffinity struct {
	HardScheduling *NodeSelector
	SoftScheduling []PreferredSchedulingTerm
}

type NodePhase

type NodePhase string

NodePhase represents a node phase.

const (
	// NodeAdded represents a node added phase.
	NodeAdded NodePhase = "Added"
	// NodeDeleted represents a node deleted phase.
	NodeDeleted NodePhase = "Deleted"
	// NodeFailed represents a node failed phase.
	NodeFailed NodePhase = "Failed"
	// NodeUpdated represents a node updated phase.
	NodeUpdated NodePhase = "Updated"
)

type NodeSelector

type NodeSelector struct {
	//Required. A list of node selector terms. The terms are ORed.
	NodeSelectorTerms []NodeSelectorTerm
}

type NodeSelectorRequirement

type NodeSelectorRequirement struct {
	Key      string
	Operator string
	Values   []string
}

Node Affinity Struct

type NodeSelectorTerm

type NodeSelectorTerm struct {
	MatchExpressions []NodeSelectorRequirement
}

A null or empty node selector term matches no objects.

type NodeSelectors

type NodeSelectors map[string]string

NodeSelectors stores Kubernetes node selectors.

type NodeWatcher

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

NodeWatcher is a Kubernetes node watcher.

func NewNodeWatcher

NewNodeWatcher initializes a NodeWatcher based on the given Kubernetes client and Firmament client.

func (*NodeWatcher) Run

func (nw *NodeWatcher) Run(stopCh <-chan struct{}, nWorkers int)

Run starts node watcher.

type Pod

type Pod struct {
	Identifier      PodIdentifier
	State           PodPhase
	CPURequest      int64
	MemRequestKb    int64
	EphemeralReqKb  int64
	Labels          map[string]string
	Annotations     map[string]string
	NodeSelector    map[string]string
	OwnerRef        string
	Affinity        *Affinity
	CreateTimeStamp metav1.Time
	Tolerations     []Toleration
	OwnerKind       string
	OwnerUid        string
}

Pod is an internal structure for a Kubernetes pod.

type PodAffinity

type PodAffinity struct {
	HardScheduling []PodAffinityTerm
	SoftScheduling []WeightedPodAffinityTerm
}

type PodAffinityTerm

type PodAffinityTerm struct {
	LabelSelector *metav1.LabelSelector
	Namespaces    []string
	TopologyKey   string
}

type PodEvents

type PodEvents struct {
	Recorder    record.EventRecorder
	BroadCaster record.EventBroadcaster
}

func NewPodEvents

func NewPodEvents(coreEvent kubernetes.Interface) *PodEvents

type PodIdentifier

type PodIdentifier struct {
	Name      string
	Namespace string
}

PodIdentifier is used to identify a pod by its namespace and name.

func (*PodIdentifier) UniqueName

func (this *PodIdentifier) UniqueName() string

UniqueName returns pod namespace/name.

type PodPhase

type PodPhase string

PodPhase represents a pod phase.

const (
	// PodPending is an internal phase used for unscheduled pods.
	PodPending PodPhase = "Pending"
	// PodRunning is an internal phase used for running pods.
	PodRunning PodPhase = "Running"
	// PodSucceeded is an internal phase used for successfully existed pods.
	PodSucceeded PodPhase = "Succeeded"
	// PodFailed is an internal phase used for failed pods.
	PodFailed PodPhase = "Failed"
	// PodUnknown is an internal phase used for state unknown pods.
	PodUnknown PodPhase = "Unknown"
	// PodDeleted is an internal phase used for removed pods.
	PodDeleted PodPhase = "Deleted"
	// PodUpdated is an internal phase for pods that are externally updated.
	PodUpdated PodPhase = "Updated"
)

type PodWatcher

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

PodWatcher is a Kubernetes pod watcher.

func NewPodWatcher

func NewPodWatcher(kubeVerMajor, kubeVerMinor int, schedulerName string, client kubernetes.Interface, fc firmament.FirmamentSchedulerClient) *PodWatcher

NewPodWatcher initialize a PodWatcher.

func (*PodWatcher) GetGangSchedulingReferenceCount

func (pw *PodWatcher) GetGangSchedulingReferenceCount(pod *Pod) int32

GetGangSchedulingReference to get the parent object reference

func (*PodWatcher) Run

func (pw *PodWatcher) Run(stopCh <-chan struct{}, nWorkers int)

Run starts a pod watcher.

type PoseidonEvents

type PoseidonEvents struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewPoseidonEvents

func NewPoseidonEvents(coreEvent kubernetes.Interface) *PoseidonEvents

NewPoseidonEvents singleton Events object create function

func (*PoseidonEvents) ProcessEvents

func (posiedonEvents *PoseidonEvents) ProcessEvents(deltas *firmament.SchedulingDeltas)

func (*PoseidonEvents) ProcessFailureEvents

func (posiedonEvents *PoseidonEvents) ProcessFailureEvents(unscheduledTasks []uint64)

ProcessFailureEvents The failed/unscheduled task events are sent only once

func (*PoseidonEvents) ProcessSuccessEvents

func (posiedonEvents *PoseidonEvents) ProcessSuccessEvents(scheduledTasks []*firmament.SchedulingDelta)

ProcessSuccessEvents send success event to api-server

type PreferredSchedulingTerm

type PreferredSchedulingTerm struct {
	// Weight associated with matching the corresponding nodeSelectorTerm, in the range 1-100.
	Weight int32
	// A node selector term, associated with the corresponding weight.
	Preference NodeSelectorTerm
}

type Queue

type Queue interface {
	// Add enqueues a key and its associated item.
	Add(key interface{}, item interface{})
	// Get removes an item from the queue and inserts the item to the currently processing key set.
	Get() (key interface{}, items []interface{}, shutdown bool)
	// Done removes the item under processing.
	Done(key interface{})
	// ShutDown shuts down the queue.
	ShutDown()
	// ShuttingDown tests if the queue is shutting down.
	ShuttingDown() bool
}

Queue is an interface which abstracts a queue.

type Taint

type Taint struct {
	// Required. The taint key to be applied to a node.
	Key string
	// Required. The taint value corresponding to the taint key.
	// +optional
	Value string
	// Required. The effect of the taint on pods
	// that do not tolerate the taint.
	// Valid effects are NoSchedule, PreferNoSchedule and NoExecute.
	Effect string
}

type Toleration

type Toleration struct {
	// Key is the taint key that the toleration applies to. Empty means match all taint keys.
	// If the key is empty, operator must be Exists; this combination means to match all values and all keys.
	// +optional
	Key string
	// Operator represents a key's relationship to the value.
	// Valid operators are Exists and Equal. Defaults to Equal.
	// Exists is equivalent to wildcard for value, so that a pod can
	// tolerate all taints of a particular category.
	// +optional
	Operator string
	// Value is the taint value the toleration matches to.
	// If the operator is Exists, the value should be empty, otherwise just a regular string.
	// +optional
	Value string
	// Effect indicates the taint effect to match. Empty means match all taint effects.
	// When specified, allowed values are NoSchedule, PreferNoSchedule and NoExecute.
	// +optional
	Effect string
	// TolerationSeconds represents the period of time the toleration (which must be
	// of effect NoExecute, otherwise this field is ignored) tolerates the taint. By default,
	// it is not set, which means tolerate the taint forever (do not evict). Zero and
	// negative values will be treated as 0 (evict immediately) by the system.
	// +optional
	TolerationSeconds *int64
}

The pod this Toleration is attached to tolerates any taint that matches the triple <key,value,effect> using the matching operator <operator>.

type Type

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

Type implements the Queue interface.

func NewKeyedQueue

func NewKeyedQueue() *Type

NewKeyedQueue initializes a queue.

func (*Type) Add

func (q *Type) Add(key interface{}, item interface{})

Add enqueues a key and its associated item.

func (*Type) Done

func (q *Type) Done(key interface{})

Done removes the item under processing and put the queued item into the to-be-processed set.

func (*Type) Get

func (q *Type) Get() (key interface{}, items []interface{}, shutdown bool)

Get removes an item from the queue and inserts the item to the currently processing key set.

func (*Type) ShutDown

func (q *Type) ShutDown()

ShutDown shuts down the queue. After ShutDown is called new items will not be appended to the queue. Only already appended items will be drained.

func (*Type) ShuttingDown

func (q *Type) ShuttingDown() bool

ShuttingDown tests if the queue is shutting down.

type WeightedPodAffinityTerm

type WeightedPodAffinityTerm struct {
	Weight          int32
	PodAffinityTerm PodAffinityTerm
}

Jump to

Keyboard shortcuts

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