util

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// GlobalLabel make object global
	GlobalLabel = "global"
	// SelectorKey is the key of ClusterSelector
	SelectorKey = "clusterSelector"
	// SelectedNodeKey is the node selected by a scheduler
	SelectedNodeKey = "volume.kubernetes.io/selected-node"
	// HostNameKey is the label of HostNameKey
	HostNameKey = "kubernetes.io/hostname"
	// BetaHostNameKey is the label of HostNameKey
	BetaHostNameKey = "beta.kubernetes.io/hostname"
	// LabelOSBeta is the label of os
	LabelOSBeta = "beta.kubernetes.io/os"
	// VirtualPodLabel is the label of virtual pod
	VirtualPodLabel = "virtual-pod"
	// VirtualKubeletLabel is the label of virtual kubelet
	VirtualKubeletLabel = "virtual-kubelet"
	// TrippedLabels is the label of tripped labels
	TrippedLabels = "tripped-labels"
	// ClusterID marks the id of a cluster
	ClusterID = "clusterID"
	// NodeType is define the node type key
	NodeType = "type"
	// BatchPodLabel is the label of batch pod
	BatchPodLabel = "pod-group.scheduling.sigs.k8s.io"
	// TaintNodeNotReady will be added when node is not ready
	// and feature-gate for TaintBasedEvictions flag is enabled,
	// and removed when node becomes ready.
	TaintNodeNotReady = "node.kubernetes.io/not-ready"

	// TaintNodeUnreachable will be added when node becomes unreachable
	// (corresponding to NodeReady status ConditionUnknown)
	// and feature-gate for TaintBasedEvictions flag is enabled,
	// and removed when node becomes reachable (NodeReady status ConditionTrue).
	TaintNodeUnreachable = "node.kubernetes.io/unreachable"
	// CreatedbyDescheduler is used to mark if a pod is re-created by descheduler
	CreatedbyDescheduler = "create-by-descheduler"
	// DescheduleCount is used for recording deschedule count
	DescheduleCount = "sigs.k8s.io/deschedule-count"
)

Variables

This section is empty.

Functions

func CreateJSONPatch

func CreateJSONPatch(original, new interface{}) ([]byte, error)

CreateJSONPatch return patch generated from original and new interfaces

func CreateMergePatch

func CreateMergePatch(original, new interface{}) ([]byte, error)

CreateMergePatch return patch generated from original and new interfaces

func GetClusterID

func GetClusterID(node *corev1.Node) string

GetClusterID return the cluster in node label

func GetRequestFromPod

func GetRequestFromPod(pod *corev1.Pod) *common.Resource

GetRequestFromPod get resources required by pod

func GetUpdatedPod

func GetUpdatedPod(orig, update *corev1.Pod, ignoreLabels []string)

GetUpdatedPod allows user to update image, label, annotations for tolerations, we can only add some more.

func IsVirtualNode

func IsVirtualNode(node *corev1.Node) bool

IsVirtualNode defines if a node is virtual node

func IsVirtualPod

func IsVirtualPod(pod *corev1.Pod) bool

IsVirtualPod defines if a pod is virtual pod

func NewClient

func NewClient(configPath string, opts ...Opts) (kubernetes.Interface, error)

NewClient returns a new client for k8s

func NewMetricClient

func NewMetricClient(configPath string, opts ...Opts) (versioned.Interface, error)

NewMetricClient returns a new client for k8s

func RecoverLabels

func RecoverLabels(labels map[string]string, annotations map[string]string)

RecoverLabels recover some label that have been removed

func ReplacePodNodeNameNodeAffinity

func ReplacePodNodeNameNodeAffinity(affinity *corev1.Affinity, ownerID string, expireTime time.Duration,
	checkFuc CheckValidFunc, nodeNames ...string) (*corev1.Affinity,
	int)

ReplacePodNodeNameNodeAffinity replaces the RequiredDuringSchedulingIgnoredDuringExecution NodeAffinity of the given affinity with a new NodeAffinity that selects the given nodeName. Note that this function assumes that no NodeAffinity conflicts with the selected nodeName.

func SetupSignalHandler

func SetupSignalHandler() <-chan struct{}

SetupSignalHandler registered for SIGTERM and SIGINT. A stop channel is returned which is closed on one of these signals. If a second signal is caught, the program is terminated with exit code 1.

func TrimObjectMeta

func TrimObjectMeta(meta *metav1.ObjectMeta)

TrimObjectMeta removes some fields of ObjectMeta

func TrimPod

func TrimPod(pod *corev1.Pod, ignoreLabels []string) *corev1.Pod

TrimPod filter some fields that should not be contained when created in subClusters for example: ownerReference, serviceLink and Uid we should also add some fields back for scheduling.

func UpdateConfigMap

func UpdateConfigMap(old, new *corev1.ConfigMap)

UpdateConfigMap updates the configMap data

func UpdateSecret

func UpdateSecret(old, new *corev1.Secret)

UpdateSecret updates the secret data

Types

type CheckValidFunc

type CheckValidFunc func(string, string, time.Duration) bool

CheckValidFunc defines the check func

type ClustersNodeSelection

type ClustersNodeSelection struct {
	NodeSelector map[string]string   `json:"nodeSelector,omitempty"`
	Affinity     *corev1.Affinity    `json:"affinity,omitempty"`
	Tolerations  []corev1.Toleration `json:"tolerations,omitempty"`
}

ClustersNodeSelection is a struct including some scheduling parameters

func ConvertAnnotations

func ConvertAnnotations(annotation map[string]string) *ClustersNodeSelection

ConvertAnnotations converts annotations to ClustersNodeSelection

type Opts

type Opts func(*rest.Config)

Opts define the ops parameter functions

type UnschedulableCache

type UnschedulableCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

UnschedulableCache contaiens cache ownerid/node/freezeTime

func NewUnschedulableCache

func NewUnschedulableCache() *UnschedulableCache

NewUnschedulableCache init a new Unschedulable

func (*UnschedulableCache) Add

func (c *UnschedulableCache) Add(node, ownerID string)

Add add node/ownerID to cache

func (*UnschedulableCache) GetFreezeNodes

func (c *UnschedulableCache) GetFreezeNodes(ownerID string) []string

GetFreezeNodes return the freezed nodes

func (*UnschedulableCache) GetFreezeTime

func (c *UnschedulableCache) GetFreezeTime(node, ownerID string) *time.Time

GetFreezeTime returns node/ownerID freeze time

Jump to

Keyboard shortcuts

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