k8s

package
v0.0.0-...-ff6338b Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2018 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NsGoodPhases = []api_core_v1.NamespacePhase{"Active"}

NsGoodPhases is an array of phases of the Namespace which are considered to be good

View Source
var PodBadPhases = []string{"Error"}

PodBadPhases is an array of phases of the Pod which are considered to be bad

View Source
var PodBadStates = []string{"CrashLoopBackOff", "ImagePullBackOff", "RunContainerError", "ContainerCannotRun"}

PodBadStates is an array of the states of the Pod which are considered to be bad

View Source
var PodGoodPhases = []string{"Running"}

PodGoodPhases is an array of phases of the Pod which are considered to be good

View Source
var PodGoodStates = []string{"Running"}

PodGoodStates is an array of the states of the Pod which are considered to be good

View Source
var PodWaitPhases = []string{"Pending"}

PodWaitPhases is an array of phases of the Pod which are considered to be waiting

View Source
var PodWaitStates = []string{"ContainerCreating", "Pending"}

PodWaitStates is an array of the states of the Pod which are considered to be waiting

Functions

func GetClientConfig

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

GetClientConfig first tries to get a config object which uses the service account kubernetes gives to pods, if it is called from a process running in a kubernetes environment. Otherwise, it tries to build config from a default kubeconfig filepath if it fails, it fallback to the default config. Once it get the config, it returns the same.

func GetClientset

func GetClientset() (*kubernetes.Clientset, error)

GetClientset first tries to get a config object which uses the service account kubernetes gives to pods, if it is called from a process running in a kubernetes environment. Otherwise, it tries to build config from a default kubeconfig filepath if it fails, it fallback to the default config. Once it get the config, it creates a new Clientset for the given config and returns the clientset.

func GetClientsetFromConfig

func GetClientsetFromConfig(config *rest.Config) (*kubernetes.Clientset, error)

GetClientsetFromConfig takes REST config and Create a clientset based on that and return that clientset

func GetRESTClient

func GetRESTClient() (*rest.RESTClient, error)

GetRESTClient first tries to get a config object which uses the service account kubernetes gives to pods, if it is called from a process running in a kubernetes environment. Otherwise, it tries to build config from a default kubeconfig filepath if it fails, it fallback to the default config. Once it get the config, it

Types

type K8S

type K8S struct {
	Config           *rest.Config
	Clientset        *kubernetes.Clientset
	OpenebsClientSet *openebs.Clientset
}

K8S is a struct which will be the driver for all the methods related to kubernetes

func NewK8S

func NewK8S() (K8S, error)

NewK8S returns K8S struct

func (K8S) ApplyDSFromManifestStruct

func (k8s K8S) ApplyDSFromManifestStruct(manifest v1beta1.DaemonSet) (v1beta1.DaemonSet, error)

ApplyDSFromManifestStruct Creates a Daemonset from the manifest supplied

func (K8S) BlockUntilPodIsUp

func (k8s K8S) BlockUntilPodIsUp(pod *core_v1.Pod, quit <-chan bool) (err error)

BlockUntilPodIsUp blocks until all containers of the given pod is ready or when `true` is send to channel `quit`. It returns error if occurred.

func (K8S) BlockUntilPodIsUpOrTimeout

func (k8s K8S) BlockUntilPodIsUpOrTimeout(pod *core_v1.Pod, timeout time.Duration) (err error)

BlockUntilPodIsUpOrTimeout blocks until all containers of the given pod is ready or when timeout is hit. It returns error if occurred. It uses `BlockUntilPodIsUpWithContext` internally, so in case of timeout it will give error describing "context cancelled"

func (K8S) BlockUntilPodIsUpWithContext

func (k8s K8S) BlockUntilPodIsUpWithContext(ctx context.Context, pod *core_v1.Pod) (err error)

BlockUntilPodIsUpWithContext blocks until all containers of the given pod is ready or when supplied context cancelled. It returns error if occurred.

func (K8S) CreateCStorPool

