Documentation
¶
Overview ¶
package client provides a thin wrapper around the controller-runtime client.
It provides standard operations (such as Get, Patch, Delete) for interacting with a Kubernetes cluster as well some helper functions for making it easier to perform certain operations.
Note: The client when created is set to use lazy discovery and doesn't pre-cache CRDs from the cluster. This is to allow for creation of a Client instance for a Workload Cluster before the api-server is ready by using the kubeconfig available from the Management Cluster secret.
For the full list of available functions make sure to also check cr.Client for the controller-runtime methods.
Index ¶
- type Client
- func New(kubeconfigPath string) (*Client, error)
- func NewFromRawKubeconfig(kubeconfig string) (*Client, error)
- func NewFromSecret(ctx context.Context, kubeClient *Client, clusterName string, namespace string) (*Client, error)
- func NewWithContext(kubeconfigPath string, contextName string) (*Client, error)
- func (c *Client) CheckConnection() error
- func (c *Client) CreateOrUpdate(ctx context.Context, obj cr.Object) error
- func (c *Client) DeleteApp(ctx context.Context, app application.Application) error
- func (c *Client) DeployApp(ctx context.Context, app application.Application) error
- func (c *Client) DeployAppManifests(ctx context.Context, appCR *applicationv1alpha1.App, ...) error
- func (c *Client) ExecInPod(ctx context.Context, podName, namespace, containerName string, ...) (string, string, error)
- func (c *Client) GetAPIServerEndpoint() string
- func (c *Client) GetClusterKubeConfig(ctx context.Context, clusterName string, clusterNamespace string) (string, error)
- func (c *Client) GetClusterName() string
- func (c *Client) GetEventsForResource(ctx context.Context, resource cr.Object, ...) (*corev1.EventList, error)
- func (c *Client) GetHelmValues(name, namespace string, values interface{}) error
- func (c *Client) GetLogs(ctx context.Context, pod *corev1.Pod, numOfLines *int64) (string, error)
- func (c *Client) GetNormalEventsForResource(ctx context.Context, resource cr.Object) (*corev1.EventList, error)
- func (c *Client) GetPodsForDaemonSet(ctx context.Context, daemonset *appsv1.DaemonSet) (*corev1.PodList, error)
- func (c *Client) GetPodsForDeployment(ctx context.Context, deployment *appsv1.Deployment) (*corev1.PodList, error)
- func (c *Client) GetPodsForStatefulSet(ctx context.Context, statefulset *appsv1.StatefulSet) (*corev1.PodList, error)
- func (c *Client) GetWarningEventsForResource(ctx context.Context, resource cr.Object) (*corev1.EventList, error)
- func (c *Client) IsTeleportKubeconfig() bool
- type DoesNotHaveLabels
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client extends the client from controller-runtime
func New ¶
New creates a new Kubernetes client for the provided kubeconfig file
The client is an extension of the client from controller-runtime and provides some additional helper functions. The creation of the client doesn't confirm connectivity to the cluster and REST discovery is set to lazy discovery so the client can be created while the cluster is still being set up.
func NewFromRawKubeconfig ¶
NewFromRawKubeconfig is like New but takes in the string contents of a Kubeconfig and creates a client for it
The client is an extension of the client from controller-runtime and provides some additional helper functions. The creation of the client doesn't confirm connectivity to the cluster and REST discovery is set to lazy discovery so the client can be created while the cluster is still being set up.
func NewFromSecret ¶
func NewFromSecret(ctx context.Context, kubeClient *Client, clusterName string, namespace string) (*Client, error)
NewFromSecret create a new Kubernetes client from a cluster kubeconfig found in a secret on the MC. This function may return a Not Found error if the kubeconfig secret is not found on the cluster.
The client is an extension of the client from controller-runtime and provides some additional helper functions. The creation of the client doesn't confirm connectivity to the cluster and REST discovery is set to lazy discovery so the client can be created while the cluster is still being set up.
func NewWithContext ¶
NewWithContext creates a new Kubernetes client for the provided kubeconfig file and changes the current context to the provided value
The client is an extension of the client from controller-runtime and provides some additional helper functions. The creation of the client doesn't confirm connectivity to the cluster and REST discovery is set to lazy discovery so the client can be created while the cluster is still being set up.
func (*Client) CheckConnection ¶
CheckConnection attempts to connect to the clusters API server and returns an error if not successful. A successful connection is defined as a valid response from the api-server but not necessarily a success response. For example, both a "Not Found" and a "Forbidden" response from the server is still a valid, working connection to the cluster and doesn't cause this function to return an error.
func (*Client) CreateOrUpdate ¶
CreateOrUpdate attempts first to create the object given but if an AlreadyExists error is returned it instead updates the existing resource.
func (*Client) DeleteApp ¶
func (c *Client) DeleteApp(ctx context.Context, app application.Application) error
DeleteApp removes an App CR and its ConfigMap from the cluster
func (*Client) DeployApp ¶
func (c *Client) DeployApp(ctx context.Context, app application.Application) error
DeployApp takes an Application and applies its manifests to the cluster in the correct order, ensuring the ConfigMap is made available first.
func (*Client) DeployAppManifests ¶
func (c *Client) DeployAppManifests(ctx context.Context, appCR *applicationv1alpha1.App, configMap *corev1.ConfigMap) error
DeployAppManifests takes an applications App CR and ConfigMap manifests and ensures they are applied in the correct order, with the ConfigMap being added first.
func (*Client) ExecInPod ¶
func (c *Client) ExecInPod(ctx context.Context, podName, namespace, containerName string, command []string) (string, string, error)
ExecInPod runs a given command within a pod running within the cluster and returns back the stdout and stderr
func (*Client) GetAPIServerEndpoint ¶
GetAPIServerEndpoint returns the full URL for the API server
func (*Client) GetClusterKubeConfig ¶
func (c *Client) GetClusterKubeConfig(ctx context.Context, clusterName string, clusterNamespace string) (string, error)
GetClusterKubeConfig retrieves the Kubeconfig from the secret associated with the provided cluster name.
func (*Client) GetClusterName ¶
GetClusterName returns the friendly name of the Cluster from the KubeConfig
func (*Client) GetEventsForResource ¶
func (c *Client) GetEventsForResource(ctx context.Context, resource cr.Object, extraFieldSelectors ...fields.Selector) (*corev1.EventList, error)
GetEventsForResource returns all existing events related to the provided resource
func (*Client) GetHelmValues ¶
GetHelmValues retrieves the helm values of a Helm release in the provided name and namespace and it will Unmarshal the values into the provided values struct.
func (*Client) GetLogs ¶
GetLogs fetches the logs from the provided Pod. If `numOfLines` is provided (instead of `nil`) then that many lines will be returned from the end of the logs. If multiple containers (including initContainers and ephermeralContainers) are found in the pod then logs from all of them will be collected.
func (*Client) GetNormalEventsForResource ¶
func (c *Client) GetNormalEventsForResource(ctx context.Context, resource cr.Object) (*corev1.EventList, error)
GetNormalEventsForResource returns all events related to the provided resource that have a type of "Normal"
func (*Client) GetPodsForDaemonSet ¶
func (c *Client) GetPodsForDaemonSet(ctx context.Context, daemonset *appsv1.DaemonSet) (*corev1.PodList, error)
GetPodsForDaemonSet returns a list of Pods that match the given DaemonSet selector
func (*Client) GetPodsForDeployment ¶
func (c *Client) GetPodsForDeployment(ctx context.Context, deployment *appsv1.Deployment) (*corev1.PodList, error)
GetPodsForDeployment returns a list of Pods that match the given Deployments selector
func (*Client) GetPodsForStatefulSet ¶
func (c *Client) GetPodsForStatefulSet(ctx context.Context, statefulset *appsv1.StatefulSet) (*corev1.PodList, error)
GetPodsForStatefulSet returns a list of Pods that match the given StatefulSet selector
func (*Client) GetWarningEventsForResource ¶
func (c *Client) GetWarningEventsForResource(ctx context.Context, resource cr.Object) (*corev1.EventList, error)
GetWarningEventsForResource returns all events related to the provided resource that have a type of "Warning"
func (*Client) IsTeleportKubeconfig ¶
IsTeleportKubeconfig checks if the kubeconfig being used is one provided by Teleport or not
type DoesNotHaveLabels ¶
type DoesNotHaveLabels []string
DoesNotHaveLabels filters the list/delete operation for objects that don't have the given set of labels.
func (DoesNotHaveLabels) ApplyToDeleteAllOf ¶
func (m DoesNotHaveLabels) ApplyToDeleteAllOf(opts *cr.DeleteAllOfOptions)
ApplyToDeleteAllOf applies this configuration to the given an List options.
func (DoesNotHaveLabels) ApplyToList ¶
func (m DoesNotHaveLabels) ApplyToList(opts *cr.ListOptions)
ApplyToList applies this configuration to the given list options.