core

package
v1.20.4-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 31 Imported by: 145

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetInstance

func SetInstance(i Ops)

SetInstance replaces the instance with the provided one. Should be used only for testing purposes.

Types

type Client

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

Client is a wrapper for kubernetes core client.

func New

func New(kubernetes kubernetes.Interface) *Client

New builds a new client.

func NewForConfig

func NewForConfig(c *rest.Config) (*Client, error)

NewForConfig builds a new client for the given config.

func (*Client) AddLabelOnNode

func (c *Client) AddLabelOnNode(name, key, value string) error

AddLabelOnNode adds a label key=value on the given node

func (*Client) CordonNode

func (c *Client) CordonNode(nodeName string, timeout, retryInterval time.Duration) error

CordonNode cordons the given node

func (*Client) CreateConfigMap

func (c *Client) CreateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)

CreateConfigMap creates a new config map object if it does not already exist.

func (*Client) CreateEndpoints

func (c *Client) CreateEndpoints(endpoints *corev1.Endpoints) (*corev1.Endpoints, error)

CreateEndpoints creates a given endpoints.

func (*Client) CreateEvent

func (c *Client) CreateEvent(event *corev1.Event) (*corev1.Event, error)

CreateEvent puts an event into k8s etcd

func (*Client) CreateLimitRange

func (c *Client) CreateLimitRange(limitrange *corev1.LimitRange) (*corev1.LimitRange, error)

CreateLimitRange creates the given limitrange

func (*Client) CreateNamespace

func (c *Client) CreateNamespace(namespace *corev1.Namespace) (*corev1.Namespace, error)

CreateNamespace creates a namespace with given name and metadata

func (*Client) CreateNode

func (c *Client) CreateNode(n *corev1.Node) (*corev1.Node, error)

CreateNode creates the given node

func (*Client) CreatePersistentVolume

func (c *Client) CreatePersistentVolume(pv *corev1.PersistentVolume) (*corev1.PersistentVolume, error)

CreatePersistentVolume creates the given PV

func (*Client) CreatePersistentVolumeClaim

func (c *Client) CreatePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)

CreatePersistentVolumeClaim creates the given persistent volume claim

func (*Client) CreatePod

func (c *Client) CreatePod(pod *corev1.Pod) (*corev1.Pod, error)

CreatePod creates the given pod.

func (*Client) CreateSecret

func (c *Client) CreateSecret(secret *corev1.Secret) (*corev1.Secret, error)

CreateSecret creates the given secret

func (*Client) CreateService

func (c *Client) CreateService(service *corev1.Service) (*corev1.Service, error)

CreateService creates the given service

func (*Client) CreateServiceAccount

func (c *Client) CreateServiceAccount(account *corev1.ServiceAccount) (*corev1.ServiceAccount, error)

CreateServiceAccount creates the given service account

func (*Client) DeleteConfigMap

func (c *Client) DeleteConfigMap(name, namespace string) error

DeleteConfigMap deletes the given config map

func (*Client) DeleteEndpoints

func (c *Client) DeleteEndpoints(name, ns string) error

DeleteEndpoints retrieves endpoints for a given namespace/name.

func (*Client) DeleteLimitRange

func (c *Client) DeleteLimitRange(name, namespace string) error

DeleteLimitRange deletes the given limitrange

func (*Client) DeleteNamespace

func (c *Client) DeleteNamespace(name string) error

DeleteNamespace deletes a namespace with given name

func (*Client) DeleteNode

func (c *Client) DeleteNode(name string) error

DeleteNode deletes a node

func (*Client) DeletePersistentVolume

func (c *Client) DeletePersistentVolume(pvName string) error

DeletePersistentVolume deletes the PV for given name

func (*Client) DeletePersistentVolumeClaim

func (c *Client) DeletePersistentVolumeClaim(name, namespace string) error

DeletePersistentVolumeClaim deletes the given persistent volume claim

func (*Client) DeletePod

func (c *Client) DeletePod(name string, ns string, force bool) error

DeletePod deletes the given pod

func (*Client) DeletePods

func (c *Client) DeletePods(pods []corev1.Pod, force bool) error

DeletePods deletes the given pods

func (*Client) DeleteSecret

func (c *Client) DeleteSecret(name, namespace string) error

DeleteSecret deletes the given secret

func (*Client) DeleteService

func (c *Client) DeleteService(name, namespace string) error

DeleteService deletes the given service

func (*Client) DeleteServiceAccount

func (c *Client) DeleteServiceAccount(accountName, namespace string) error