func (k8s K8S) CreateCStorPool(cStorPool *openebs_v1.CStorPool) (*openebs_v1.CStorPool, error)

CreateCStorPool creates the CStorPool and returns it.

func (K8S) CreateDeployment

func (k8s K8S) CreateDeployment(namespace string, deployment *v1beta1.Deployment) (*v1beta1.Deployment, error)

CreateDeployment creates the Deployment in the given namespace.

func (K8S) CreatePersistentVolumeClaim

func (k8s K8S) CreatePersistentVolumeClaim(namespace string, persistentVolumeClaim *core_v1.PersistentVolumeClaim) (*core_v1.PersistentVolumeClaim, error)

CreatePersistentVolumeClaim creates the PVC in the given namespace.

func (K8S) CreateStoragePool

func (k8s K8S) CreateStoragePool(storagePool *openebs_v1.StoragePool) (*openebs_v1.StoragePool, error)

CreateStoragePool takes the representation of a StoragePool and creates it.

func (K8S) CreateStoragePoolClaim

func (k8s K8S) CreateStoragePoolClaim(storagePoolClaim *openebs_v1.StoragePoolClaim) (*openebs_v1.StoragePoolClaim, error)

CreateStoragePoolClaim takes StoragePoolClaim as an argument and creates it.

func (K8S) CreateStorgeClass

func (k8s K8S) CreateStorgeClass(storageClass *storage_v1.StorageClass) (*storage_v1.StorageClass, error)

CreateStorageClass creates the StorageClass.

func (K8S) DeleteCStorPool

func (k8s K8S) DeleteCStorPool(cStorPoolName string, opts *meta_v1.DeleteOptions) error

DeleteCStorPool deletes a CStorPool with the given name.

func (K8S) DeleteCStorVolumeReplica

func (k8s K8S) DeleteCStorVolumeReplica(cvrName, namespace string, opts *meta_v1.DeleteOptions) error

DeleteCStorVolumeReplica deletes a CStorVolumeReplica with the given CStorVolumeReplicaName and namespace

func (K8S) DeleteDeployment

func (k8s K8S) DeleteDeployment(namespace, deploymentName string, opts *meta_v1.DeleteOptions) error

DeleteDeployment deletes the Deployment object of the given deploymentName in the given namespace.

func (K8S) DeleteDisk

func (k8s K8S) DeleteDisk(diskName string, opts *meta_v1.DeleteOptions) error

DeleteDisk deletes a Disk object with the given diskname

func (K8S) DeletePersistentVolume

func (k8s K8S) DeletePersistentVolume(persistentVolumeName string, opts *meta_v1.DeleteOptions) error

DeletePersistentVolume deletes a PersistentVolume object with the given persistentVolumeName

func (K8S) DeletePersistentVolumeClaim

func (k8s K8S) DeletePersistentVolumeClaim(namespace, persistentVolumeClaimName string, opts *meta_v1.DeleteOptions) error

DeletePersistentVolumeClaim deletes supplied PVC in the given namespace.

func (K8S) DeleteStorageClass

func (k8s K8S) DeleteStorageClass(storageClassName string, opts *meta_v1.DeleteOptions) error

DeleteStorageClass deletes the StorageClass object of given storageClassName.

func (K8S) DeleteStoragePool

func (k8s K8S) DeleteStoragePool(storagePoolName string, opts *meta_v1.DeleteOptions) error

DeleteStoragePool deletes a StoragePool object with the given storagePoolName.

func (K8S) DeleteStoragePoolClaim

func (k8s K8S) DeleteStoragePoolClaim(spcName string, opts *meta_v1.DeleteOptions) error

DeleteStoragePoolClaim deletes a StoragePoolClaim with the given name.

func (K8S) ExecToPod

func (k8s K8S) ExecToPod(command, containerName, podName, namespace string) (string, error)

