client

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: MIT Imports: 40 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TempDebugManifest    = "tmp-manifest-%s.yaml"
	K8sStatePollInterval = 2 * time.Second
	JobFinalizedTimeout  = 2 * time.Minute
	AppLabel             = "app"
)

Variables

This section is empty.

Functions

func ExecCmd

func ExecCmd(command string) error

func ExecCmdWithOptions

func ExecCmdWithOptions(command string, outputFunction func(string)) error

func GetLocalK8sDeps

func GetLocalK8sDeps() (*kubernetes.Clientset, *rest.Config, error)

GetLocalK8sDeps get local k8s context config

Types

type Chaos

type Chaos struct {
	Client         *K8sClient
	ResourceByName map[string]string
	Namespace      string
}

Chaos is controller that manages Chaosmesh CRD instances to run experiments

func NewChaos

func NewChaos(client *K8sClient, namespace string) *Chaos

NewChaos creates controller to run and stop chaos experiments

func (*Chaos) Run

func (c *Chaos) Run(app cdk8s.App, id string, resource string) (string, error)

Run runs experiment and saves its ID

func (*Chaos) Stop

func (c *Chaos) Stop(id string) error

Stop removes a chaos experiment

func (*Chaos) WaitForAllRecovered

func (c *Chaos) WaitForAllRecovered(id string) error

type ChaosState

type ChaosState struct {
	ChaosDetails v1alpha1.ChaosStatus `json:"status"`
}

type ConnectionInfo

type ConnectionInfo struct {
	Ports portforward.ForwardedPort
	Host  string
}

type ConnectionMode

type ConnectionMode int
const (
	LocalConnection ConnectionMode = iota
	RemoteConnection
)

type Forwarder

type Forwarder struct {
	Client *K8sClient

	KeepConnection bool
	Info           map[string]interface{}
	// contains filtered or unexported fields
}

func NewForwarder

func NewForwarder(client *K8sClient, keepConnection bool) *Forwarder

func (*Forwarder) Connect

func (m *Forwarder) Connect(namespaceName string, selector string, insideK8s bool) error

func (*Forwarder) FindPort

func (m *Forwarder) FindPort(ks ...string) *URLConverter

func (*Forwarder) PrintLocalPorts

func (m *Forwarder) PrintLocalPorts()

PrintLocalPorts prints all local forwarded ports

type K8sClient

type K8sClient struct {
	ClientSet  *kubernetes.Clientset
	RESTConfig *rest.Config
}

K8sClient high level k8s client

func NewK8sClient

func NewK8sClient() *K8sClient

NewK8sClient creates a new k8s client with a REST config

func (*K8sClient) AddLabel

func (m *K8sClient) AddLabel(namespace string, selector string, label string) error

AddLabel adds a new label to a group of pods defined by selector

func (*K8sClient) AddPodAnnotation

func (m *K8sClient) AddPodAnnotation(namespace string, pod v1.Pod, key, value string) error

AddPodAnnotation adds an annotation to a pod

func (*K8sClient) AddPodLabel

func (m *K8sClient) AddPodLabel(namespace string, pod v1.Pod, key, value string) error

AddPodLabel adds a label to a pod

func (*K8sClient) AddPodsAnnotations

func (m *K8sClient) AddPodsAnnotations(namespace, labelSelector string, annotations map[string]string) error

AddPodsAnnotations adds map of annotations to all pods selected by selector

func (*K8sClient) Apply

func (m *K8sClient) Apply(manifest string) error

Apply applying a manifest to a currently connected k8s context

func (*K8sClient) CopyToPod

func (m *K8sClient) CopyToPod(namespace, src, destination, containername string) (*bytes.Buffer, *bytes.Buffer, *bytes.Buffer, error)

CopyToPod copies src to a particular container. Destination should be in the form of a proper K8s destination path NAMESPACE/POD_NAME:folder/FILE_NAME

