k8s

package
v0.0.0-...-584eab7 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: UPL-1.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasicAdminPod

func BasicAdminPod(node string, namespace string, podNamePrefix string, toolbox bool) *v1.Pod

BasicAdminPod returns the skeleton of a pod specification that can be used to create a privileged pod on a node.

func CertHashesFromKubeconfig

func CertHashesFromKubeconfig(kubeconfigPath string) ([]string, error)

CertHashesFromKubeconfig returns a list of hashes, one for each x509 certificate in a kubeconfig

func CertsFromKubeconfig

func CertsFromKubeconfig(kubeconfigPath string) ([]*x509.Certificate, error)

CertsFromKubeconfig gets the list of x509 certificates embedded in a kubeconfig.

func CreateConfigMapWithData

func CreateConfigMapWithData(client kubernetes.Interface, namespace string, name string, data map[string]string) error

func CreateConfigmap

func CreateConfigmap(client kubernetes.Interface, configMap *corev1.ConfigMap) error

func CreateJoin

func CreateJoin(kubeconfigPath string) (string, []string, error)

CreateJoin creates a join token on an existing cluster and returns the token as well as the hashes of the CA certs for the input kubeconfig

func CreateJoinToken

func CreateJoinToken(kubeconfigPath string, generateOnly bool) (string, error)

func CreateNamespaceIfNotExists

func CreateNamespaceIfNotExists(client kubernetes.Interface, name string) error

CreateNamespaceIfNotExists creates a namespace if it does not already exist

func CreateResource

func CreateResource(restConf *rest.Config, u *unstructured.Unstructured) error

func CreateResourceIfNotExist

func CreateResourceIfNotExist(restConf *rest.Config, u *unstructured.Unstructured) error

func CreateScriptsPod

func CreateScriptsPod(client kubernetes.Interface, p *PodOptions) error

CreateScriptsPod create a pod that mounts the config map with the same name as the pod

func CreateSecret

func CreateSecret(client kubernetes.Interface, namespace string, secret *v1.Secret) error

CreateSecret creates a Secret

func CreateService

func CreateService(client kubernetes.Interface, svc *v1.Service) error

func DeleteConfigmap

func DeleteConfigmap(client kubernetes.Interface, namespace string, name string) error

func DeletePod

func DeletePod(client kubernetes.Interface, namespace string, name string) error

func DeleteResource

func DeleteResource(restConf *rest.Config, u *unstructured.Unstructured) error

func DeleteResourceByIdentifier

func DeleteResourceByIdentifier(restConf *rest.Config, group string, version string, kind string, name string, namespace string) error

func DeleteService

func DeleteService(client kubernetes.Interface, namespace string, name string) error

func FindAll

func FindAll(haystack string, filter func(unstructured.Unstructured) bool) ([]unstructured.Unstructured, error)

FindAll finds all objects that mateches the criteria in a multi-doc yaml string.

func FindIn

func FindIn(haystack string, filter func(unstructured.Unstructured) bool) (unstructured.Unstructured, error)

FindIn finds the first object that matches the criteria in a multi-doc yaml string.

func FindSecretsByLabelKey

func FindSecretsByLabelKey(client kubernetes.Interface, namespace string, key string) (*v1.SecretList, error)

FindSecretsByLabelKey returns a SecretList for services that match the specified label key

func FindSecretsByLabelKeyVal

func FindSecretsByLabelKeyVal(client kubernetes.Interface, namespace string, key string, val string) (*v1.SecretList, error)

FindSecretsByLabelKeyVal returns a SecretList for services that match the specified label key/value pair

func FindSecretsByLabelSelector

func FindSecretsByLabelSelector(client kubernetes.Interface, namespace string, selector labels.Selector) (*v1.SecretList, error)

FindSecretsByLabelSelector returns a SecretList for services that match the label selector

func FindServicesByLabelKey

func FindServicesByLabelKey(client kubernetes.Interface, namespace string, key string) (*v1.ServiceList, error)

FindServicesByLabelKey returns a ServiceList for services that match the specified label key

func FindServicesByLabelKeyVal

func FindServicesByLabelKeyVal(client kubernetes.Interface, namespace string, key string, val string) (*v1.ServiceList, error)

FindServicesByLabelKeyVal returns a ServiceList for services that match the specified label key/value pair

func FindServicesByLabelSelector

func FindServicesByLabelSelector(client kubernetes.Interface, namespace string, selector labels.Selector) (*v1.ServiceList, error)

FindServicesByLabelSelector returns a ServiceList for services that match the label selector

func GetConfigmap

func GetConfigmap(client kubernetes.Interface, namespace string, name string) (*corev1.ConfigMap, error)

func GetControlPlaneNodes

func GetControlPlaneNodes(cli kubernetes.Interface) (*v1.NodeList, error)

GetControlPlaneNodes gets all nodes that run control plane components. It looks for data other than labels and annotations to make a reasonable guess at what those nodes are.

func GetNamespaceList

func GetNamespaceList(client kubernetes.Interface) (*v1.NamespaceList, error)

GetNamespaceList returns the list of namespaces

func GetNamespaces

func GetNamespaces(cli kubernetes.Interface) ([]string, error)

GetNamespaces returns the namespace names

func GetNode

func GetNode(client kubernetes.Interface, name string) (*v1.Node, error)

GetNode returns the specified node.

func GetNodeList

func GetNodeList(client kubernetes.Interface) (*v1.NodeList, error)

GetNodeList returns a list of Kubernetes nodes.

func GetNodeNames