DeleteServiceAccount deletes the given service account

func (*Client) DescribeService

func (c *Client) DescribeService(svcName string, svcNamespace string) (*corev1.ServiceStatus, error)

DescribeService gets the service status

func (*Client) DrainPodsFromNode

func (c *Client) DrainPodsFromNode(nodeName string, pods []corev1.Pod, timeout time.Duration, retryInterval time.Duration) error

DrainPodsFromNode drains given pods from given node. If timeout is set to a non-zero value, it waits for timeout duration for each pod to get deleted

func (*Client) FindMyNode

func (c *Client) FindMyNode() (*corev1.Node, error)

FindMyNode finds LOCAL Node in Kubernetes cluster.

func (*Client) GetConfigMap

func (c *Client) GetConfigMap(name string, namespace string) (*corev1.ConfigMap, error)

GetConfigMap gets the config map object for the given name and namespace

func (*Client) GetEndpoints

func (c *Client) GetEndpoints(name, ns string) (*corev1.Endpoints, error)

GetEndpoints retrieves endpoints for a given namespace/name.

func (*Client) GetLabelsOnNode

func (c *Client) GetLabelsOnNode(name string) (map[string]string, error)

GetLabelsOnNode gets all the labels on the given node

func (*Client) GetLimitRange

func (c *Client) GetLimitRange(name string, namespace string) (*corev1.LimitRange, error)

GetLimitRange gets the limitranges object given its name and namespace

func (*Client) GetNamespace

func (c *Client) GetNamespace(name string) (*corev1.Namespace, error)

GetNamespace returns a namespace object for given name

func (*Client) GetNodeByName

func (c *Client) GetNodeByName(name string) (*corev1.Node, error)

GetNodeByName returns the k8s node given it's name

func (*Client) GetNodes

func (c *Client) GetNodes() (*corev1.NodeList, error)

GetNodes talks to the k8s api server and gets the nodes in the cluster

func (*Client) GetPVCsUsingStorageClass

func (c *Client) GetPVCsUsingStorageClass(scName string) ([]corev1.PersistentVolumeClaim, error)

GetPVCsUsingStorageClass returns all PVCs that use the given storage class

func (*Client) GetPersistentVolume

func (c *Client) GetPersistentVolume(pvName string) (*corev1.PersistentVolume, error)

GetPersistentVolume returns the PV for given name

func (*Client) GetPersistentVolumeClaim

func (c *Client) GetPersistentVolumeClaim(pvcName string, namespace string) (*corev1.PersistentVolumeClaim, error)

GetPersistentVolumeClaim returns the PVC for given name and namespace

func (*Client) GetPersistentVolumeClaimParams

func (c *Client) GetPersistentVolumeClaimParams(pvc *corev1.PersistentVolumeClaim) (map[string]string, error)

GetPersistentVolumeClaimParams fetches custom parameters for the given PVC

func (*Client) GetPersistentVolumeClaimStatus

func (c *Client) GetPersistentVolumeClaimStatus(pvc *corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaimStatus, error)

GetPersistentVolumeClaimStatus returns the status of the given pvc

func (*Client) GetPersistentVolumeClaims

func (c *Client) GetPersistentVolumeClaims(namespace string, labelSelector map[string]string) (*corev1.PersistentVolumeClaimList, error)

GetPersistentVolumeClaims returns all PVCs in given namespace and that match the optional labelSelector

func (*Client) GetPersistentVolumes

func (c *Client) GetPersistentVolumes() (*corev1.PersistentVolumeList, error)

GetPersistentVolumes returns all PVs in cluster

func (*Client) GetPodByName

func (c *Client) GetPodByName(podName string, namespace string) (*corev1.Pod, error)

GetPodByName returns pod for the given pod name and namespace

func (*Client) GetPodByUID

func (c *Client) GetPodByUID(uid types.UID, namespace string) (*corev1.Pod, error)

GetPodByUID returns pod with the given UID, or error if nothing found

func (*Client) GetPods

func (c *Client) GetPods(namespace string, labelSelector map[string]string) (*corev1.PodList, error)

GetPods returns pods for the given namespace

func (*Client) GetPodsByNode

func (c *Client) GetPodsByNode(nodeName, namespace string) (*corev1.PodList, error)

GetPodsByNode returns all pods in given namespace and given k8s node name.

If namespace is empty, it will return pods from all namespaces

func (*Client) GetPodsByNodeAndLabels

func (c *Client) GetPodsByNodeAndLabels(nodeName, namespace string, labels map[string]string) (*corev1.PodList, error)

