Documentation ¶
Overview ¶
Package kubectl is a generated GoMock package.
Index ¶
- Constants
- func ArePodsRunning(k KubeRunner) (yes bool, err error)
- func DeletePod(k KubeRunner, name string) (err error)
- func GetKubectlPath() string
- func GetOldestRunningPod(k KubeRunner) (pod string, err error)
- func GetPodNodes(k KubeRunner) (nodes []string, err error)
- func GetPods(k KubeRunner) (pods []string, err error)
- func GetRunningPods(k KubeRunner) (pods []string, err error)
- func IsPod(kind string) (yes bool)
- func IsPodRunning(k KubeRunner, name string) (yes bool, err error)
- type KubeRunner
- type Kubectl
- type KubectlFile
- type MockKubeCtlRunner
- type MockKubeCtlRunnerMockRecorder
- type MockKubeRunner
- type MockKubeRunnerMockRecorder
Constants ¶
const ( // DefaultLitmusNamespace is the default namespace where kubectl operations // will be executed DefaultLitmusNamespace = "litmus" )
const (
// KubectlPath is the expected location where kubectl executable may be found
KubectlPath = "/usr/local/bin/kubectl"
)
Variables ¶
This section is empty.
Functions ¶
func ArePodsRunning ¶
func ArePodsRunning(k KubeRunner) (yes bool, err error)
ArePodsRunning returns true if all the pod(s) are running, false otherwise
An example of kubectl get pods & its state:
This makes use of status.containerStatuses[*].state.*.reason
$ kubectl get po -n kube-system --selector=k8s-app=kube-dns -o jsonpath='{.items[*].status.containerStatuses[*].state.*.reason}' CrashLoopBackOff CrashLoopBackOff
Another example of kubectl get pods & its state:
This makes use of status.containerStatuses[*].ready
$ kubectl get pods -n kube-system --selector=k8s-app=kube-dns -o jsonpath='{.items[*].status.containerStatuses[*].ready}' true false true
func DeletePod ¶
func DeletePod(k KubeRunner, name string) (err error)
DeletePod deletes the specified pod
func GetKubectlPath ¶
func GetKubectlPath() string
GetKubectlPath gets the location where kubectl executable is expected to be present
func GetOldestRunningPod ¶
func GetOldestRunningPod(k KubeRunner) (pod string, err error)
GetOldestRunningPod fetches the oldest running pod based on the provided labels and sorted based on their age
Sample code to do this:
$ JSONPATH='{range .items[*]}{@.metadata.name}::{@.status.containerStatuses[*].ready}::::{end}' && kubectl get po -n kube-system --sort-by=.metadata.creationTimestamp -o jsonpath="$JSONPATH" kube-addon-manager-amit-thinkpad-l470::true::::kube-dns-54cccfbdf8-q7v2c::false false true::::kubernetes-dashboard-77d8b98585-cwbjq::false::::storage-provisioner::true::::tiller-deploy-5b48764ff7-g9qz7::true::::
func GetPodNodes ¶
func GetPodNodes(k KubeRunner) (nodes []string, err error)
GetPodNodes fetches the nodes that hosts the pods. Pods are referred to via the provided labels
func GetPods ¶
func GetPods(k KubeRunner) (pods []string, err error)
GetPods fetches the pods based on the provided labels
func GetRunningPods ¶
func GetRunningPods(k KubeRunner) (pods []string, err error)
GetRunningPods fetches the pods which are running based on the provided labels
Sample code to do this:
$ JSONPATH='{range .items[*]}{@.metadata.name}::{@.status.containerStatuses[*].ready}::::{end}' && kubectl get po -n kube-system -o jsonpath="$JSONPATH" kube-addon-manager-amit-thinkpad-l470::true::::kube-dns-54cccfbdf8-q7v2c::false false true::::kubernetes-dashboard-77d8b98585-cwbjq::false::::storage-provisioner::true::::tiller-deploy-5b48764ff7-g9qz7::true::::
func IsPodRunning ¶
func IsPodRunning(k KubeRunner, name string) (yes bool, err error)
IsPodRunning returns true if the specified pod is running, false otherwise
An example of kubectl get pods & its state:
This makes use of status.containerStatuses[*].state.*.reason
$ kubectl get po -n kube-system my-pod -o jsonpath='{.status.containerStatuses[*].state.*.reason}' CrashLoopBackOff CrashLoopBackOff
Another example of kubectl get pods & its state:
This makes use of status.containerStatuses[*].ready
$ kubectl get pods -n kube-system my-pod -o jsonpath='{.status.containerStatuses[*].ready}' true false true
Types ¶
type KubeRunner ¶
type KubeRunner interface { // Run executes the kubectl command Run(args []string) (output string, err error) }
KubeRunner interface provides the contract i.e. method signature to invoke commands at kubernetes cluster
type Kubectl ¶
type Kubectl struct {
// contains filtered or unexported fields
}
Kubectl holds the properties required to execute any kubectl command. Kubectl is an implementation of following interfaces: 1. KubeRunner
type KubectlFile ¶
type KubectlFile string
KubectlFile is the type to hold various yaml file paths that can be applied by kubectl
type MockKubeCtlRunner ¶
type MockKubeCtlRunner struct {
// contains filtered or unexported fields
}
MockKubeCtlRunner is a mock of KubeCtlRunner interface
func NewMockKubeCtlRunner ¶
func NewMockKubeCtlRunner(ctrl *gomock.Controller) *MockKubeCtlRunner
NewMockKubeCtlRunner creates a new mock instance
func (*MockKubeCtlRunner) EXPECT ¶
func (m *MockKubeCtlRunner) EXPECT() *MockKubeCtlRunnerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockKubeCtlRunnerMockRecorder ¶
type MockKubeCtlRunnerMockRecorder struct {
// contains filtered or unexported fields
}
MockKubeCtlRunnerMockRecorder is the mock recorder for MockKubeCtlRunner
func (*MockKubeCtlRunnerMockRecorder) Run ¶
func (mr *MockKubeCtlRunnerMockRecorder) Run(args interface{}) *gomock.Call
Run indicates an expected call of Run
type MockKubeRunner ¶
type MockKubeRunner struct {
// contains filtered or unexported fields
}
MockKubeRunner is a mock of KubeRunner interface
func NewMockKubeRunner ¶
func NewMockKubeRunner(ctrl *gomock.Controller) *MockKubeRunner
NewMockKubeRunner creates a new mock instance
func (*MockKubeRunner) EXPECT ¶
func (m *MockKubeRunner) EXPECT() *MockKubeRunnerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockKubeRunnerMockRecorder ¶
type MockKubeRunnerMockRecorder struct {
// contains filtered or unexported fields
}
MockKubeRunnerMockRecorder is the mock recorder for MockKubeRunner
func (*MockKubeRunnerMockRecorder) Run ¶
func (mr *MockKubeRunnerMockRecorder) Run(args interface{}) *gomock.Call
Run indicates an expected call of Run