ExecToPod performs non-interactive exec to the pod with the specified command. first through API with `stdin` param as `nil`, if it fails then it uses `kubectl exec` :param string command: list of the str which specify the command. :param string containerName: name of the container in the Pod. (If the Pod has only one container, then it can be Empty String) :param string pod_name: Pod name :param string namespace: namespace of the Pod. (If it is blank string then, namespace will be default i.e. k8s.io/api/core/v1.NamespaceDefault) :return: string: Output of the command. (STDOUT)

error: If any error has occurred otherwise `nil`

func (K8S) ExecToPodThroughAPI

func (k8s K8S) ExecToPodThroughAPI(command, containerName, podName, namespace string, stdin io.Reader) (string, string, error)

ExecToPodThroughAPI performs non-interactive exec to the pod with the specified command using client-go. :param string command: list of the str which specify the command. :param string containerName: name of the container in the Pod. (If the Pod has only one container, then it can be Empty String) :param string pod_name: Pod name :param string namespace: namespace of the Pod. (If it is blank string then, namespace will be default i.e. k8s.io/api/core/v1.NamespaceDefault) :param io.Reader stdin: Standard Input if necessary, otherwise `nil` :return: string: Output of the command. (STDOUT)

string: Errors. (STDERR)
 error: If any error has occurred otherwise `nil`

func (K8S) ExecToPodThroughKubectl

func (k8s K8S) ExecToPodThroughKubectl(command, containerName, podName, namespace string) (string, error)

ExecToPodThroughKubectl performs non-interactive exec to the pod with the specified command using `kubectl exec` :param string command: list of the str which specify the command. :param string containerName: name of the container in the Pod. (If the Pod has only one container, then it can be Empty String) :param string pod_name: Pod name :param string namespace: namespace of the Pod. (If it is blank string then, namespace will be default i.e. k8s.io/api/core/v1.NamespaceDefault) :return: string: Output of the command. (STDOUT)

error: If any error has occurred otherwise `nil`

func (K8S) GetAllNamespacesCoreV1NamespaceArray

func (k8s K8S) GetAllNamespacesCoreV1NamespaceArray() ([]core_v1.Namespace, error)

GetAllNamespacesCoreV1NamespaceArray returns V1NamespaceList of all the namespaces. :return kubernetes.client.models.v1_namespace_list.V1NamespaceList: list of namespaces.

func (K8S) GetAllNamespacesMap

func (k8s K8S) GetAllNamespacesMap() (map[string]core_v1.Namespace, error)

GetAllNamespacesMap returns list of the names of all the namespaces. :return: map[string]core_v1.Namespace: map of namespaces where key is namespace name (str) and value is corresponding k8s.io/api/core/v1.Namespace object.

func (K8S) GetCStorPool

func (k8s K8S) GetCStorPool(cStorPoolName string, opts meta_v1.GetOptions) (*openebs_v1.CStorPool, error)

GetCStorPool returns the CStorPool object for given cStorPoolName.

func (K8S) GetCStorVolumeReplica

func (k8s K8S) GetCStorVolumeReplica(cvrName, namespace string, opts meta_v1.GetOptions) (*openebs_v1.CStorVolumeReplica, error)

GetCStorVolumeReplica returns the CStorVolumeReplica object for given CStorVolumeReplicaName and namespace

func (K8S) GetContainerStateByIndexInPod

func (k8s K8S) GetContainerStateByIndexInPod(pod *core_v1.Pod, containerIndex int) (containerState core_v1.ContainerState, err error)

GetContainerStateByIndexInPod tries to get the state of the container of supplied index of the supplied Pod only once

:param pod: pod object on which operation should be performed
:param containerIndex: index of the container for which you want state.
:return: k8s.io/api/core/v1.ContainerState: state of the container.
       : error: error if occurred, `nil` otherwise

func (K8S) GetContainerStateByIndexInPodUntilToldToQuit

func (k8s K8S) GetContainerStateByIndexInPodUntilToldToQuit(pod *core_v1.Pod, containerIndex int, quit <-chan bool) (containerState core_v1.ContainerState, err error)

GetContainerStateByIndexInPodUntilToldToQuit tries to get the state of the container of supplied index of the supplied Pod until `true` is sent in `quit` channel