GetPodsByNodeAndLabels returns all pods in given namespace and given k8s node name for the given labels

If namespace is empty, it will return pods from all namespaces

func (*Client) GetPodsByOwner

func (c *Client) GetPodsByOwner(ownerUID types.UID, namespace string) ([]corev1.Pod, error)

GetPodsByOwner returns pods for the given owner and namespace

func (*Client) GetPodsUsingPV

func (c *Client) GetPodsUsingPV(pvName string) ([]corev1.Pod, error)

GetPodsUsingPV returns all pods in cluster using given pv

func (*Client) GetPodsUsingPVByNodeName

func (c *Client) GetPodsUsingPVByNodeName(pvName, nodeName string) ([]corev1.Pod, error)

GetPodsUsingPVByNodeName returns all pods running on the node using the given pv

func (*Client) GetPodsUsingPVC

func (c *Client) GetPodsUsingPVC(pvcName, pvcNamespace string) ([]corev1.Pod, error)

GetPodsUsingPVC returns all pods in cluster using given pvc

func (*Client) GetPodsUsingPVCByNodeName

func (c *Client) GetPodsUsingPVCByNodeName(pvcName, pvcNamespace, nodeName string) ([]corev1.Pod, error)

GetPodsUsingPVCByNodeName returns all pods running on the node using given pvc

func (*Client) GetPodsUsingVolumePlugin

func (c *Client) GetPodsUsingVolumePlugin(plugin string) ([]corev1.Pod, error)

GetPodsUsingVolumePlugin returns all pods who use PVCs provided by the given volume plugin

func (*Client) GetPodsUsingVolumePluginByNodeName

func (c *Client) GetPodsUsingVolumePluginByNodeName(nodeName, plugin string) ([]corev1.Pod, error)

GetPodsUsingVolumePluginByNodeName returns all pods who use PVCs provided by the given volume plugin on the given node

func (*Client) GetSecret

func (c *Client) GetSecret(name string, namespace string) (*corev1.Secret, error)

GetSecret gets the secrets object given its name and namespace

func (*Client) GetService

func (c *Client) GetService(svcName string, svcNS string) (*corev1.Service, error)

GetService gets the service by the name

func (*Client) GetServiceAccount

func (c *Client) GetServiceAccount(name, namespace string) (*corev1.ServiceAccount, error)

GetServiceAccount gets the given service account

func (*Client) GetServiceEndpoint

func (c *Client) GetServiceEndpoint(svcName, namespace string) (string, error)

GetServiceEndpoint gets the externalIP if service is a LoadBalancer or ClusterIP otherwise

func (*Client) GetStorageClassForPVC

func (c *Client) GetStorageClassForPVC(pvc *corev1.PersistentVolumeClaim) (*storagev1.StorageClass, error)

GetStorageClassForPVC returns the appropriate storage class object for a certain pvc

func (*Client) GetStorageProvisionerForPVC

func (c *Client) GetStorageProvisionerForPVC(pvc *corev1.PersistentVolumeClaim) (string, error)

GetStorageProvisionerForPVC returns storage provisioner for given PVC if it exists

func (*Client) GetVersion

func (c *Client) GetVersion() (*version.Info, error)

GetVersion returns server version

func (*Client) GetVolumeForPersistentVolumeClaim

func (c *Client) GetVolumeForPersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim) (string, error)

GetVolumeForPersistentVolumeClaim returns the volumeID for the given PVC

func (*Client) IsNodeMaster

func (c *Client) IsNodeMaster(node corev1.Node) bool

IsNodeMaster returns true if given node is a kubernetes master node

func (*Client) IsNodeReady

func (c *Client) IsNodeReady(name string) error

IsNodeReady checks if node with given name is ready. Returns nil is ready.

func (*Client) IsPodBeingManaged

func (c *Client) IsPodBeingManaged(pod corev1.Pod) bool

IsPodBeingManaged returns true if the pod is being managed by a controller

func (*Client) IsPodReady

func (c *Client) IsPodReady(pod corev1.Pod) bool

IsPodReady checks if all containers in a pod are ready (passed readiness probe)

func (*Client) IsPodRunning

func (c *Client) IsPodRunning(pod corev1.Pod) bool

IsPodRunning checks if all containers in a pod are in running state

func (*Client) ListEvents

func (c *Client) ListEvents(namespace string, opts metav1.ListOptions) (*corev1.EventList, error)

ListEvents retrieves all events registered with kubernetes

