kubectl

package
v0.0.0-...-6ebe776 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Apply

func Apply(namespace string, yamlFilePath string) error

Apply updates the resource using kubectl command

func Create

func Create(namespace string, yamlFilePath string) error

Create creates the resource using kubectl command

func CreateNamespace

func CreateNamespace(name string) error

CreateNamespace create the namespace using kubectl command

func CreateSecretFromLiteral

func CreateSecretFromLiteral(namespace string, secretName string, literalValues map[string]string) error

CreateSecretFromLiteral creates a generic type secret using kubectl command

func Delete

func Delete(namespace string, yamlFilePath string) error

Delete creates the resource using kubectl command

func DeleteLabelFilter

func DeleteLabelFilter(namespace string, resourceName string, labelName string) error

DeleteLabelFilter deletes the resource based on label using kubectl command

func DeleteNamespace

func DeleteNamespace(ns string) error

DeleteNamespace removes existing ns

func DeleteResource

func DeleteResource(namespace string, resourceName string, name string) error

DeleteResource deletes the resource using kubectl command

func DeleteSecret

func DeleteSecret(namespace string, secretName string) error

DeleteSecret deletes the namespace using kubectl command

func DeleteWebhooks

func DeleteWebhooks(ns string, name string) error

DeleteWebhooks removes existing webhookconfiguration and validatingwebhookconfiguration

func GetData

func GetData(namespace string, resourceName string, name string, templatePath string) ([]byte, error)

GetData fetches the specified output by the given templatePath

func GetObject

func GetObject(name, namespace, resourceType string, obj interface{}) (err error)

func HelmBinaryVersion

func HelmBinaryVersion() (string, error)

HelmBinaryVersion executes helm version and return 2 or 3

func PatchNamespace

func PatchNamespace(name string, patch string) error

PatchNamespace patche the namespace resource using kubectl command

func Run

func Run(s ...string) (string, error)

Run allow to control kubectl directly

func RunCommandWithOutput

func RunCommandWithOutput(namespace string, podName string, commandInPod string) (string, error)

RunCommandWithOutput runs the command specified in the container and returns output

func RunHelmBinaryWithCustomErr

func RunHelmBinaryWithCustomErr(args ...string) error

RunHelmBinaryWithCustomErr executes a desire binary

func RunHelmBinaryWithOutput

func RunHelmBinaryWithOutput(args ...string) (string, error)

RunHelmBinaryWithOutput executes a desired binary and returns the output

func RunWithoutErr

func RunWithoutErr(s ...string) (string, error)

RunWithoutErr allow to control kubectl directly but without any StdErr

func SecretCheckData

func SecretCheckData(namespace string, secretName string, fieldPath string) error

SecretCheckData checks the field specified in the given field

Types

type ClusterCrd

type ClusterCrd struct {
	Items []struct {
		APIVersion string `json:"apiVersion"`
		Kind       string `json:"kind"`
		Metadata   struct {
			Name string `json:"name"`
		} `json:"metadata"`
	} `json:"items"`
}

ClusterCrd defines a list of CRDs

func GetCRDs

func GetCRDs() (*ClusterCrd, error)

GetCRDs returns all CRDs

func (*ClusterCrd) ContainsElement

func (c *ClusterCrd) ContainsElement(element string) bool

ContainsElement verify if a CRD exist

type ConfigMap

type ConfigMap struct {
	APIVersion string `json:"apiVersion" yaml:"apiVersion"`
	Kind       string `json:"kind" yaml:"kind"`
	Metadata   struct {
		Name string `json:"name" yaml:"name"`
	} `json:"metadata" yaml:"metadata"`
	Data map[string]string `json:"data" yaml:"data"`
}

ConfigMap defines a kube ConfigMap

type Container

type Container struct {
	Name    string   `yaml:"name"`
	Image   string   `yaml:"image,omitempty"`
	Command []string `yaml:"command,omitempty"`
	Args    []string `yaml:"args,omitempty"`
	Env     []EnvVar `yaml:"envs,omitempty"`
}

Container is a single application container that you want to run within a pod.

type ContainerState

type ContainerState struct {
	Waiting    *ContainerStateWaiting    `yaml:"waiting,omitempty" protobuf:"bytes,1,opt,name=waiting"`
	Running    *ContainerStateRunning    `yaml:"running,omitempty" protobuf:"bytes,2,opt,name=running"`
	Terminated *ContainerStateTerminated `yaml:"terminated,omitempty" protobuf:"bytes,3,opt,name=terminated"`
}

ContainerState is the known state of a container in a pod

type ContainerStateRunning

type ContainerStateRunning struct {
	StartedAt time.Time `yaml:"startedAt,omitempty"`
}

ContainerStateRunning is a running state of a container.

