k8s

package
v0.16.15 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 49 Imported by: 0

Documentation

Overview

Package k8s provides various helper functions for interacting with Kubernetes APIs.

IMPORTANT: Please note that the APIs of this package might change without any notice until cilium-cli reaches v1.0.0.

Index

Constants

This section is empty.

Variables

View Source
var ErrKVStoreMeshStatusNotImplemented = errors.New("kvstoremesh-dbg status is not available")

KVStoreMeshStatusNotImplemented is a sentinel error to signal that the status command is not implemented.

Functions

func NewClusterRoleBinding

func NewClusterRoleBinding(name, namespace, serviceAccount string) *rbacv1.ClusterRoleBinding

func NewIngressClass

func NewIngressClass(name, controllerName string) *networkingv1.IngressClass

func NewSecret

func NewSecret(name, namespace string, data map[string][]byte) *corev1.Secret

func NewServiceAccount

func NewServiceAccount(name string) *corev1.ServiceAccount

func NewTLSSecret

func NewTLSSecret(name, namespace string, data map[string][]byte) *corev1.Secret

NewTLSSecret return a Secret of the type kubernetes.io/tls. Note that for this kind of Secret, both tls.key and tls.crt are required in data.

Types

type Client

type Client struct {
	Clientset          kubernetes.Interface
	ExtensionClientset apiextensionsclientset.Interface // k8s api extension needed to retrieve CRDs
	DynamicClientset   dynamic.Interface
	CiliumClientset    ciliumClientset.Interface
	Config             *rest.Config
	RawConfig          clientcmdapi.Config
	RESTClientGetter   genericclioptions.RESTClientGetter

	HelmActionConfig *action.Configuration
	// contains filtered or unexported fields
}

func NewClient

func NewClient(contextName, kubeconfig, ciliumNamespace string) (*Client, error)

func (*Client) AutodetectFlavor

func (c *Client) AutodetectFlavor(ctx context.Context) Flavor

func (*Client) CheckDaemonSetStatus added in v0.15.20

func (c *Client) CheckDaemonSetStatus(ctx context.Context, namespace, deployment string) error

func (*Client) CheckDeploymentStatus

func (c *Client) CheckDeploymentStatus(ctx context.Context, namespace, deployment string) error

func (*Client) CiliumDbgEndpoints added in v0.16.0

func (c *Client) CiliumDbgEndpoints(ctx context.Context, namespace, pod string) ([]*models.Endpoint, error)

func (*Client) CiliumLogs

func (c *Client) CiliumLogs(ctx context.Context, namespace, pod string, since time.Time) (string, error)

func (*Client) CiliumStatus

func (c *Client) CiliumStatus(ctx context.Context, namespace, pod string) (*models.StatusResponse, error)

func (*Client) ClusterName

func (c *Client) ClusterName() (name string)

ClusterName returns the name of the cluster the client is connected to

func (*Client) ContextName

func (c *Client) ContextName() (name string)

ContextName returns the name of the context the client is connected to

func (*Client) CopyFromPod

func (c *Client) CopyFromPod(ctx context.Context, namespace, pod, container, fromFile, destFile string, retryLimit int) error

CopyFromPod is to copy srcFile in a given pod to local destFile with defaultMaxTries.

func (*Client) CreateConfigMap

func (c *Client) CreateConfigMap(ctx context.Context, namespace string, config *corev1.ConfigMap, opts metav1.CreateOptions) (*corev1.ConfigMap, error)

func (*Client) CreateDaemonSet

func (c *Client) CreateDaemonSet(ctx context.Context, namespace string, ds *appsv1.DaemonSet, opts metav1.CreateOptions) (*appsv1.DaemonSet, error)

func (*Client) CreateDeployment

func (c *Client) CreateDeployment(ctx context.Context, namespace string, deployment *appsv1.Deployment, opts metav1.CreateOptions) (*appsv1.Deployment, error)

func (*Client) CreateEphemeralContainer added in v0.12.0

func (c *Client) CreateEphemeralContainer(ctx context.Context, pod *corev1.Pod, ec *corev1.EphemeralContainer) (*corev1.Pod, error)

CreateEphemeralContainer will create a EphemeralContainer (debug container) in the specified pod. EphemeralContainers are special containers which can be added after-the-fact in running pods. They're useful for debugging, either when the target container image doesn't have necessary tools, or because the pod has no running containers due to a crash.

