Documentation ¶
Overview ¶
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Package k8s provides a client for interacting with a Kubernetes cluster.
Index ¶
- Constants
- func MakeLabels(labels map[string]string) string
- type GeneratedPKI
- type K8s
- func (k *K8s) AddLabelsAndAnnotations(resourceNamespace string, resourceName string, groupKind schema.GroupKind, ...) error
- func (k *K8s) CreateConfigmap(namespace, name string, data map[string][]byte) (*corev1.ConfigMap, error)
- func (k *K8s) CreateNamespace(namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (k *K8s) CreateOrUpdateSecret(secret *corev1.Secret) (createdSecret *corev1.Secret, err error)
- func (k *K8s) CreateOrUpdateTLSSecret(namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
- func (k *K8s) CreatePod(pod *corev1.Pod) (*corev1.Pod, error)
- func (k *K8s) CreateService(service *corev1.Service) (*corev1.Service, error)
- func (k *K8s) DeleteConfigMapsByLabel(namespace string, labels Labels) error
- func (k *K8s) DeleteConfigmap(namespace, name string) error
- func (k *K8s) DeleteNamespace(ctx context.Context, name string) error
- func (k *K8s) DeletePod(namespace string, name string) error
- func (k *K8s) DeletePods(target PodLookup) error
- func (k *K8s) DeleteSecret(secret *corev1.Secret) error
- func (k *K8s) DeleteService(namespace, name string) error
- func (k *K8s) DetectDistro() (string, error)
- func (k *K8s) FindPodContainerPort(svc corev1.Service) int
- func (k *K8s) GeneratePod(name, namespace string) *corev1.Pod
- func (k *K8s) GenerateSecret(namespace, name string, secretType corev1.SecretType) *corev1.Secret
- func (k *K8s) GenerateService(namespace, name string) *corev1.Service
- func (k *K8s) GenerateTLSSecret(namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
- func (k *K8s) GetAllHPAs() (*autoscalingV2.HorizontalPodAutoscalerList, error)
- func (k *K8s) GetAllPods() (*corev1.PodList, error)
- func (k *K8s) GetAllServiceAccounts() (*corev1.ServiceAccountList, error)
- func (k *K8s) GetArchitectures() ([]string, error)
- func (k *K8s) GetHPA(namespace, name string) (*autoscalingV2.HorizontalPodAutoscaler, error)
- func (k *K8s) GetHPAs(namespace string) (*autoscalingV2.HorizontalPodAutoscalerList, error)
- func (k *K8s) GetNamespaces() (*corev1.NamespaceList, error)
- func (k *K8s) GetNode(nodeName string) (*corev1.Node, error)
- func (k *K8s) GetNodes() (*corev1.NodeList, error)
- func (k *K8s) GetPods(namespace string) (*corev1.PodList, error)
- func (k *K8s) GetSecret(namespace, name string) (*corev1.Secret, error)
- func (k *K8s) GetSecretsWithLabel(namespace, labelSelector string) (*corev1.SecretList, error)
- func (k *K8s) GetServerVersion() (version string, err error)
- func (k *K8s) GetService(namespace, serviceName string) (*corev1.Service, error)
- func (k *K8s) GetServiceAccount(namespace, name string) (*corev1.ServiceAccount, error)
- func (k *K8s) GetServiceAccounts(namespace string) (*corev1.ServiceAccountList, error)
- func (k *K8s) GetServices(namespace string) (*corev1.ServiceList, error)
- func (k *K8s) GetServicesByLabel(namespace, label, value string) (*corev1.ServiceList, error)
- func (k *K8s) GetServicesByLabelExists(namespace, label string) (*corev1.ServiceList, error)
- func (k *K8s) HandleDeprecations(rawData *unstructured.Unstructured, kubernetesVersion semver.Version) (*unstructured.Unstructured, bool, error)
- func (k *K8s) IsInitialNamespace(name string) bool
- func (k *K8s) NewJackalManagedNamespace(name string) *corev1.Namespace
- func (k *K8s) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int) (*Tunnel, error)
- func (k *K8s) RemoveLabelsAndAnnotations(resourceNamespace string, resourceName string, groupKind schema.GroupKind, ...) error
- func (k *K8s) ReplaceConfigmap(namespace, name string, data map[string][]byte) (*corev1.ConfigMap, error)
- func (k *K8s) ReplaceService(service *corev1.Service) (*corev1.Service, error)
- func (k *K8s) ServiceInfoFromNodePortURL(nodePortURL string) (*ServiceInfo, error)
- func (k *K8s) UpdateHPA(hpa *autoscalingV2.HorizontalPodAutoscaler) (*autoscalingV2.HorizontalPodAutoscaler, error)
- func (k *K8s) UpdateNamespace(namespace *corev1.Namespace) (*corev1.Namespace, error)
- func (k *K8s) UpdateServiceAccount(svcAccount *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
- func (k *K8s) WaitForHealthyCluster(timeout time.Duration) error
- func (k *K8s) WaitForPodsAndContainers(target PodLookup, include PodFilter) []corev1.Pod
- func (k *K8s) WaitForServiceAccount(ns, name string, timeout time.Duration) (*corev1.ServiceAccount, error)
- type Labels
- type Log
- type PodFilter
- type PodLookup
- type ServiceInfo
- type Tunnel
Constants ¶
const ( DistroIsUnknown = "unknown" DistroIsK3s = "k3s" DistroIsK3d = "k3d" DistroIsKind = "kind" DistroIsMicroK8s = "microk8s" DistroIsEKS = "eks" DistroIsEKSAnywhere = "eksanywhere" DistroIsDockerDesktop = "dockerdesktop" DistroIsGKE = "gke" DistroIsAKS = "aks" DistroIsRKE2 = "rke2" DistroIsTKG = "tkg" )
List of supported distros via distro detection.
const ( PodResource = "pod" SvcResource = "svc" )
Jackal Tunnel Configuration Constants.
Variables ¶
This section is empty.
Functions ¶
func MakeLabels ¶
MakeLabels is a helper to format a map of label key and value pairs into a single string for use as a selector.
Types ¶
type GeneratedPKI ¶
type GeneratedPKI struct { CA []byte `json:"ca"` Cert []byte `json:"cert"` Key []byte `json:"key"` }
GeneratedPKI is a struct for storing generated PKI data.
type K8s ¶
K8s is a client for interacting with a Kubernetes cluster.
func NewWithWait ¶
NewWithWait is a convenience function that creates a new K8s client and waits for the cluster to be healthy.
func (*K8s) AddLabelsAndAnnotations ¶
func (k *K8s) AddLabelsAndAnnotations(resourceNamespace string, resourceName string, groupKind schema.GroupKind, labels map[string]string, annotations map[string]string) error
AddLabelsAndAnnotations adds the provided labels and annotations to the specified K8s resource
func (*K8s) CreateConfigmap ¶
func (k *K8s) CreateConfigmap(namespace, name string, data map[string][]byte) (*corev1.ConfigMap, error)
CreateConfigmap applies a configmap to the cluster.
func (*K8s) CreateNamespace ¶
CreateNamespace creates the given namespace or returns it if it already exists in the cluster.
func (*K8s) CreateOrUpdateSecret ¶
CreateOrUpdateSecret creates or updates a Kubernetes secret.
func (*K8s) CreateOrUpdateTLSSecret ¶
func (k *K8s) CreateOrUpdateTLSSecret(namespace, name string, conf GeneratedPKI) (*corev1.Secret, error)
CreateOrUpdateTLSSecret creates or updates a Kubernetes secret with a new TLS secret.
func (*K8s) CreateService ¶
CreateService creates the given service in the cluster.
func (*K8s) DeleteConfigMapsByLabel ¶
DeleteConfigMapsByLabel deletes a configmap by label(s).
func (*K8s) DeleteConfigmap ¶
DeleteConfigmap deletes a configmap by name.
func (*K8s) DeleteNamespace ¶
DeleteNamespace deletes the given namespace from the cluster.
func (*K8s) DeletePods ¶
DeletePods removes a collection of pods from the cluster by pod lookup.
func (*K8s) DeleteSecret ¶
DeleteSecret deletes a Kubernetes secret.
func (*K8s) DeleteService ¶
DeleteService removes a service from the cluster by namespace and name.
func (*K8s) DetectDistro ¶
DetectDistro returns the matching distro or unknown if not found.
func (*K8s) FindPodContainerPort ¶
FindPodContainerPort will find a pod's container port from a service and return it.
Returns 0 if no port is found.
func (*K8s) GeneratePod ¶
GeneratePod creates a new pod without adding it to the k8s cluster.
func (*K8s) GenerateSecret ¶
GenerateSecret returns a Kubernetes secret object without applying it to the cluster.
func (*K8s) GenerateService ¶
GenerateService returns a K8s service struct without writing to the cluster.
func (*K8s) GenerateTLSSecret ¶
GenerateTLSSecret returns a Kubernetes secret object without applying it to the cluster.
func (*K8s) GetAllHPAs ¶
func (k *K8s) GetAllHPAs() (*autoscalingV2.HorizontalPodAutoscalerList, error)
GetAllHPAs returns a list of horizontal pod autoscalers for all namespaces.
func (*K8s) GetAllPods ¶
GetAllPods returns a list of pods from the cluster for all namespaces.
func (*K8s) GetAllServiceAccounts ¶
func (k *K8s) GetAllServiceAccounts() (*corev1.ServiceAccountList, error)
GetAllServiceAccounts returns a list of services accounts for all namespaces.
func (*K8s) GetArchitectures ¶
GetArchitectures returns the cluster system architectures if found.
func (*K8s) GetHPA ¶
func (k *K8s) GetHPA(namespace, name string) (*autoscalingV2.HorizontalPodAutoscaler, error)
GetHPA returns a single horizontal pod autoscaler by namespace and name.
func (*K8s) GetHPAs ¶
func (k *K8s) GetHPAs(namespace string) (*autoscalingV2.HorizontalPodAutoscalerList, error)
GetHPAs returns a list of horizontal pod autoscalers in a given namespace.
func (*K8s) GetNamespaces ¶
func (k *K8s) GetNamespaces() (*corev1.NamespaceList, error)
GetNamespaces returns a list of namespaces in the cluster.
func (*K8s) GetSecretsWithLabel ¶
func (k *K8s) GetSecretsWithLabel(namespace, labelSelector string) (*corev1.SecretList, error)
GetSecretsWithLabel returns a list of Kubernetes secrets with the given label.
func (*K8s) GetServerVersion ¶
GetServerVersion retrieves and returns the k8s revision.
func (*K8s) GetService ¶
GetService returns a Kubernetes service resource in the provided namespace with the given name.
func (*K8s) GetServiceAccount ¶
func (k *K8s) GetServiceAccount(namespace, name string) (*corev1.ServiceAccount, error)
GetServiceAccount returns a single service account by namespace and name.
func (*K8s) GetServiceAccounts ¶
func (k *K8s) GetServiceAccounts(namespace string) (*corev1.ServiceAccountList, error)
GetServiceAccounts returns a list of service accounts in a given namespace.
func (*K8s) GetServices ¶
func (k *K8s) GetServices(namespace string) (*corev1.ServiceList, error)
GetServices returns a list of services in the provided namespace. To search all namespaces, pass "" in the namespace arg.
func (*K8s) GetServicesByLabel ¶
func (k *K8s) GetServicesByLabel(namespace, label, value string) (*corev1.ServiceList, error)
GetServicesByLabel returns a list of matched services given a label and value. To search all namespaces, pass "" in the namespace arg.
func (*K8s) GetServicesByLabelExists ¶
func (k *K8s) GetServicesByLabelExists(namespace, label string) (*corev1.ServiceList, error)
GetServicesByLabelExists returns a list of matched services given a label. To search all namespaces, pass "" in the namespace arg.
func (*K8s) HandleDeprecations ¶
func (k *K8s) HandleDeprecations(rawData *unstructured.Unstructured, kubernetesVersion semver.Version) (*unstructured.Unstructured, bool, error)
HandleDeprecations takes in an unstructured object and the version of kubernetes in a cluster and returns a converted version of that object and whether it was modified (if applicable)
func (*K8s) IsInitialNamespace ¶
IsInitialNamespace returns true if the given namespace name is an initial k8s namespace: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#initial-namespaces
func (*K8s) NewJackalManagedNamespace ¶
NewJackalManagedNamespace returns a corev1.Namespace with Jackal-managed labels
func (*K8s) NewTunnel ¶
func (k *K8s) NewTunnel(namespace, resourceType, resourceName, urlSuffix string, local, remote int) (*Tunnel, error)
NewTunnel will create a new Tunnel struct. Note that if you use 0 for the local port, an open port on the host system will be selected automatically, and the Tunnel struct will be updated with the selected port.
func (*K8s) RemoveLabelsAndAnnotations ¶
func (k *K8s) RemoveLabelsAndAnnotations(resourceNamespace string, resourceName string, groupKind schema.GroupKind, labels map[string]string, annotations map[string]string) error
RemoveLabelsAndAnnotations removes the provided labels and annotations to the specified K8s resource
func (*K8s) ReplaceConfigmap ¶
func (k *K8s) ReplaceConfigmap(namespace, name string, data map[string][]byte) (*corev1.ConfigMap, error)
ReplaceConfigmap deletes and recreates a configmap.
func (*K8s) ReplaceService ¶
ReplaceService deletes and re-creates a service.
func (*K8s) ServiceInfoFromNodePortURL ¶
func (k *K8s) ServiceInfoFromNodePortURL(nodePortURL string) (*ServiceInfo, error)
ServiceInfoFromNodePortURL takes a nodePortURL and parses it to find the service info for connecting to the cluster. The string is expected to follow the following format: Example nodePortURL: 127.0.0.1:{PORT}.
func (*K8s) UpdateHPA ¶
func (k *K8s) UpdateHPA(hpa *autoscalingV2.HorizontalPodAutoscaler) (*autoscalingV2.HorizontalPodAutoscaler, error)
UpdateHPA updates the given horizontal pod autoscaler in the cluster.
func (*K8s) UpdateNamespace ¶
UpdateNamespace updates the given namespace in the cluster.
func (*K8s) UpdateServiceAccount ¶
func (k *K8s) UpdateServiceAccount(svcAccount *corev1.ServiceAccount) (*corev1.ServiceAccount, error)
UpdateServiceAccount updates the given service account in the cluster.
func (*K8s) WaitForHealthyCluster ¶
WaitForHealthyCluster checks for an available K8s cluster every second until timeout.
func (*K8s) WaitForPodsAndContainers ¶
WaitForPodsAndContainers attempts to find pods matching the given selector and optional inclusion filter It will wait up to 90 seconds for the pods to be found and will return a list of matching pod names If the timeout is reached, an empty list will be returned.
func (*K8s) WaitForServiceAccount ¶
func (k *K8s) WaitForServiceAccount(ns, name string, timeout time.Duration) (*corev1.ServiceAccount, error)
WaitForServiceAccount waits for a service account to be created in the cluster.
type PodFilter ¶
PodFilter is a function that returns true if the pod should be targeted for data injection or lookups.
type PodLookup ¶
type PodLookup struct { Namespace string `json:"namespace" jsonschema:"description=The namespace to target for data injection"` Selector string `json:"selector" jsonschema:"description=The K8s selector to target for data injection"` Container string `json:"container" jsonschema:"description=The container to target for data injection"` }
PodLookup is a struct for specifying a pod to target for data injection or lookups.
type ServiceInfo ¶
ServiceInfo contains information necessary for connecting to a cluster service.
func ServiceInfoFromServiceURL ¶
func ServiceInfoFromServiceURL(serviceURL string) (*ServiceInfo, error)
ServiceInfoFromServiceURL takes a serviceURL and parses it to find the service info for connecting to the cluster. The string is expected to follow the following format: Example serviceURL: http://{SERVICE_NAME}.{NAMESPACE}.svc.cluster.local:{PORT}.
type Tunnel ¶
type Tunnel struct {
// contains filtered or unexported fields
}
Tunnel is the main struct that configures and manages port forwarding tunnels to Kubernetes resources.
func (*Tunnel) Close ¶
func (tunnel *Tunnel) Close()
Close disconnects a tunnel connection by closing the StopChan, thereby stopping the goroutine.
func (*Tunnel) Endpoint ¶
Endpoint returns the tunnel ip address and port (i.e. for docker registries)
func (*Tunnel) FullURL ¶
FullURL returns the tunnel endpoint as a HTTP URL string with the urlSuffix appended.
func (*Tunnel) HTTPEndpoint ¶
HTTPEndpoint returns the tunnel endpoint as a HTTP URL string.