k8s

package
v1.17.0-pre.3 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 50 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, impersonateAs string, impersonateGroup []string) (*Client, error)

func (*Client) ApplyGeneric

func (c *Client) ApplyGeneric(ctx context.Context, obj Object) (*unstructured.Unstructured, error)

ApplyGeneric uses server-side apply to merge changes to an arbitrary object. Returns the applied object.

func (*Client) AutodetectFlavor

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

func (*Client) CheckDaemonSetStatus

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

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, previous bool) (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

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

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

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

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

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) DeleteGeneric

func (c *Client) DeleteGeneric(ctx context.Context, obj Object) error

func (*Client) DeleteKubernetesNetworkPolicy

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) Describe

func (c *Client) Describe(obj runtime.Object) (gvk schema.GroupVersionKind, resource schema.GroupVersionResource, err error)

Describe returns the Kubernetes type and resource information for an object

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

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

func (*Client) GetAPIServerHostAndPort

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

func (*Client) GetCRD

func (*Client) GetCiliumExternalWorkload

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

func (*Client) GetCiliumLocalRedirectPolicy

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

func (*Client) GetCiliumVersion

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

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

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

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

func (*Client) GetGeneric

func (c *Client) GetGeneric(ctx context.Context, namespace, name string, obj Object) (*unstructured.Unstructured, error)

func (*Client) GetHelmMetadata

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

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

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

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

func (*Client) GetPod

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

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

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

func (*Client) GetStatefulSet

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

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

func (*Client) ListCiliumBGPAdvertisements

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

func (*Client) ListCiliumBGPClusterConfigs

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

func (*Client) ListCiliumBGPNodeConfigOverrides

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

func (*Client) ListCiliumBGPNodeConfigs

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

func (*Client) ListCiliumBGPPeerConfigs

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

func (*Client) ListCiliumBGPPeeringPolicies

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

func (*Client) ListCiliumCIDRGroups

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

func (*Client) ListCiliumClusterwideEnvoyConfigs

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

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

func (*Client) ListCiliumEndpointSlices

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

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

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

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

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) ListEndpointSlices

func (c *Client) ListEndpointSlices(ctx context.Context, o metav1.ListOptions) (*discoveryv1.EndpointSliceList, error)

func (*Client) ListEndpoints

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

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

func (*Client) ListIngresses

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

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

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

func (*Client) PortForwardService

func (c *Client) PortForwardService(ctx context.Context, namespace, name string, localPort, svcPort int32) (*k8s.PortForwardServiceResult, error)

PortForwardService executes in a goroutine a port forward command towards one of the pod behind a service. If `localPort` is 0, a random port is selected. If `svcPort` is 0, uses the first port configured on the service.

To stop the port-forwarding, use the context by cancelling it.

func (*Client) ProxyGet

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

func (*Client) ProxyTCP

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 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 Object

type Object interface {
	metav1.Object
	runtime.Object
}

type Platform

type Platform struct {
	OS   string
	Arch string
}

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

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