:param pod: pod object on which operation should be performed
:param containerIndex: index of the container for which you want state.
:param quit: channel which is used to stop this function.
:return: k8s.io/api/core/v1.ContainerState: state of the container.
       : error: error if occurred, `nil` otherwise

func (K8S) GetContainerStateByIndexInPodWithTimeout

func (k8s K8S) GetContainerStateByIndexInPodWithTimeout(pod *core_v1.Pod, containerIndex int, timeout time.Duration) (containerState core_v1.ContainerState, err error)

GetContainerStateByIndexInPodWithTimeout returns the state of the container of supplied index of the supplied Pod.

:param pod: pod object on which operation should be performed
:param containerIndex: index of the container for which you want state.
:param timeout: maximum time duration to get the container's state.
:return: k8s.io/api/core/v1.ContainerState: state of the container.
       : error: error if occurred, `nil` otherwise

func (K8S) GetContainerStatesInPod

func (k8s K8S) GetContainerStatesInPod(pod *core_v1.Pod) (containerStates []core_v1.ContainerState, err error)

GetContainerStatesInPod tries to get the states of all the containers of the supplied Pod only once

:param pod: pod object on which operation should be performed
:return: []k8s.io/api/core/v1.ContainerState: slice which holds states of the containers.
       : error: error if occurred, `nil` otherwise

func (K8S) GetContainerStatesInPodUntilToldToQuit

func (k8s K8S) GetContainerStatesInPodUntilToldToQuit(pod *core_v1.Pod, quit <-chan bool) (containerStates []core_v1.ContainerState, err error)

GetContainerStatesInPodUntilToldToQuit tries to get the states of all the containers of the supplied Pod until `true` is sent in `quit` channel

:param pod: pod object on which operation should be performed
:param quit: channel which is used to stop this function.
:return: []k8s.io/api/core/v1.ContainerState: slice which holds states of the containers.
       : error: error if occurred, `nil` otherwise

func (K8S) GetContainerStatesInPodWithTimeout

func (k8s K8S) GetContainerStatesInPodWithTimeout(pod *core_v1.Pod, timeout time.Duration) (containerStates []core_v1.ContainerState, err error)

GetContainerStatesInPodWithTimeout returns the states of all the containers of the supplied Pod.

:param pod: pod object on which operation should be performed
:param timeout: maximum time duration to get the container's state.
:return: []k8s.io/api/core/v1.ContainerState: slice which holds states of the containers.
       : error: error if occurred, `nil` otherwise

func (K8S) GetDaemonset

func (k8s K8S) GetDaemonset(daemonsetName, daemonsetNamespace string) (v1beta1.DaemonSet, error)

GetDaemonset returns the k8s.io/api/extensions/v1beta1.DaemonSet for the name supplied.

func (K8S) GetDaemonsetStructFromYamlBytes

func (k8s K8S) GetDaemonsetStructFromYamlBytes(yamlBytes []byte) (v1beta1.DaemonSet, error)

GetDaemonsetStructFromYamlBytes returns k8s.io/api/extensions/v1beta1.DaemonSet for the yaml supplied

func (K8S) GetDeployment

func (k8s K8S) GetDeployment(namespace, deploymentName string, opts meta_v1.GetOptions) (*v1beta1.Deployment, error)

GetDeployment returns the Deployment object for given deploymentName in the given namespace.

func (K8S) GetDisk

func (k8s K8S) GetDisk(diskName string, opts meta_v1.GetOptions) (*openebs_v1.Disk, error)

GetDisk returns the Disk object for the given disk name

func (K8S) GetLog

func (k8s K8S) GetLog(podName, namespace string) (string, error)

GetLog returns the log of the pod. :param string pod_name: Name of the pod. (required) :param string namespace: Namespace of the pod. (required) :return: string: Log of the pod specified.

error: If an error has occurred, otherwise `nil`

func (K8S) GetNodeNames

func (k8s K8S) GetNodeNames() (nodeNames []string, err error)