see https://kubernetes.io/docs/concepts/workloads/pods/ephemeral-containers/

EphemeralContainers were added in there current form (behind a feature gate) in 1.22. They are scheduled for GA in v1.25.

func (*Client) CreateIngress added in v0.14.1

func (c *Client) CreateIngress(ctx context.Context, namespace string, ingress *networkingv1.Ingress, opts metav1.CreateOptions) (*networkingv1.Ingress, error)

func (*Client) CreateNamespace

func (c *Client) CreateNamespace(ctx context.Context, namespace *corev1.Namespace, opts metav1.CreateOptions) (*corev1.Namespace, error)

func (*Client) CreatePod added in v0.12.0

func (c *Client) CreatePod(ctx context.Context, namespace string, pod *corev1.Pod, opts metav1.CreateOptions) (*corev1.Pod, error)

func (*Client) CreateSecret

func (c *Client) CreateSecret(ctx context.Context, namespace string, secret *corev1.Secret, opts metav1.CreateOptions) (*corev1.Secret, error)

func (*Client) CreateService

func (c *Client) CreateService(ctx context.Context, namespace string, service *corev1.Service, opts metav1.CreateOptions) (*corev1.Service, error)

func (*Client) CreateServiceAccount

func (c *Client) CreateServiceAccount(ctx context.Context, namespace string, account *corev1.ServiceAccount, opts metav1.CreateOptions) (*corev1.ServiceAccount, error)

func (*Client) DeleteCiliumClusterwideNetworkPolicy