func (*Client) ListLimitRange

func (c *Client) ListLimitRange(namespace string, opts metav1.ListOptions) (*corev1.LimitRangeList, error)

ListLimitRange creates the given limitrange

func (*Client) ListNamespaces

func (c *Client) ListNamespaces(labelSelector map[string]string) (*corev1.NamespaceList, error)

ListNamespaces returns all the namespaces

func (*Client) ListServices

func (c *Client) ListServices(svcNamespace string, listOptions metav1.ListOptions) (*corev1.ServiceList, error)

ListServices list services using filters or list all if options are empty

func (*Client) PatchEndpoints

func (c *Client) PatchEndpoints(name, ns string, pt types.PatchType, jsonPatch []byte, subresources ...string) (*corev1.Endpoints, error)

PatchEndpoints applies a patch for a given endpoints.

func (*Client) PatchService

func (c *Client) PatchService(name, namespace string, jsonPatch []byte, subresources ...string) (*corev1.Service, error)

PatchService patches the current service with the given json path

func (*Client) RecordEvent

func (c *Client) RecordEvent(source v1.EventSource, object runtime.Object, eventtype, reason, message string)

func (*Client) RemoveLabelOnNode

func (c *Client) RemoveLabelOnNode(name, key string) error

RemoveLabelOnNode removes the label with key on given node

func (*Client) ResourceExists

func (c *Client) ResourceExists(gvk schema.GroupVersionKind) (bool, error)

ResourceExists checks if resource already exists

func (*Client) RunCommandInPod

func (c *Client) RunCommandInPod(cmds []string, podName, containerName, namespace string) (string, error)

RunCommandInPod runs given command in the given pod

func (*Client) SearchNodeByAddresses

func (c *Client) SearchNodeByAddresses(addresses []string) (*corev1.Node, error)

SearchNodeByAddresses searches the node based on the IP addresses, then it falls back to a search by hostname, and finally by the labels

func (*Client) SetConfig

func (c *Client) SetConfig(cfg *rest.Config)

SetConfig sets the config and resets the client.

func (*Client) UnCordonNode

func (c *Client) UnCordonNode(nodeName string, timeout, retryInterval time.Duration) error

UnCordonNode uncordons the given node

func (*Client) UpdateConfigMap

func (c *Client) UpdateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)

UpdateConfigMap updates the given config map object

func (*Client) UpdateEndpoints

func (c *Client) UpdateEndpoints(endpoints *corev1.Endpoints) (*corev1.Endpoints, error)

UpdateEndpoints updates the given endpoint.

func (*Client) UpdateLimitRange

func (c *Client) UpdateLimitRange(limitrange *corev1.LimitRange) (*corev1.LimitRange, error)

UpdateLimitRange updates the given limitrange

func (*Client) UpdateNamespace

func (c *Client) UpdateNamespace(namespace *corev1.Namespace) (*corev1.Namespace, error)

UpdateNamespace updates a namespace with given metadata

func (*Client) UpdateNode

func (c *Client) UpdateNode(n *corev1.Node) (*corev1.Node, error)

UpdateNode updates the given node

func (*Client) UpdatePersistentVolumeClaim

func (c *Client) UpdatePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)

UpdatePersistentVolumeClaim updates an existing persistent volume claim

func (*Client) UpdatePod

func (c *Client) UpdatePod(pod *corev1.Pod) (*corev1.Pod, error)

UpdatePod updates the given pod

func (*Client) UpdateSecret

func (c *Client) UpdateSecret(secret *corev1.Secret) (*corev1.Secret, error)

UpdateSecret updates the given secret

func (*Client) UpdateSecretData

func (c *Client) UpdateSecretData(name string, ns string, data map[string][]byte) (*corev1.Secret, error)

UpdateSecretData updates or creates a new secret with the given data

func (*Client) UpdateService

func (c *Client) UpdateService(service *corev1.Service) (*corev1.Service, error)

UpdateService updates the given service

func (*Client) UpdateServiceAccount

func (c *Client) UpdateServiceAccount(account *corev1.ServiceAccount) (*corev1.ServiceAccount, error)

UpdaeServiceAccount updates the given service account

func (*Client) ValidateDeletedService

func (c *Client) ValidateDeletedService(svcName string, svcNS string) error

ValidateDeletedService validates if given service is deleted

func (*Client) ValidatePersistentVolumeClaim

func (c *Client) ValidatePersistentVolumeClaim(pvc *corev1.PersistentVolumeClaim, timeout, retryInterval time.Duration) error