func GetNodeNames(cli kubernetes.Interface) ([]string, error)

GetNodeNames returns the cluster node naems

func GetPod

func GetPod(client kubernetes.Interface, namespace string, name string) (*v1.Pod, error)

func GetPodsBySelector

func GetPodsBySelector(client kubernetes.Interface, namespace string, selector string) (*v1.PodList, error)

func GetResource

func GetResource(restConf *rest.Config, u *unstructured.Unstructured) error

func GetResourceByIdentifier

func GetResourceByIdentifier(restConf *rest.Config, group string, version string, kind string, name string, namespace string) (*unstructured.Unstructured, error)

func GetRole

func GetRole(node *v1.Node) (bool, string)

GetRole returns true if the node is a control-plane node, along with a string indicating the node's role

func GetService

func GetService(client kubernetes.Interface, namespace string, name string) (*v1.Service, error)

GetService returns the specified service.

func GrabContainer

func GrabContainer(objectsToSearch []v1.Container, name string) (v1.Container, int, error)

func GrabDeployment

func GrabDeployment(objectsToSearch []unstructured.Unstructured) (v1Apps.Deployment, int, error)

func IsControlPlane

func IsControlPlane(node *v1.Node) bool

IsControlPlane returns true if the node is a control-plane node

func IsNodeReady

func IsNodeReady(status v1.NodeStatus) bool

func IsNotExist

func IsNotExist(err error) bool

IsNotExist checks if an error represents non-existence

func IsUpdateAvailable

func IsUpdateAvailable(node *v1.Node) bool

IsUpdateAvailable returns true if an update is available on that node

func PortForwardToService

func PortForwardToService(kubeConfigPath string, serviceNsn types.NamespacedName, remotePort string) (int, error)

PortForwardToService does a port forward to a service and returns the local port

func StartAdminPodOnNode

func StartAdminPodOnNode(client kubernetes.Interface, node string, namespace string, podNamePrefix string, toolbox bool) (*v1.Pod, error)

StartAdminPodOnNode creates a privileged pod on a node, executes a command, and tears down the pod.

func StartPortForwardToService

func StartPortForwardToService(kubeInfo *client.KubeInfo, forwardSpec *PortForwardSpec) (int, error)

StartPortForwardToService starts a port-forward to a service in the background, then returns the local port. The caller can then send data to http://localhost:<localport> The port-forwarding session remains until the CLI exits.

func Unmarshall

func Unmarshall(reader *bufio.Reader) ([]unstructured.Unstructured, error)

Unmarshall a reader containing YAML to a list of unstructured objects

func UpdateConfigMap

func UpdateConfigMap(client kubernetes.Interface, configMap *corev1.ConfigMap, namespace string) (*corev1.ConfigMap, error)

func UploadCertificateStanza

func UploadCertificateStanza(kubeconfigPath string, key string) (string, error)

UploadCertificateStanza returns a command to run that will upload certificates to the cluster to enable joining new control plane nodes.

func UploadCertificates

func UploadCertificates(kubeconfigPath string, key string) error

UploadCertificates uploads the key material required for control plane nodes to join clusters.

func WaitForDeployment

func WaitForDeployment(client kubernetes.Interface, namespace string, name string, expectedReplicas int32) error

WaitForDeployment - wait for deployment to be ready

func WaitForPod

func WaitForPod(client kubernetes.Interface, namespace string, name string) error

func WaitForService

func WaitForService(client kubernetes.Interface, namespace string, name string) error

WaitForService - wait for service to exist

func WaitForServiceAccount

func WaitForServiceAccount(client kubernetes.Interface, accountName string, namespace string) error

WaitForServiceAccount waits for a service account to exist.

func WaitUntilGetNodesSucceeds

func WaitUntilGetNodesSucceeds(client kubernetes.Interface) (*v1.NodeList, error)

WaitUntilGetNodesSucceeds until Kubernetes returns node list

func WaitUntilNodeIsReady

func WaitUntilNodeIsReady(client kubernetes.Interface, nodeName string) error

WaitUntilNodeIsReady until Kubernetes node is ready

func WaitUntilPodReady

func WaitUntilPodReady(client kubernetes.Interface, namespace string, name string) error

WaitUntilPodReady waits until a pod is ready

Types

type ErrorNotExist

type ErrorNotExist struct {
}

func (*ErrorNotExist) Error

func (e *ErrorNotExist) Error() string

type PodOptions

type PodOptions struct {
	NodeName      string
	Namespace     string
	PodName       string
	ImageName     string
	ConfigMapName string
	HostPID       bool
	HostNetwork   bool
	Env           []v1.EnvVar
}

PodOptions are used to create a pod that mounts a configmap

type PortForwardSpec

type PortForwardSpec struct {
	// ServiceNsn is the namespace and name of the service which the target of the port forward.
	// Required
	ServiceNsn types.NamespacedName

	// LocalPort is the port on the local system (where the CLI is) where HTTP requests will be sent
	// This is normally left blank and the port-forwarding code will assign an ephemeral port, which
	// is returned to the caller when the port-forward is started. Only set it if you really
	// want to use a specific port.
	// Optional
	LocalPort string

	// RemotePort is the service port which will receive forwarded traffic.
	// Required
	RemotePort string
}

PortForwardSpec contains the information needed to do the port forward

type Result

type Result struct {
	// Err will be non-nil if the goroutine encountered a problem
	Err error

	// LocalPort is the local port that the port-forwarder is listening on
	LocalPort int
}

Result is the data sent from the goroutine over the channel

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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