func (c *Client) DeleteCiliumClusterwideNetworkPolicy(ctx context.Context, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteCiliumEgressGatewayPolicy added in v0.14.2

func (c *Client) DeleteCiliumEgressGatewayPolicy(ctx context.Context, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteCiliumExternalWorkload

func (c *Client) DeleteCiliumExternalWorkload(ctx context.Context, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteCiliumLocalRedirectPolicy added in v0.16.10

func (c *Client) DeleteCiliumLocalRedirectPolicy(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteCiliumNetworkPolicy

func (c *Client) DeleteCiliumNetworkPolicy(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteConfigMap

func (c *Client) DeleteConfigMap(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteDeployment

func (c *Client) DeleteDeployment(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteKubernetesNetworkPolicy added in v0.14.0

func (c *Client) DeleteKubernetesNetworkPolicy(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteNamespace

func (c *Client) DeleteNamespace(ctx context.Context, namespace string, opts metav1.DeleteOptions) error

func (*Client) DeletePod

func (c *Client) DeletePod(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeletePodCollection

func (c *Client) DeletePodCollection(ctx context.Context, namespace string, opts metav1.DeleteOptions, listOpts metav1.ListOptions) error

func (*Client) DeleteSecret

func (c *Client) DeleteSecret(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteService

func (c *Client) DeleteService(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) DeleteServiceAccount

func (c *Client) DeleteServiceAccount(ctx context.Context, namespace, name string, opts metav1.DeleteOptions) error

func (*Client) ExecInPod

func (c *Client) ExecInPod(ctx context.Context, namespace, pod, container string, command []string) (bytes.Buffer, error)

func (*Client) ExecInPodWithStderr

func (c *Client) ExecInPodWithStderr(ctx context.Context, namespace, pod, container string, command []string) (bytes.Buffer, bytes.Buffer, error)

func (*Client) ExecInPodWithWriters added in v0.12.12

func (c *Client) ExecInPodWithWriters(connCtx, killCmdCtx context.Context, namespace, pod, container string, command []string, stdout, stderr io.Writer) error

func (*Client) GetAPIServerHostAndPort added in v0.12.2

func (c *Client) GetAPIServerHostAndPort() (string, string)

func (*Client) GetCRD added in v0.14.0

func (*Client) GetCiliumExternalWorkload

func (c *Client) GetCiliumExternalWorkload(ctx context.Context, name string, opts metav1.GetOptions) (*ciliumv2.CiliumExternalWorkload, error)

func (*Client) GetCiliumLocalRedirectPolicy added in v0.16.14

func (c *Client) GetCiliumLocalRedirectPolicy(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*ciliumv2.CiliumLocalRedirectPolicy, error)

func (*Client) GetCiliumVersion added in v0.12.12

func (c *Client) GetCiliumVersion(ctx context.Context, p *corev1.Pod) (*semver.Version, error)

GetCiliumVersion returns a semver.Version representing the version of cilium running in the cilium-agent pod

func (*Client) GetClusterRole added in v0.13.2

func (c *Client) GetClusterRole(ctx context.Context, name string, opts metav1.GetOptions) (*rbacv1.ClusterRole, error)

func (*Client) GetConfigMap

func (c *Client) GetConfigMap(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.ConfigMap, error)

func (*Client) GetCronJob added in v0.16.5

func (c *Client) GetCronJob(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*batchv1.CronJob, error)

func (*Client) GetDaemonSet

func (c *Client) GetDaemonSet(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*appsv1.DaemonSet, error)

func (*Client) GetDeployment

func (c *Client) GetDeployment(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*appsv1.Deployment, error)

func (*Client) GetEndpoints added in v0.12.7

func (c *Client) GetEndpoints(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Endpoints, error)

func (*Client) GetHelmMetadata added in v0.16.5

func (c *Client) GetHelmMetadata(_ context.Context, releaseName string, namespace string) (string, error)

GetHelmMetadata is the function for cilium cli sysdump to collect the helm metadata from the release directly

func (*Client) GetHelmValues added in v0.15.7

func (c *Client) GetHelmValues(_ context.Context, releaseName string, namespace string) (string, error)

GetHelmValues is the function for cilium cli sysdump to collect the helm values from the release directly

func (*Client) GetIngress added in v0.14.1

func (c *Client) GetIngress(ctx context.Context, namespace string, name string, opts metav1.GetOptions) (*networkingv1.Ingress, error)

func (*Client) GetLogs

func (c *Client) GetLogs(ctx context.Context, namespace, name, container string, opts corev1.PodLogOptions) (string, error)

func (*Client) GetNamespace

func (c *Client) GetNamespace(ctx context.Context, namespace string, options metav1.GetOptions) (*corev1.Namespace, error)

func (*Client) GetNode added in v0.14.6

func (c *Client) GetNode(ctx context.Context, name string, opts metav1.GetOptions) (*corev1.Node, error)

func (*Client) GetPod added in v0.12.0

func (c *Client) GetPod(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Pod, error)

func (*Client) GetPodsTable

func (c *Client) GetPodsTable(_ context.Context) (*metav1.Table, error)

func (*Client) GetRaw added in v0.15.8

func (c *Client) GetRaw(ctx context.Context, path string) (string, error)

func (*Client) GetRunningCiliumVersion

func (c *Client) GetRunningCiliumVersion(ciliumHelmReleaseName string) (string, error)

func (*Client) GetSecret

func (c *Client) GetSecret(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Secret, error)

func (*Client) GetServerVersion

func (c *Client) GetServerVersion() (*semver.Version, error)

func (*Client) GetService

func (c *Client) GetService(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.Service, error)

func (*Client) GetServiceAccount added in v0.16.14

func (c *Client) GetServiceAccount(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*corev1.ServiceAccount, error)

func (*Client) GetStatefulSet added in v0.14.8

func (c *Client) GetStatefulSet(ctx context.Context, namespace, name string, opts metav1.GetOptions) (*appsv1.StatefulSet, error)

func (*Client) GetVersion

func (c *Client) GetVersion(_ context.Context) (string, error)

func (*Client) KVStoreMeshStatus added in v0.16.8

func (c *Client) KVStoreMeshStatus(ctx context.Context, namespace, pod string) ([]*models.RemoteCluster, error)

func (*Client) ListCiliumBGPPeeringPolicies added in v0.12.13

func (c *Client) ListCiliumBGPPeeringPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumBGPPeeringPolicyList, error)

func (*Client) ListCiliumCIDRGroups added in v0.14.4

func (c *Client) ListCiliumCIDRGroups(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumCIDRGroupList, error)

func (*Client) ListCiliumClusterwideEnvoyConfigs added in v0.11.5

func (c *Client) ListCiliumClusterwideEnvoyConfigs(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumClusterwideEnvoyConfigList, error)

func (*Client) ListCiliumClusterwideNetworkPolicies

func (c *Client) ListCiliumClusterwideNetworkPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumClusterwideNetworkPolicyList, error)

func (*Client) ListCiliumEgressGatewayPolicies added in v0.12.9

func (c *Client) ListCiliumEgressGatewayPolicies(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumEgressGatewayPolicyList, error)

func (*Client) ListCiliumEndpointSlices added in v0.14.0

func (c *Client) ListCiliumEndpointSlices(ctx context.Context, options metav1.ListOptions) (*ciliumv2alpha1.CiliumEndpointSliceList, error)

func (*Client) ListCiliumEndpoints

func (c *Client) ListCiliumEndpoints(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2.CiliumEndpointList, error)

func (*Client) ListCiliumEnvoyConfigs added in v0.11.5

func (c *Client) ListCiliumEnvoyConfigs(ctx context.Context, namespace string, options metav1.ListOptions) (*ciliumv2.CiliumEnvoyConfigList, error)

func (*Client) ListCiliumExternalWorkloads

func (c *Client) ListCiliumExternalWorkloads(ctx context.Context, opts metav1.ListOptions) (*ciliumv2.CiliumExternalWorkloadList, error)

func (*Client) ListCiliumIdentities

func (c *Client) ListCiliumIdentities(ctx context.Context) (*ciliumv2.CiliumIdentityList, error)

func (*Client) ListCiliumLoadBalancerIPPools added in v0.12.13

func (c *Client) ListCiliumLoadBalancerIPPools(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumLoadBalancerIPPoolList, error)

func (*Client) ListCiliumLocalRedirectPolicies

func (c *Client) ListCiliumLocalRedirectPolicies(ctx context.Context, namespace string, opts metav1.ListOptions) (*ciliumv2.CiliumLocalRedirectPolicyList, error)

func (*Client) ListCiliumNetworkPolicies

func (c *Client) ListCiliumNetworkPolicies(ctx context.Context, namespace string, opts metav1.ListOptions) (*ciliumv2.CiliumNetworkPolicyList, error)

func (*Client) ListCiliumNodeConfigs added in v0.12.13

func (c *Client) ListCiliumNodeConfigs(ctx context.Context, namespace string, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumNodeConfigList, error)

func (*Client) ListCiliumNodes

func (c *Client) ListCiliumNodes(ctx context.Context) (*ciliumv2.CiliumNodeList, error)

func (*Client) ListCiliumPodIPPools added in v0.14.8

func (c *Client) ListCiliumPodIPPools(ctx context.Context, opts metav1.ListOptions) (*ciliumv2alpha1.CiliumPodIPPoolList, error)

func (*Client) ListDaemonSet

func (c *Client) ListDaemonSet(ctx context.Context, namespace string, o metav1.ListOptions) (*appsv1.DaemonSetList, error)

func (*Client) ListEndpoints added in v0.11.1

func (c *Client) ListEndpoints(ctx context.Context, o metav1.ListOptions) (*corev1.EndpointsList, error)

func (*Client) ListEvents

func (c *Client) ListEvents(ctx context.Context, o metav1.ListOptions) (*corev1.EventList, error)

func (*Client) ListIngressClasses added in v0.14.4

func (c *Client) ListIngressClasses(ctx context.Context, o metav1.ListOptions) (*networkingv1.IngressClassList, error)

func (*Client) ListIngresses added in v0.11.5

func (c *Client) ListIngresses(ctx context.Context, o metav1.ListOptions) (*networkingv1.IngressList, error)

func (*Client) ListNamespaces

func (c *Client) ListNamespaces(ctx context.Context, o metav1.ListOptions) (*corev1.NamespaceList, error)

func (*Client) ListNetworkPolicies

func (c *Client) ListNetworkPolicies(ctx context.Context, o metav1.ListOptions) (*networkingv1.NetworkPolicyList, error)

func (*Client) ListNodes

func (c *Client) ListNodes(ctx context.Context, options metav1.ListOptions) (*corev1.NodeList, error)

func (*Client) ListPods

func (c *Client) ListPods(ctx context.Context, namespace string, options metav1.ListOptions) (*corev1.PodList, error)

func (*Client) ListServices

func (c *Client) ListServices(ctx context.Context, namespace string, options metav1.ListOptions) (*corev1.ServiceList, error)

func (*Client) ListUnstructured

func (c *Client) ListUnstructured(ctx context.Context, gvr schema.GroupVersionResource, namespace *string, o metav1.ListOptions) (*unstructured.UnstructuredList, error)

func (*Client) PatchConfigMap

func (c *Client) PatchConfigMap(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*corev1.ConfigMap, error)

func (*Client) PatchDaemonSet

func (c *Client) PatchDaemonSet(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*appsv1.DaemonSet, error)

func (*Client) PatchNode added in v0.12.2

func (c *Client) PatchNode(ctx context.Context, nodeName string, pt types.PatchType, data []byte) (*corev1.Node, error)

func (*Client) PatchSecret

func (c *Client) PatchSecret(ctx context.Context, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*corev1.Secret, error)

func (*Client) PodLogs

func (c *Client) PodLogs(namespace, name string, opts *corev1.PodLogOptions) *rest.Request

func (*Client) PortForward added in v0.14.4

PortForward executes in a goroutine a port forward command. To stop the port-forwarding, use the context by cancelling it

func (*Client) ProxyGet added in v0.15.8

func (c *Client) ProxyGet(ctx context.Context, namespace, name, url string) (string, error)

func (*Client) ProxyTCP added in v0.16.8

func (c *Client) ProxyTCP(ctx context.Context, namespace, name string, port uint16, handler func(io.ReadWriteCloser) error) error

func (*Client) UpdateSecret

func (c *Client) UpdateSecret(ctx context.Context, namespace string, secret *corev1.Secret, opts metav1.UpdateOptions) (*corev1.Secret, error)

type CopyOptions

type CopyOptions struct {
	// Maximum number of retries, -1 for unlimited retries.
	MaxTries int

	// ReaderFunc is the actual implementation for reading file content
	ReadFunc ReadFunc
}

CopyOptions have the data required to perform the copy operation

type CopyPipe

type CopyPipe struct {
	Options *CopyOptions

	Reader *io.PipeReader
	Writer *io.PipeWriter
	// contains filtered or unexported fields
}

CopyPipe struct is simple implementation to support copy files with retry.

func (*CopyPipe) Read

func (t *CopyPipe) Read(p []byte) (int, error)

Read function is to satisfy io.Reader interface. This is simple implementation to support resuming copy in case of there is any temporary issue (e.g. networking)

type ExecParameters

type ExecParameters struct {
	Namespace string
	Pod       string
	Container string
	Command   []string
	TTY       bool // fuses stderr into stdout if 'true', needed for Ctrl-C support
}

type ExecResult

type ExecResult struct {
	Stdout bytes.Buffer
	Stderr bytes.Buffer
}

type Flavor

type Flavor struct {
	ClusterName string
	Kind        Kind
}

type ForwardedPort added in v0.14.4

type ForwardedPort struct {
	Local  uint16
	Remote uint16
}

ForwardedPort holds the remote and local mapped port.

type Kind

type Kind int
const (
	KindUnknown Kind = iota
	KindMinikube
	KindKind
	KindEKS
	KindGKE
	KindAKS
	KindMicrok8s
	KindRancherDesktop
	KindK3s
)

func (Kind) String

func (k Kind) String() string

type OutWriters added in v0.14.4

type OutWriters struct {
	Out    io.Writer
	ErrOut io.Writer
}

OutWriters holds the two io.Writer needed for the port forward one for the output and for the errors.

type Platform

type Platform struct {
	OS   string
	Arch string
}

type PortForwardParameters added in v0.14.4

type PortForwardParameters struct {
	Namespace  string
	Pod        string
	Ports      []string
	Addresses  []string
	OutWriters OutWriters
}

PortForwardParameters are the needed parameters to call PortForward. Ports value follow the kubectl syntax: <local-port>:<remote-port> 5000 means 5000:5000 listening on 5000 port locally, forwarding to 5000 in the pod 8888:5000 means listening on 8888 port locally, forwarding to 5000 in the pod 0:5000 means listening on a random port locally, forwarding to 5000 in the pod :5000 means listening on a random port locally, forwarding to 5000 in the pod

type PortForwardResult added in v0.14.4

type PortForwardResult struct {
	ForwardedPorts []ForwardedPort
}

PortForwardResult are the ports that have been forwarded.

type ReadFunc

type ReadFunc func(offset uint64, writer io.Writer) error

ReadFunc function is to support reading content from given offset till EOF. The content will be written to io.Writer.

type ResourceClient added in v0.16.12

type ResourceClient[T any] interface {
	Create(ctx context.Context, r *T, opts metav1.CreateOptions) (*T, error)
	Update(ctx context.Context, r *T, opts metav1.UpdateOptions) (*T, error)
	Delete(ctx context.Context, name string, opts metav1.DeleteOptions) error
	Get(ctx context.Context, name string, opts metav1.GetOptions) (*T, error)
}

ResourceClient is a common client interface for typed k8s resource clients.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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