ValidatePersistentVolumeClaim validates the given pvc

func (*Client) ValidatePersistentVolumeClaimSize

func (c *Client) ValidatePersistentVolumeClaimSize(pvc *corev1.PersistentVolumeClaim, expectedPVCSize int64, timeout, retryInterval time.Duration) error

ValidatePersistentVolumeClaimSize validates the given pvc size

func (*Client) ValidatePod

func (c *Client) ValidatePod(pod *corev1.Pod, timeout, retryInterval time.Duration) error

ValidatePod validates the given pod if it's ready

func (*Client) WaitForPodDeletion

func (c *Client) WaitForPodDeletion(uid types.UID, namespace string, timeout time.Duration) error

WaitForPodDeletion waits for given timeout for given pod to be deleted

func (*Client) WatchConfigMap

func (c *Client) WatchConfigMap(configMap *corev1.ConfigMap, fn WatchFunc) error

WatchConfigMap sets up a watcher that listens for changes on the config map

func (*Client) WatchLimitRange

func (c *Client) WatchLimitRange(limitrange *corev1.LimitRange, fn WatchFunc) error

func (*Client) WatchNode

func (c *Client) WatchNode(node *corev1.Node, watchNodeFn WatchFunc) error

WatchNode sets up a watcher that listens for the changes on Node.

func (*Client) WatchPods

func (c *Client) WatchPods(namespace string, fn WatchFunc, listOptions metav1.ListOptions) error

WatchPods sets up a watcher that listens for the changes to pods in given namespace

func (*Client) WatchSecret

func (c *Client) WatchSecret(secret *v1.Secret, fn WatchFunc) error

type ConfigMapOps

type ConfigMapOps interface {
	// GetConfigMap gets the config map object for the given name and namespace
	GetConfigMap(name string, namespace string) (*corev1.ConfigMap, error)
	// CreateConfigMap creates a new config map object if it does not already exist.
	CreateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)
	// DeleteConfigMap deletes the given config map
	DeleteConfigMap(name, namespace string) error
	// UpdateConfigMap updates the given config map object
	UpdateConfigMap(configMap *corev1.ConfigMap) (*corev1.ConfigMap, error)
	// WatchConfigMap sets up a watcher that listens for changes on the config map
	WatchConfigMap(configMap *corev1.ConfigMap, fn WatchFunc) error
}

ConfigMapOps is an interface to perform k8s ConfigMap operations

type EndpointsOps

type EndpointsOps interface {
	// CreateEndpoints creates a given endpoints.
	CreateEndpoints(endpoints *corev1.Endpoints) (*corev1.Endpoints, error)
	// GetEndpoints retrieves endpoints for a given namespace/name.
	GetEndpoints(name, namespace string) (*corev1.Endpoints, error)
	// PatchEndpoints applies a patch for a given endpoints.
	PatchEndpoints(name, namespace string, pt types.PatchType, jsonPatch []byte, subresources ...string) (*corev1.Endpoints, error)
	// DeleteEndpoints removes endpoints for a given namespace/name.
	DeleteEndpoints(name, namespace string) error
	// UpdateEndpoints updates the given endpoint
	UpdateEndpoints(endpoints *corev1.Endpoints) (*corev1.Endpoints, error)
}

EndpointsOps is an interface to deal with kubernetes endpoints.

type EventOps

type EventOps interface {
	// CreateEvent puts an event into k8s etcd
	CreateEvent(event *corev1.Event) (*corev1.Event, error)
	// ListEvents retrieves all events registered with kubernetes
	ListEvents(namespace string, opts metav1.ListOptions) (*corev1.EventList, error)
}

EventOps is an interface to put and get k8s events

type LimitRangeOps

type LimitRangeOps interface {
	// GetLimitRange gets the limitranges object given its name and namespace
	GetLimitRange(name string, namespace string) (*corev1.LimitRange, error)
	// CreateLimitRange creates the given limitrange
	CreateLimitRange(*corev1.LimitRange) (*corev1.LimitRange, error)
	// ListLimitRange changes and callback fn
	ListLimitRange(string, metav1.ListOptions) (*corev1.LimitRangeList, error)
	// UpdateLimitRange updates the given limitrange
	UpdateLimitRange(*corev1.LimitRange) (*corev1.LimitRange, error)
	// DeleteLimitRange deletes the given limitrange
	DeleteLimitRange(name, namespace string) error
	// WatchLimitRange changes and callback fn
	WatchLimitRange(*corev1.LimitRange, WatchFunc) error
}