func (*K8sClient) Create

func (m *K8sClient) Create(manifest string) error

Create creating a manifest to a currently connected k8s context

func (*K8sClient) DeleteResource

func (m *K8sClient) DeleteResource(namespace string, resource string, instance string) error

DeleteResource deletes resource

func (*K8sClient) DryRun

func (m *K8sClient) DryRun(manifest string) error

DryRun generates manifest and writes it in a file

func (*K8sClient) EnumerateInstances

func (m *K8sClient) EnumerateInstances(namespace string, selector string) error

EnumerateInstances enumerate pods with instance label

func (*K8sClient) ExecuteInPod

func (m *K8sClient) ExecuteInPod(namespace, podName, containerName string, command []string) ([]byte, []byte, error)

ExecuteInPod is similar to kubectl exec

func (*K8sClient) LabelChaosGroup

func (m *K8sClient) LabelChaosGroup(namespace string, startInstance int, endInstance int, group string) error

func (*K8sClient) LabelChaosGroupByLabels

func (m *K8sClient) LabelChaosGroupByLabels(namespace string, labels map[string]string, group string) error

func (*K8sClient) ListNamespaces

func (m *K8sClient) ListNamespaces(selector string) (*v1.NamespaceList, error)

ListNamespaces lists k8s namespaces

func (*K8sClient) ListPods

func (m *K8sClient) ListPods(namespace, selector string) (*v1.PodList, error)

ListPods lists pods for a namespace and selector

func (*K8sClient) NamespaceExists

func (m *K8sClient) NamespaceExists(namespace string) bool

NamespaceExists check if namespace exists

func (*K8sClient) RemoveNamespace

func (m *K8sClient) RemoveNamespace(namespace string) error

RemoveNamespace removes namespace

func (*K8sClient) RolloutRestartBySelector

func (m *K8sClient) RolloutRestartBySelector(namespace string, resource string, selector string) error

RolloutRestartBySelector rollouts and restarts object by selector

func (*K8sClient) RolloutStatefulSets

func (m *K8sClient) RolloutStatefulSets(namespace string) error

RolloutStatefulSets applies "rollout statefulset" to all existing statefulsets in that namespace

func (*K8sClient) UniqueLabels

func (m *K8sClient) UniqueLabels(namespace string, selector string) ([]string, error)

UniqueLabels gets all unique application labels

func (*K8sClient) WaitForJob

func (m *K8sClient) WaitForJob(namespaceName string, jobName string, fundReturnStatus func(string)) error

WaitForJob wait for job execution, follow logs and returns an error if job failed

func (*K8sClient) WaitPodsReady

func (m *K8sClient) WaitPodsReady(ns string, rcd *ReadyCheckData, expectedPodCount int) error

WaitPodsReady waits until all pods are ready

type Protocol

type Protocol int

Protocol represents a URL scheme to use when fetching connection details

const (
	// WS : Web Socket Protocol
	WS Protocol = iota
	// WSSUFFIX : Web Socket Protocol
	WSSUFFIX
	// WSS : Web Socket Secure Protocol
	WSS
	// HTTP : Hypertext Transfer Protocol
	HTTP
	// HTTPS : Hypertext Transfer Protocol Secure
	HTTPS
	POSTGRESQL
)

type ReadyCheckData

type ReadyCheckData struct {
	ReadinessProbeCheckSelector string
	Timeout                     time.Duration
}

ReadyCheckData data to check if selected pods are running and all containers are ready ( readiness check ) are ready

type URLConverter

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

URLConverter converts ports to URLs

func NewURLConverter

func NewURLConverter(fp ConnectionInfo, err error) *URLConverter

NewURLConverter creates new URLConverter instance

func (*URLConverter) As

func (m *URLConverter) As(conn ConnectionMode, proto Protocol) (string, error)

As converts host/port to an URL

Jump to

Keyboard shortcuts

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