GetNodeNames returns a list of the name of all the nodes.

:return: slice: list of node names (slice of string array).

func (K8S) GetNodes

func (k8s K8S) GetNodes() (nodeNames []core_v1.Node, err error)

GetNodes returns a list of all the nodes.

:return: slice: list of nodes (slice of k8s.io/api/core/v1.Node array).

func (K8S) GetPersistentVolume

func (k8s K8S) GetPersistentVolume(persistentVolumeName string, opts meta_v1.GetOptions) (*core_v1.PersistentVolume, error)

GetPersistentVolume returns the PersistentVolume object for the given persistentVolumeName

func (K8S) GetPersistentVolumeClaim

func (k8s K8S) GetPersistentVolumeClaim(namespace, persistentVolumeClaimName string, opts meta_v1.GetOptions) (*core_v1.PersistentVolumeClaim, error)

GetPersistentVolumeClaim lists single PVC in the given namespace.

func (K8S) GetPod

func (k8s K8S) GetPod(namespace, podName string) (*core_v1.Pod, error)

GetPod returns the Pod object for given podName in the given namespace. :return: *kubernetes.client.models.v1_pod.V1Pod: Pointer to Pod objects.

func (K8S) GetPodPhase

func (k8s K8S) GetPodPhase(pod *core_v1.Pod) core_v1.PodPhase

GetPodPhase returns phase of the pod passed as an k8s.io/api/core/v1.PodPhase object.

:param k8s.io/api/core/v1.Pod pod: pod object for which you want to get phase.
:return: k8s.io/api/core/v1.PodPhase: phase of the pod.

func (K8S) GetPodPhaseStr

func (k8s K8S) GetPodPhaseStr(pod *core_v1.Pod) string

GetPodPhaseStr returns phase of the pod passed in string format.

:param k8s.io/api/core/v1.Pod pod: pod object for which you want to get phase.
:return: str: phase of the pod.

func (K8S) GetPods

func (k8s K8S) GetPods(namespace, podNamePrefix string) ([]core_v1.Pod, error)

GetPods returns all the Pods object which has a prefix specified in its name in the given namespace. it tries to get the pods which match the criteria only once. NOTE: it counts pods which are not even in ContainerCreating state yet. Deal with them properly.

func (K8S) GetPodsOrBlock

func (k8s K8S) GetPodsOrBlock(namespace, podNamePrefix string) ([]core_v1.Pod, error)

GetPodsOrBlock returns all the Pods object which has a prefix specified in its name in the given namespace. it tries to get the pods which match the criteria unless it gets at least one such pod. NOTE: it counts pods which are not even in ContainerCreating state yet. Deal with them properly.

func (K8S) GetPodsOrTimeout

func (k8s K8S) GetPodsOrTimeout(namespace, podNamePrefix string, timeout time.Duration) ([]core_v1.Pod, error)

GetPodsOrTimeout returns all the Pods object which has a prefix specified in its name in the given namespace. it tries to get the pods which match the criteria unless timeout occurs or it gets at least one such pod. NOTE: it counts pods which are not even in ContainerCreating state yet. Deal with them properly.

func (K8S) GetPodsUntilQuitSignal

func (k8s K8S) GetPodsUntilQuitSignal(namespace, podNamePrefix string, quit <-chan bool) (thePods []core_v1.Pod, err error)

GetPodsUntilQuitSignal returns all the Pods object which has a prefix specified in its name in the given namespace. it tries to get the pods which match the criteria unless `true` received from `quit` or it gets at least one such pod. NOTE: it counts pods which are not even in ContainerCreating state yet. Deal with them properly.

func (K8S) GetStorageClass

func (k8s K8S) GetStorageClass(storageClassName string, opts meta_v1.GetOptions) (*storage_v1.StorageClass, error)

GetStorageClass returns the StorageClass object for given storageClassName.

func (K8S) GetStoragePool

func (k8s K8S) GetStoragePool(storagePoolName string, opts meta_v1.GetOptions) (*openebs_v1.StoragePool, error)