type ContainerStateTerminated

type ContainerStateTerminated struct {
	ExitCode    int32     `yaml:"exitCode"`
	Signal      int32     `yaml:"signal,omitempty"`
	Reason      string    `yaml:"reason,omitempty"`
	Message     string    `yaml:"message,omitempty"`
	StartedAt   time.Time `yaml:"startedAt,omitempty"`
	FinishedAt  time.Time `yaml:"finishedAt,omitempty"`
	ContainerID string    `yaml:"containerID,omitempty"`
}

ContainerStateTerminated is a terminated state of a container.

type ContainerStateWaiting

type ContainerStateWaiting struct {
	Reason  string `yaml:"reason,omitempty"`
	Message string `yaml:"message,omitempty"`
}

ContainerStateWaiting is a waiting state of a container.

type ContainerStatus

type ContainerStatus struct {
	Name                 string         `yaml:"name"`
	State                ContainerState `yaml:"state,omitempty"`
	LastTerminationState ContainerState `yaml:"lastState,omitempty"`
	Ready                bool           `yaml:"ready"`
	RestartCount         int32          `yaml:"restartCount"`
	Image                string         `yaml:"image"`
	ImageID              string         `yaml:"imageID"`
	ContainerID          string         `yaml:"containerID,omitempty"`
	Started              *bool          `yaml:"started,omitempty"`
}

ContainerStatus contains details for the current status of this container.

type CustomError

type CustomError struct {
	Msg    string
	StdOut string
	Err    error
}

CustomError containing stdOutput of a binary execution

func (*CustomError) Error

func (e *CustomError) Error() string

type EnvVar

type EnvVar struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value,omitempty"`
}

EnvVar represents an environment variable present in a Container.

type Kubectl

type Kubectl struct {
	Log          *zap.SugaredLogger
	Namespace    string
	PollTimeout  time.Duration
	PollInterval time.Duration
}

Kubectl is used as a command to test e2e tests

func New

func New() *Kubectl

New returns a new Kubectl command

func (*Kubectl) ApplyJSON

func (k *Kubectl) ApplyJSON(namespace string, name string, v interface{}) error

ApplyJSON applies arbitrary interfaces with kubectl.

func (*Kubectl) ApplyYAML

func (k *Kubectl) ApplyYAML(namespace string, name string, v interface{}) error

ApplyYAML applies arbitrary interfaces with kubectl.

func (*Kubectl) CreateRoleBinding

func (k *Kubectl) CreateRoleBinding(namespace string, clusterrole, serviceaccount, role string) error

CreateRoleBinding Create a new rolebinding in a namespace from a cluster role

func (*Kubectl) CreateServiceAccount

func (k *Kubectl) CreateServiceAccount(namespace string, serviceaccount string) error

CreateServiceAccount Create a new serviceaccount in a namespace

func (*Kubectl) Delete

func (k *Kubectl) Delete(args ...string) error

Delete calls kubectl with the given arguments

func (*Kubectl) DeleteRoleBinding

func (k *Kubectl) DeleteRoleBinding(namespace string, role string) error

DeleteRoleBinding Deletes a rolebinding in a namespace

func (*Kubectl) DeleteServiceAccount

func (k *Kubectl) DeleteServiceAccount(namespace string, serviceaccount string) error

DeleteServiceAccount Deletes a serviceaccount in a namespace

func (*Kubectl) EventuallyPodMatch

func (k *Kubectl) EventuallyPodMatch(namespace, label string, timeout, poll time.Duration, mm gomega.OmegaMatcher)

EventuallyPodMatch uses ginkgo/gomega matcher to satisfy against a namespace/label pod

func (*Kubectl) Exists

func (k *Kubectl) Exists(namespace, resource, name string) (bool, error)

Exists returns true if the resource by that name exists

func (*Kubectl) GetConfigMap

func (k *Kubectl) GetConfigMap(namespace string, name string) (ConfigMap, error)

GetConfigMap blocks until the specified data is available. It fails after the timeout.

func (*Kubectl) GetPodNames

func (k *Kubectl) GetPodNames(namespace string, selector string) ([]string, error)

GetPodNames returns the names of the pods matching the selector

func (*Kubectl) NamespaceWithReadyPod

func (k *Kubectl) NamespaceWithReadyPod(namespace string, labelName string) (bool, error)

NamespaceWithReadyPod returns true if pods by that label are present in the given namespace

func (*Kubectl) PodExists

func (k *Kubectl) PodExists(namespace string, labelName string, podName string) (bool, error)

PodExists returns true if the pod by that label is present

func (*Kubectl) PodStatus

func (k *Kubectl) PodStatus(namespace string, podName string) (*PodStatus, error)

PodStatus returns the status if the pod by that label is present

