kubectl

package
v0.0.0-...-2a0142f Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package kubectl is a generated GoMock package.

Index

Constants

View Source
const (
	// DefaultLitmusNamespace is the default namespace where kubectl operations
	// will be executed
	DefaultLitmusNamespace = "litmus"
)
View Source
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 IsPod

func IsPod(kind string) (yes bool)

IsPod flags if the provided kind is a kubernetes pod or is related to a pod

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

func New

func New() *Kubectl

New returns a new instance of kubectl based on defaults

func (*Kubectl) Args

func (k *Kubectl) Args(args []string) *Kubectl

Args sets the args to be used during kubectl run

func (*Kubectl) Context

func (k *Kubectl) Context(context string) *Kubectl

Context sets the context to be used during kubectl run

func (*Kubectl) Labels

func (k *Kubectl) Labels(labels string) *Kubectl

Labels sets the labels to be used during kubectl run

func (*Kubectl) Namespace

func (k *Kubectl) Namespace(namespace string) *Kubectl

Namespace sets the namespace to be used during kubectl run

func (*Kubectl) Run

func (k *Kubectl) Run(args []string) (output string, err error)

Run will execute the kubectl command & provide output or error

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

EXPECT returns an object that allows the caller to indicate expected use

func (*MockKubeCtlRunner) Run

func (m *MockKubeCtlRunner) Run(args []string) (string, error)

Run mocks base method

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

EXPECT returns an object that allows the caller to indicate expected use

func (*MockKubeRunner) Run

func (m *MockKubeRunner) Run(args []string) (string, error)

Run mocks base method

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

Jump to

Keyboard shortcuts

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