GetStoragePool returns the StoragePool object for the given storagePoolName.

func (K8S) GetStoragePoolClaim

func (k8s K8S) GetStoragePoolClaim(spcName string, opts meta_v1.GetOptions) (*openebs_v1.StoragePoolClaim, error)

GetStoragePoolClaim returns the StoragePoolClaim object for given spcName.

func (K8S) IsNSinGoodPhase

func (k8s K8S) IsNSinGoodPhase(namespace api_core_v1.Namespace) bool

IsNSinGoodPhase checks if supplied namespace is in good phase or not by matching phase of supplied namespace with pre-identified Good phase list (NsGoodPhases)

func (K8S) IsPodRunning

func (k8s K8S) IsPodRunning(pod *api_core_v1.Pod) bool

IsPodRunning returns whether all the containers in a given pod is running TODO: Check if it works for the Pod where one container has successfully terminated but other is running

func (K8S) IsPodStateGood

func (k8s K8S) IsPodStateGood(podState string) bool

IsPodStateGood checks if supplied pod state is good or not by matching state of supplied pod state with pre-identified Good states list (PodGoodStates)

func (K8S) IsPodStateWait

func (k8s K8S) IsPodStateWait(podState string) bool

IsPodStateWait checks if supplied pod state is wait state or not by matching state of supplied pod state with pre-identified Wait states list (PodWaitStates)

func (K8S) ListCStorPool

func (k8s K8S) ListCStorPool(opts meta_v1.ListOptions) (*openebs_v1.CStorPoolList, error)

ListCStorPool returns all CStorPool objects.

func (K8S) ListCStorVolumeReplica

func (k8s K8S) ListCStorVolumeReplica(namespace string, opts meta_v1.ListOptions) (*openebs_v1.CStorVolumeReplicaList, error)

ListCStorVolumeReplica returns all the CStorVolumeReplicaList for given namespace

func (K8S) ListDeployments

func (k8s K8S) ListDeployments(namespace string, opts meta_v1.ListOptions) (*v1beta1.DeploymentList, error)

ListDeployments returns a pointer to the DeploymentList containing all the deployments.

func (K8S) ListDisks

func (k8s K8S) ListDisks(opts meta_v1.ListOptions) (*openebs_v1.DiskList, error)

ListDisks list all the Disk objects

func (K8S) ListPersistentVolume

func (k8s K8S) ListPersistentVolume(opts meta_v1.ListOptions) (*core_v1.PersistentVolumeList, error)

ListPersistentVolume returns all the PersistentVolume objects

func (K8S) ListPersistentVolumeClaim

func (k8s K8S) ListPersistentVolumeClaim(namespace string, opts meta_v1.ListOptions) (*core_v1.PersistentVolumeClaimList, error)

ListPersistentVolumeClaim lists all the PVCs in the given namespace.

func (K8S) ListStorageClasses

func (k8s K8S) ListStorageClasses(opts meta_v1.ListOptions) (*storage_v1.StorageClassList, error)

ListStorageClasses returns a pointer to StorageClassList containing all the storage classes.

func (K8S) ListStoragePool

func (k8s K8S) ListStoragePool(opts meta_v1.ListOptions) (*openebs_v1.StoragePoolList, error)

ListStoragePool returns all the StoragePool objects.

func (K8S) ListStoragePoolClaims

func (k8s K8S) ListStoragePoolClaims(opts meta_v1.ListOptions) (*openebs_v1.StoragePoolClaimList, error)

ListStoragePoolClaims returns an object of StoragePoolClaimList.

func (K8S) ReloadPod

func (k8s K8S) ReloadPod(pod *core_v1.Pod) (*core_v1.Pod, error)

ReloadPod reloads the state of the pod supplied and return error if any

func (K8S) YAMLApply

func (k8s K8S) YAMLApply(yamlPath string) error

YAMLApply apply the yaml specified by the argument.

:param str yamlPath: Path of the yaml file that is to be applied.

Jump to

Keyboard shortcuts

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