LimitRangeOps is an interface to perform k8s LimitRange operations

type NamespaceOps

type NamespaceOps interface {
	// ListNamespaces returns all the namespaces
	ListNamespaces(labelSelector map[string]string) (*corev1.NamespaceList, error)
	// GetNamespace returns a namespace object for given name
	GetNamespace(name string) (*corev1.Namespace, error)
	// CreateNamespace creates a namespace with given name and metadata
	CreateNamespace(*corev1.Namespace) (*corev1.Namespace, error)
	// UpdateNamespace update a namespace with given metadata
	UpdateNamespace(*corev1.Namespace) (*corev1.Namespace, error)
	// DeleteNamespace deletes a namespace with given name
	DeleteNamespace(name string) error
}

NamespaceOps is an interface to perform namespace operations

type NodeOps

type NodeOps interface {
	// CreateNode creates the given node
	CreateNode(n *corev1.Node) (*corev1.Node, error)
	// UpdateNode updates the given node
	UpdateNode(n *corev1.Node) (*corev1.Node, error)
	// GetNodes talks to the k8s api server and gets the nodes in the cluster
	GetNodes() (*corev1.NodeList, error)
	// GetNodeByName returns the k8s node given it's name
	GetNodeByName(string) (*corev1.Node, error)
	// SearchNodeByAddresses searches corresponding k8s node match any of the given address
	SearchNodeByAddresses(addresses []string) (*corev1.Node, error)
	// FindMyNode finds LOCAL Node in Kubernetes cluster
	FindMyNode() (*corev1.Node, error)
	// IsNodeReady checks if node with given name is ready. Returns nil is ready.
	IsNodeReady(string) error
	// IsNodeMaster returns true if given node is a kubernetes master node
	IsNodeMaster(corev1.Node) bool
	// GetLabelsOnNode gets all the labels on the given node
	GetLabelsOnNode(string) (map[string]string, error)
	// AddLabelOnNode adds a label key=value on the given node
	AddLabelOnNode(string, string, string) error
	// RemoveLabelOnNode removes the label with key on given node
	RemoveLabelOnNode(string, string) error
	// WatchNode sets up a watcher that listens for the changes on Node.
	WatchNode(node *corev1.Node, fn WatchFunc) error
	// CordonNode cordons the given node
	CordonNode(nodeName string, timeout, retryInterval time.Duration) error
	// UnCordonNode uncordons the given node
	UnCordonNode(nodeName string, timeout, retryInterval time.Duration) error
	// DrainPodsFromNode drains given pods from given node. If timeout is set to
	// a non-zero value, it waits for timeout duration for each pod to get deleted
	DrainPodsFromNode(nodeName string, pods []corev1.Pod, timeout, retryInterval time.Duration) error
	// DeleteNode deletes the given node
	DeleteNode(name string) error
}

NodeOps is an interface to perform k8s node operations

type Ops

type Ops interface {
	ConfigMapOps
	EndpointsOps
	EventOps
	RecorderOps
	NamespaceOps
	NodeOps
	PersistentVolumeClaimOps
	PodOps
	SecretOps
	ServiceOps
	ServiceAccountOps
	LimitRangeOps

	// SetConfig sets the config and resets the client
	SetConfig(config *rest.Config)
	// GetVersion gets the version from the kubernetes cluster
	GetVersion() (*version.Info, error)
	// ResourceExists returns true if given resource type exists in kubernetes API server
	ResourceExists(schema.GroupVersionKind) (bool, error)
}

Ops is an interface to perform kubernetes related operations on the core resources.

func Instance

func Instance() Ops

Instance returns a singleton instance of the client.

func NewInstanceFromConfigFile

func NewInstanceFromConfigFile(config string) (Ops, error)

NewInstanceFromConfigFile returns new instance of client by using given config file

type PersistentVolumeClaimOps

