Documentation ¶
Index ¶
- Constants
- Variables
- func GetContainersByNode(pods []corev1.Pod) map[string]int
- func GetEntityKey(namespace string, kind string, name string) string
- func RangePods(pods []corev1.Pod, fn func(corev1.Pod) bool) error
- type Container
- type ContainerResources
- type ContainerResourcesRequirements
- type GetWatcherFromKindFunc
- type GroupVersionResourceKind
- type Identifiable
- type Kube
- func (kube *Kube) GetAgentPermissions() (string, error)
- func (kube *Kube) GetCronJob(namespace, name string) (*kbeta1.CronJob, error)
- func (kube *Kube) GetCronJobs() (*kbeta1.CronJobList, error)
- func (kube *Kube) GetDaemonSet(namespace, name string) (*v1.DaemonSet, error)
- func (kube *Kube) GetDaemonSets() (*appsV1.DaemonSetList, error)
- func (kube *Kube) GetDeployments() (*appsV1.DeploymentList, error)
- func (kube *Kube) GetLimitRanges() (*kv1.LimitRangeList, error)
- func (kube *Kube) GetNameSpacePods(namespace string) (*kv1.PodList, error)
- func (kube *Kube) GetNamespaceReplicaSets(namespace string) (*appsV1.ReplicaSetList, error)
- func (kube *Kube) GetNodes() (*kv1.NodeList, error)
- func (kube *Kube) GetPods() (*kv1.PodList, error)
- func (kube *Kube) GetReplicaSets() (*appsV1.ReplicaSetList, error)
- func (kube *Kube) GetReplicationControllers() (*kv1.ReplicationControllerList, error)
- func (kube *Kube) GetResources() (pods []kv1.Pod, limitRanges []kv1.LimitRange, resources []Resource, ...)
- func (kube *Kube) GetServerMinorVersion() (int, error)
- func (kube *Kube) GetServerVersion() (string, error)
- func (kube *Kube) GetStatefulSet(namespace, name string) (*v1.StatefulSet, error)
- func (kube *Kube) GetStatefulSets() (*appsV1.StatefulSetList, error)
- func (kube *Kube) SetResources(kind string, name string, namespace string, totalResources TotalResources) (skipped bool, err error)
- type Node
- type NodeCapacity
- type Observer
- func (observer *Observer) FindContainer(namespaceName string, controllerKind string, controllerName string, ...) (*corev1.Container, error)
- func (observer *Observer) FindController(namespaceName string, controllerKind string, controllerName string) (*unstructured.Unstructured, error)
- func (observer *Observer) FindPodController(namespaceName string, podName string) (string, string, error)
- func (observer *Observer) GetNodes() ([]corev1.Node, error)
- func (observer *Observer) GetPods() ([]corev1.Pod, error)
- func (observer *Observer) Start()
- func (observer *Observer) Stop()
- func (observer *Observer) WaitForCacheSync() error
- func (observer *Observer) Watch(gvrk GroupVersionResourceKind) *watcher
- func (observer *Observer) WatchAndWaitForSync(gvrk GroupVersionResourceKind) (*watcher, error)
- func (observer *Observer) WatcherFor(gvrk GroupVersionResourceKind) *watcher
- type ParentController
- type ParentsStore
- type RawResources
- type RequestLimit
- type Resource
- type ResourceEventHandler
- type ResourceEventHandlerFuncs
- func (r ResourceEventHandlerFuncs) OnAdd(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
- func (r ResourceEventHandlerFuncs) OnDelete(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
- func (r ResourceEventHandlerFuncs) OnUpdate(now time.Time, gvrk GroupVersionResourceKind, ...)
- type TotalResources
- type Watcher
Constants ¶
const NodeRoleLabelPrefix = "node-role.kubernetes.io/"
Variables ¶
var ( Nodes = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("nodes"), Kind: "Node", } Namespaces = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("namespaces"), Kind: "Namespace", } LimitRanges = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("limitranges"), Kind: "LimitRange", } Pods = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("pods"), Kind: "Pod", } ReplicationControllers = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("replicationcontrollers"), Kind: "ReplicationController", } Deployments = GroupVersionResourceKind{ GroupVersionResource: appsv1.SchemeGroupVersion.WithResource("deployments"), Kind: "Deployment", } StatefulSets = GroupVersionResourceKind{ GroupVersionResource: appsv1.SchemeGroupVersion.WithResource("statefulsets"), Kind: "StatefulSet", } DaemonSets = GroupVersionResourceKind{ GroupVersionResource: appsv1.SchemeGroupVersion.WithResource("daemonsets"), Kind: "DaemonSet", } ReplicaSets = GroupVersionResourceKind{ GroupVersionResource: appsv1.SchemeGroupVersion.WithResource("replicasets"), Kind: "ReplicaSet", } Jobs = GroupVersionResourceKind{ GroupVersionResource: batchv1.SchemeGroupVersion.WithResource("jobs"), Kind: "Job", } CronJobs = GroupVersionResourceKind{ GroupVersionResource: batchv1beta1.SchemeGroupVersion.WithResource("cronjobs"), Kind: "CronJob", } Ingresses = GroupVersionResourceKind{ GroupVersionResource: networkingv1beta1.SchemeGroupVersion.WithResource("ingresses"), Kind: "Ingress", } IngressClasses = GroupVersionResourceKind{ GroupVersionResource: networkingv1beta1.SchemeGroupVersion.WithResource("ingressclasses"), Kind: "IngressClass", } NetworkPolicies = GroupVersionResourceKind{ GroupVersionResource: networkingv1.SchemeGroupVersion.WithResource("networkpolicies"), Kind: "NetworkPolicy", } Services = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("services"), Kind: "Service", } PersistentVolumes = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("persistentvolumes"), Kind: "PersistentVolume", } PersistentVolumeClaims = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("persistentvolumeclaims"), Kind: "PersistentVolumeClaim", } StorageClasses = GroupVersionResourceKind{ GroupVersionResource: storagev1.SchemeGroupVersion.WithResource("storageclasses"), Kind: "StorageClass", } Roles = GroupVersionResourceKind{ GroupVersionResource: rbacv1.SchemeGroupVersion.WithResource("roles"), Kind: "Role", } RoleBindings = GroupVersionResourceKind{ GroupVersionResource: rbacv1.SchemeGroupVersion.WithResource("rolebindings"), Kind: "RoleBinding", } ClusterRoles = GroupVersionResourceKind{ GroupVersionResource: rbacv1.SchemeGroupVersion.WithResource("clusterroles"), Kind: "ClusterRole", } ClusterRoleBindings = GroupVersionResourceKind{ GroupVersionResource: rbacv1.SchemeGroupVersion.WithResource("clusterrolebindings"), Kind: "ClusterRoleBinding", } ServiceAccounts = GroupVersionResourceKind{ GroupVersionResource: corev1.SchemeGroupVersion.WithResource("serviceaccounts"), Kind: "ServiceAccount", } )
Functions ¶
Types ¶
type Container ¶
type Container struct { // cluster where host of container located in Cluster string `json:"cluster,omitempty"` // image of container Image string `json:"image"` // limits of container Limits *ContainerResources `json:"limits,omitempty"` // requests of container Requests *ContainerResources `json:"requests,omitempty"` // name of container (not guaranteed to be unique in cluster scope) Name string `json:"name"` // namespace where pod located in Namespace string `json:"namespace"` // node where container located in Node string `json:"node"` // pod where container located in Pod string `json:"pod"` }
Container user type.
type ContainerResources ¶
ContainerResources user type.
type ContainerResourcesRequirements ¶
type ContainerResourcesRequirements struct { Name string Requests *RequestLimit Limits *RequestLimit }
ContainerResources container resources
type GetWatcherFromKindFunc ¶
type GroupVersionResourceKind ¶
type GroupVersionResourceKind struct { schema.GroupVersionResource Kind string }
func KindToGvrk ¶
func KindToGvrk(kind string) (*GroupVersionResourceKind, error)
TODO: Refactor to a map[kind]GVRK
func (GroupVersionResourceKind) String ¶
func (gvrk GroupVersionResourceKind) String() string
type Identifiable ¶
type Kube ¶
type Kube struct { Clientset *kubernetes.Clientset ClientV1 *kapps.AppsV1Client ClientBatch *batch.BatchV1beta1Client // contains filtered or unexported fields }
Kube kube struct
func (*Kube) GetAgentPermissions ¶ added in v2.8.0
func (*Kube) GetCronJob ¶ added in v2.6.1
GetCronJobs get cron jobs
func (*Kube) GetCronJobs ¶
func (kube *Kube) GetCronJobs() ( *kbeta1.CronJobList, error, )
GetCronJobs get cron jobs
func (*Kube) GetDaemonSet ¶ added in v2.6.1
func (*Kube) GetDaemonSets ¶
func (kube *Kube) GetDaemonSets() ( *appsV1.DaemonSetList, error, )
GetDaemonSets get daemon sets
func (*Kube) GetDeployments ¶
func (kube *Kube) GetDeployments() (*appsV1.DeploymentList, error)
GetDeployments get deployments
func (*Kube) GetLimitRanges ¶
func (kube *Kube) GetLimitRanges() ( *kv1.LimitRangeList, error, )
GetLimitRanges get limits and ranges for namespaces
func (*Kube) GetNameSpacePods ¶ added in v2.6.1
GetPods get kubernetes pods for namespace
func (*Kube) GetNamespaceReplicaSets ¶ added in v2.6.1
func (kube *Kube) GetNamespaceReplicaSets(namespace string) ( *appsV1.ReplicaSetList, error, )
GetReplicaSets get replicasets
func (*Kube) GetReplicaSets ¶
func (kube *Kube) GetReplicaSets() ( *appsV1.ReplicaSetList, error, )
GetReplicaSets get replicasets
func (*Kube) GetReplicationControllers ¶
func (kube *Kube) GetReplicationControllers() ( *kv1.ReplicationControllerList, error, )
GetReplicationControllers get replication controllers
func (*Kube) GetResources ¶
func (*Kube) GetServerMinorVersion ¶ added in v2.8.0
func (*Kube) GetServerVersion ¶ added in v2.6.1
func (*Kube) GetStatefulSet ¶
func (kube *Kube) GetStatefulSet(namespace, name string) ( *v1.StatefulSet, error, )
func (*Kube) GetStatefulSets ¶
func (kube *Kube) GetStatefulSets() ( *appsV1.StatefulSetList, error, )
GetStatefulSets get stateful sets
func (*Kube) SetResources ¶
func (kube *Kube) SetResources( kind string, name string, namespace string, totalResources TotalResources, ) (skipped bool, err error)
SetResources set resources for a service
type Node ¶
type Node struct { ID uuid.UUID `json:"id,omitempty"` Name string `json:"name"` IP string `json:"ip"` Roles string `json:"roles"` KubeletPort int32 `json:"port"` Provider string `json:"provider,omitempty"` Region string `json:"region,omitempty"` InstanceType string `json:"instance_type,omitempty"` InstanceSize string `json:"instance_size,omitempty"` Capacity NodeCapacity `json:"capacity"` Allocatable NodeCapacity `json:"allocatable"` Containers int `json:"containers,omitempty"` ContainerList []*Container `json:"container_list,omitempty"` }
func AddContainerListToNodes ¶
type NodeCapacity ¶
type NodeCapacity struct { CPU int `json:"cpu"` Memory int `json:"memory"` StorageEphemeral int `json:"storage_ephemeral"` Pods int `json:"pods"` }
func GetNodeCapacity ¶
func GetNodeCapacity(resources corev1.ResourceList) NodeCapacity
type Observer ¶
type Observer struct { ParentsStore *ParentsStore // contains filtered or unexported fields }
func NewObserver ¶
func (*Observer) FindContainer ¶ added in v2.9.0
func (*Observer) FindController ¶
func (observer *Observer) FindController( namespaceName string, controllerKind string, controllerName string, ) (*unstructured.Unstructured, error)
func (*Observer) FindPodController ¶ added in v2.9.0
func (*Observer) WaitForCacheSync ¶
func (*Observer) Watch ¶
func (observer *Observer) Watch(gvrk GroupVersionResourceKind) *watcher
func (*Observer) WatchAndWaitForSync ¶
func (observer *Observer) WatchAndWaitForSync(gvrk GroupVersionResourceKind) (*watcher, error)
func (*Observer) WatcherFor ¶
func (observer *Observer) WatcherFor( gvrk GroupVersionResourceKind, ) *watcher
type ParentController ¶
type ParentController struct { Kind string `json:"kind"` Name string `json:"name"` APIVersion string `json:"api_version"` IsWatched bool `json:"is_watched"` Parent *ParentController `json:"parent"` }
func GetParents ¶
func GetParents( obj Identifiable, parentsStore *ParentsStore, getWatcher GetWatcherFromKindFunc, ) (*ParentController, error)
func RootParent ¶
func RootParent(parent *ParentController) *ParentController
type ParentsStore ¶
TODO: Extract into a dependency
func NewParentsStore ¶
func NewParentsStore() *ParentsStore
func (*ParentsStore) Delete ¶
func (s *ParentsStore) Delete(namespace string, kind string, name string)
func (*ParentsStore) GetParents ¶
func (s *ParentsStore) GetParents(namespace string, kind string, name string) (*ParentController, bool)
func (*ParentsStore) SetParents ¶
func (s *ParentsStore) SetParents(namespace string, kind string, name string, parent *ParentController)
type RawResources ¶
type RawResources struct { PodList *kv1.PodList LimitRangeList *kv1.LimitRangeList CronJobList *kbeta1.CronJobList DeploymentList *appsV1.DeploymentList StatefulSetList *appsV1.StatefulSetList DaemonSetList *appsV1.DaemonSetList ReplicaSetList *appsV1.ReplicaSetList }
type RequestLimit ¶
RequestLimit request limit
type ResourceEventHandler ¶
type ResourceEventHandler interface { OnAdd(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured) OnUpdate(now time.Time, gvrk GroupVersionResourceKind, oldObj, newObj unstructured.Unstructured) OnDelete(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured) }
type ResourceEventHandlerFuncs ¶
type ResourceEventHandlerFuncs struct { Observer *Observer AddFunc func(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured) UpdateFunc func(now time.Time, gvrk GroupVersionResourceKind, oldObj, newObj unstructured.Unstructured) DeleteFunc func(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured) }
ResourceEventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing ResourceEventHandler.
func (ResourceEventHandlerFuncs) OnAdd ¶
func (r ResourceEventHandlerFuncs) OnAdd(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
OnAdd calls AddFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnDelete ¶
func (r ResourceEventHandlerFuncs) OnDelete(now time.Time, gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
OnDelete calls DeleteFunc if it's not nil.
func (ResourceEventHandlerFuncs) OnUpdate ¶
func (r ResourceEventHandlerFuncs) OnUpdate(now time.Time, gvrk GroupVersionResourceKind, oldObj, newObj unstructured.Unstructured)
OnUpdate calls UpdateFunc if it's not nil.
type TotalResources ¶
type TotalResources struct {
Containers []ContainerResourcesRequirements
}
TotalResources service resources and replicas
type Watcher ¶
type Watcher interface { GetGroupVersionResourceKind() GroupVersionResourceKind Lister() cache.GenericLister // AddEventHandler adds an event handler to the shared informer using the shared informer's resync // period. Events to a single handler are delivered sequentially, but there is no coordination // between different handlers. AddEventHandler(handler ResourceEventHandler) // AddEventHandlerWithResyncPeriod adds an event handler to the // shared informer using the specified resync period. The resync // operation consists of delivering to the handler a create // notification for every object in the informer's local cache; it // does not add any interactions with the authoritative storage. AddEventHandlerWithResyncPeriod(handler ResourceEventHandler, resyncPeriod time.Duration) // HasSynced returns true if the shared informer's store has been // informed by at least one full LIST of the authoritative state // of the informer's object collection. This is unrelated to "resync". HasSynced() bool // LastSyncResourceVersion is the resource version observed when last synced with the underlying // store. The value returned is not synchronized with access to the underlying store and is not // thread-safe. LastSyncResourceVersion() string }