func (*Kubectl) RunCommandWithCheckString

func (k *Kubectl) RunCommandWithCheckString(namespace string, podName string, commandInPod string, result string) error

RunCommandWithCheckString runs the command specified helper in the container

func (*Kubectl) SecretExists

func (k *Kubectl) SecretExists(namespace string, secretName string) (bool, error)

SecretExists returns true if the pod by that name is in state running

func (*Kubectl) ServiceExists

func (k *Kubectl) ServiceExists(namespace string, serviceName string) (bool, error)

ServiceExists returns true if the pod by that name is in state running

func (*Kubectl) Wait

func (k *Kubectl) Wait(namespace string, requiredStatus string, resourceName string, customTimeout time.Duration) error

Wait waits for the condition on the resource using kubectl command

func (*Kubectl) WaitForData

func (k *Kubectl) WaitForData(namespace string, resourceName string, name string, template string, expectation string) error

WaitForData blocks until the specified data is available. It fails after the timeout.

func (*Kubectl) WaitForNamespaceDelete

func (k *Kubectl) WaitForNamespaceDelete(namespace string) error

WaitForNamespaceDelete blocks while the namespace is available. It fails after the timeout.

func (*Kubectl) WaitForNamespaceWithPod

func (k *Kubectl) WaitForNamespaceWithPod(namespace string, labelName string) error

WaitForNamespaceWithPod blocks until pods matching the selector are available in the specified namespace. It fails after the timeout.

func (*Kubectl) WaitForPVC

func (k *Kubectl) WaitForPVC(namespace string, pvcName string) error

WaitForPVC blocks until the pvc is available. It fails after the timeout.

func (*Kubectl) WaitForPod

func (k *Kubectl) WaitForPod(namespace string, labelName string, podName string) error

WaitForPod blocks until the pod is available. It fails after the timeout.

func (*Kubectl) WaitForPodDelete

func (k *Kubectl) WaitForPodDelete(namespace string, podName string) error

WaitForPodDelete blocks while the pod is available. It fails after the timeout.

func (*Kubectl) WaitForSecret

func (k *Kubectl) WaitForSecret(namespace string, secretName string) error

WaitForSecret blocks until the secret is available. It fails after the timeout.

func (*Kubectl) WaitForService

func (k *Kubectl) WaitForService(namespace string, serviceName string) error

WaitForService blocks until the service is available. It fails after the timeout.

func (*Kubectl) WaitLabelFilter

func (k *Kubectl) WaitLabelFilter(namespace string, requiredStatus string, resourceName string, labelName string) error

WaitLabelFilter waits for the condition on the resource based on label using kubectl command

func (*Kubectl) WaitNamespacePodsDelete

func (k *Kubectl) WaitNamespacePodsDelete(namespace string) error

WaitNamespacePodsDelete blocks until pods are still available in the given namespace. It fails after the timeout.

type Metadata

type Metadata struct {
	Name            string            `yaml:"name"`
	GenerateName    string            `yaml:"generateName"`
	ResourceVersion string            `yaml:"resourceVersion"`
	Labels          map[string]string `yaml:"labels"`
	Annotations     map[string]string `yaml:"annotations"`
	UID             string            `yaml:"uid"`
	Namespace       string            `yaml:"namespace"`
}

Metadata is metadata attached to any object

type Pod

type Pod struct {
	APIVersion string    `yaml:"apiVersion"`
	Kind       string    `yaml:"kind,omitempty"`
	Metadata   Metadata  `yaml:"metadata"`
	Spec       PodSpec   `yaml:"spec"`
	Status     PodStatus `yaml:"status,omitempty"`
}

Pod is a collection of containers that can run on a host. This resource is created by clients and scheduled onto hosts.

type PodCondition

type PodCondition struct {
	Type string `yaml:"type"`
	// More info: https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle#pod-conditions
	Status  string `yaml:"status"`
	Reason  string `yaml:"reason,omitempty"`
	Message string `yaml:"message,omitempty"`
}

PodCondition is the pod condition status

type PodSpec

type PodSpec struct {
	Containers   []Container       `yaml:"containers"`
	NodeSelector map[string]string `yaml:"nodeSelector"`
}

PodSpec is a description of a pod.

type PodStatus

type PodStatus struct {
	Phase             string            `yaml:"phase,omitempty"`
	Conditions        []PodCondition    `yaml:"conditions,omitempty"`
	Message           string            `yaml:"message,omitempty"`
	Reason            string            `yaml:"reason,omitempty"`
	ContainerStatuses []ContainerStatus `yaml:"containerStatuses,omitempty" protobuf:"bytes,8,rep,name=containerStatuses"`
}

PodStatus has all the pod status information

Jump to

Keyboard shortcuts

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