type PersistentVolumeClaimOps interface {
	// CreatePersistentVolumeClaim creates the given persistent volume claim
	CreatePersistentVolumeClaim(*corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)
	// UpdatePersistentVolumeClaim updates an existing persistent volume claim
	UpdatePersistentVolumeClaim(*corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaim, error)
	// DeletePersistentVolumeClaim deletes the given persistent volume claim
	DeletePersistentVolumeClaim(name, namespace string) error
	// ValidatePersistentVolumeClaim validates the given pvc
	ValidatePersistentVolumeClaim(vv *corev1.PersistentVolumeClaim, timeout, retryInterval time.Duration) error
	// ValidatePersistentVolumeClaimSize validates the given pvc size
	ValidatePersistentVolumeClaimSize(vv *corev1.PersistentVolumeClaim, expectedPVCSize int64, timeout, retryInterval time.Duration) error
	// GetPersistentVolumeClaim returns the PVC for given name and namespace
	GetPersistentVolumeClaim(pvcName string, namespace string) (*corev1.PersistentVolumeClaim, error)
	// GetPersistentVolumeClaims returns all PVCs in given namespace and that match the optional labelSelector
	GetPersistentVolumeClaims(namespace string, labelSelector map[string]string) (*corev1.PersistentVolumeClaimList, error)
	// CreatePersistentVolume creates the given PV
	CreatePersistentVolume(pv *corev1.PersistentVolume) (*corev1.PersistentVolume, error)
	// GetPersistentVolume returns the PV for given name
	GetPersistentVolume(pvName string) (*corev1.PersistentVolume, error)
	// DeletePersistentVolume deletes the PV for given name
	DeletePersistentVolume(pvName string) error
	// GetPersistentVolumes returns all PVs in cluster
	GetPersistentVolumes() (*corev1.PersistentVolumeList, error)
	// GetVolumeForPersistentVolumeClaim returns the volumeID for the given PVC
	GetVolumeForPersistentVolumeClaim(*corev1.PersistentVolumeClaim) (string, error)
	// GetPersistentVolumeClaimParams fetches custom parameters for the given PVC
	GetPersistentVolumeClaimParams(*corev1.PersistentVolumeClaim) (map[string]string, error)
	// GetPersistentVolumeClaimStatus returns the status of the given pvc
	GetPersistentVolumeClaimStatus(*corev1.PersistentVolumeClaim) (*corev1.PersistentVolumeClaimStatus, error)
	// GetPVCsUsingStorageClass returns all PVCs that use the given storage class
	GetPVCsUsingStorageClass(scName string) ([]corev1.PersistentVolumeClaim, error)
	// GetStorageProvisionerForPVC returns storage provisioner for given PVC if it exists
	GetStorageProvisionerForPVC(pvc *corev1.PersistentVolumeClaim) (string, error)
	// GetStorageClassForPVC returns the appropriate storage class object for a certain pvc
	GetStorageClassForPVC(pvc *corev1.PersistentVolumeClaim) (*storagev1.StorageClass, error)
}

PersistentVolumeClaimOps is an interface to perform k8s PVC operations

type PodOps

type PodOps interface {
	// CreatePod creates the given pod.
	CreatePod(pod *corev1.Pod) (*corev1.Pod, error)
	// UpdatePod updates the given pod
	UpdatePod(pod *corev1.Pod) (*corev1.Pod, error)
	// GetPods returns pods for the given namespace
	GetPods(string, map[string]string) (*corev1.PodList, error)
	// GetPodsByNode returns all pods in given namespace and given k8s node name.
	//  If namespace is empty, it will return pods from all namespaces.
	GetPodsByNode(nodeName, namespace string) (*corev1.PodList, error)
	// GetPodsByNodeAndLabels returns all pods in given namespace and given k8s node name
	// with a given label selector.
	//  If namespace is empty, it will return pods from all namespaces.
	GetPodsByNodeAndLabels(nodeName, namespace string, labelSelector map[string]string) (*corev1.PodList, error)
	// GetPodsByOwner returns pods for the given owner and namespace
	GetPodsByOwner(types.UID, string) ([]corev1.Pod, error)
	// GetPodsUsingPV returns all pods in cluster using given pv
	GetPodsUsingPV(pvName string) ([]corev1.Pod, error)
	// GetPodsUsingPVByNodeName returns all pods running on the node using the given pv
	GetPodsUsingPVByNodeName(pvName, nodeName string) ([]corev1.Pod, error)
	// GetPodsUsingPVC returns all pods in cluster using given pvc
	GetPodsUsingPVC(pvcName, pvcNamespace string) ([]corev1.Pod, error)
	// GetPodsUsingPVCByNodeName returns all pods running on the node using given pvc
	GetPodsUsingPVCByNodeName(pvcName, pvcNamespace, nodeName string) ([]corev1.Pod, error)
	// GetPodsUsingVolumePlugin returns all pods who use PVCs provided by the given volume plugin
	GetPodsUsingVolumePlugin(plugin string) ([]corev1.Pod, error)
	// GetPodsUsingVolumePluginByNodeName returns all pods who use PVCs provided by the given volume plugin on the given node
	GetPodsUsingVolumePluginByNodeName(nodeName, plugin string) ([]corev1.Pod, error)
	// GetPodByName returns pod for the given pod name and namespace
	GetPodByName(string, string) (*corev1.Pod, error)
	// GetPodByUID returns pod with the given UID, or error if nothing found
	GetPodByUID(types.UID, string) (*corev1.Pod, error)
	// DeletePod deletes the given pod
	DeletePod(string, string, bool) error
	// DeletePods deletes the given pods
	DeletePods([]corev1.Pod, bool) error
	// IsPodRunning checks if all containers in a pod are in running state
	IsPodRunning(corev1.Pod) bool
	// IsPodReady checks if all containers in a pod are ready (passed readiness probe)
	IsPodReady(corev1.Pod) bool
	// IsPodBeingManaged returns true if the pod is being managed by a controller
	IsPodBeingManaged(corev1.Pod) bool
	// WaitForPodDeletion waits for given timeout for given pod to be deleted
	WaitForPodDeletion(uid types.UID, namespace string, timeout time.Duration) error
	// RunCommandInPod runs given command in the given pod
	RunCommandInPod(cmds []string, podName, containerName, namespace string) (string, error)
	// ValidatePod validates the given pod if it's ready
	ValidatePod(pod *corev1.Pod, timeout, retryInterval time.Duration) error
	// WatchPods sets up a watcher that listens for the changes to pods in given namespace
	WatchPods(namespace string, fn WatchFunc, listOptions metav1.ListOptions) error
}

