kuber

package
v3.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2021 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func GetEntityKey

func GetEntityKey(namespace string, kind string, name string) string

Types

type ContainerResourcesRequirements

type ContainerResourcesRequirements struct {
	Name     string
	Requests *RequestLimit
	Limits   *RequestLimit
}

ContainerResources container resources

type GetWatcherFromKindFunc

type GetWatcherFromKindFunc func(kind string) (Watcher, bool)

type GroupVersionResourceKind

type GroupVersionResourceKind struct {
	schema.GroupVersionResource
	Kind string
}

func KindToGVRK added in v3.4.0

func KindToGVRK(kind string) (*GroupVersionResourceKind, error)

func (GroupVersionResourceKind) String

func (gvrk GroupVersionResourceKind) String() string

type Identifiable

type Identifiable interface {
	GetOwnerReferences() []apisv1.OwnerReference
	GetNamespace() string
	GetKind() string
	GetName() string
	GetAPIVersion() string
}

type Kube

type Kube struct {
	Clientset   *kubernetes.Clientset
	ClientV1    *kapps.AppsV1Client
	ClientBatch *batch.BatchV1beta1Client
	// contains filtered or unexported fields
}

Kube kube struct

func InitKubernetes

func InitKubernetes(config *krest.Config) (*Kube, error)

func (*Kube) GetAgentPermissions

func (kube *Kube) GetAgentPermissions(ctx context.Context) (string, error)

func (*Kube) GetServerMinorVersion

func (kube *Kube) GetServerMinorVersion() (int, error)

func (*Kube) GetServerVersion

func (kube *Kube) GetServerVersion() (string, error)

func (*Kube) UpdateValidatingWebhookCaBundle added in v3.3.1

func (kube *Kube) UpdateValidatingWebhookCaBundle(ctx context.Context, name string, certPem []byte) error

type Observer

type Observer struct {
	dynamicinformer.DynamicSharedInformerFactory
	ParentsStore *ParentsStore
	// contains filtered or unexported fields
}

func NewObserver

func NewObserver(client dynamic.Interface, parentsStore *ParentsStore, stopCh chan struct{}, defaultResync time.Duration) *Observer

func (*Observer) FindContainer

func (observer *Observer) FindContainer(namespaceName string, controllerKind string, controllerName string, containerName string) (*corev1.Container, error)

func (*Observer) FindController

func (observer *Observer) FindController(namespaceName string, controllerKind string, controllerName string) (*unstructured.Unstructured, error)

func (*Observer) FindPodController

func (observer *Observer) FindPodController(namespaceName string, podName string) (string, string, error)

func (*Observer) GetNodes

func (observer *Observer) GetNodes() ([]corev1.Node, error)

func (*Observer) GetPods

func (observer *Observer) GetPods() ([]corev1.Pod, error)

func (*Observer) Start

func (observer *Observer) Start()

func (*Observer) Stop

func (observer *Observer) Stop()

func (*Observer) WaitForCacheSync

func (observer *Observer) WaitForCacheSync() error

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

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

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

type RequestLimit struct {
	CPU    *int64
	Memory *int64
}

RequestLimit request limit

type Resource

type Resource struct {
	Namespace      string
	Name           string
	Kind           string
	Annotations    map[string]string
	ReplicasStatus proto.ReplicasStatus
	Containers     []kv1.Container
	PodRegexp      *regexp.Regexp
}

type ResourceEventHandler

type ResourceEventHandler interface {
	OnAdd(gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
	OnUpdate(gvrk GroupVersionResourceKind, oldObj, newObj unstructured.Unstructured)
	OnDelete(gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
}

type ResourceEventHandlerFuncs

type ResourceEventHandlerFuncs struct {
	Observer   *Observer
	AddFunc    func(gvrk GroupVersionResourceKind, obj unstructured.Unstructured)
	UpdateFunc func(gvrk GroupVersionResourceKind, oldObj, newObj unstructured.Unstructured)
	DeleteFunc func(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

OnAdd calls AddFunc if it's not nil.

func (ResourceEventHandlerFuncs) OnDelete

OnDelete calls DeleteFunc if it's not nil.

func (ResourceEventHandlerFuncs) OnUpdate

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
}

Jump to

Keyboard shortcuts

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