PodOps is an interface to perform k8s pod operations

type RecorderOps

type RecorderOps interface {
	// RecordEvent records an event into k8s using client-go's EventRecorder inteface
	// It takes the event source and the object on which the event is being raised.
	RecordEvent(source v1.EventSource, object runtime.Object, eventtype, reason, message string)
}

RecorderOps is an interface to record k8s events

type SecretOps

type SecretOps interface {
	// GetSecret gets the secrets object given its name and namespace
	GetSecret(name string, namespace string) (*corev1.Secret, error)
	// CreateSecret creates the given secret
	CreateSecret(*corev1.Secret) (*corev1.Secret, error)
	// UpdateSecret updates the given secret
	UpdateSecret(*corev1.Secret) (*corev1.Secret, error)
	// UpdateSecretData updates or creates a new secret with the given data
	UpdateSecretData(string, string, map[string][]byte) (*corev1.Secret, error)
	// DeleteSecret deletes the given secret
	DeleteSecret(name, namespace string) error
	// WatchSecret changes and callback fn
	WatchSecret(*corev1.Secret, WatchFunc) error
}

SecretOps is an interface to perform k8s Secret operations

type ServiceAccountOps

type ServiceAccountOps interface {
	// CreateServiceAccount creates the given service account
	CreateServiceAccount(account *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
	// GetServiceAccount gets the given service account
	GetServiceAccount(name, namespace string) (*corev1.ServiceAccount, error)
	// UpdateServiceAccount updates the given service account
	UpdateServiceAccount(account *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
	// DeleteServiceAccount deletes the given service account
	DeleteServiceAccount(accountName, namespace string) error
}

ServiceAccountOps is an interface to perform operations on role resources.

type ServiceOps

type ServiceOps interface {
	// GetService gets the service by the name
	GetService(string, string) (*corev1.Service, error)
	// ListServices list services using filters or list all if options are empty
	ListServices(string, metav1.ListOptions) (*corev1.ServiceList, error)
	// GetServiceEndpoint gets the externalIP if service is a LoadBalancer or ClusterIP otherwise
	GetServiceEndpoint(string, string) (string, error)
	// CreateService creates the given service
	CreateService(*corev1.Service) (*corev1.Service, error)
	// DeleteService deletes the given service
	DeleteService(name, namespace string) error
	// ValidateDeletedService validates if given service is deleted
	ValidateDeletedService(string, string) error
	// DescribeService gets the service status
	DescribeService(string, string) (*corev1.ServiceStatus, error)
	// PatchService patches the current service with the given json path
	PatchService(name, namespace string, jsonPatch []byte, subresources ...string) (*corev1.Service, error)
	// UpdateService updates the given service
	UpdateService(*corev1.Service) (*corev1.Service, error)
}

ServiceOps is an interface to perform k8s service operations

type WatchFunc

type WatchFunc func(object runtime.Object) error

WatchFunc is a callback provided to the Watch functions which is invoked when the given object is changed.

Jump to

Keyboard shortcuts

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