client

package
v1.21.1 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: Apache-2.0 Imports: 38 Imported by: 3

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	cr.Client
	// contains filtered or unexported fields
}

Client extends the client from controller-runtime

func New

func New(kubeconfigPath string) (*Client, error)

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

func NewFromRawKubeconfig(kubeconfig string) (*Client, error)

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 added in v0.12.0

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 added in v0.0.5

func NewWithContext(kubeconfigPath string, contextName string) (*Client, error)

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

func (c *Client) CheckConnection() error

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 added in v0.1.0

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

CreateOrUpdate attempts first to create the object given but if an AlreadyExists error is returned it instead updates the existing resource.

func (*Client) DeleteApp added in v0.7.0

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 added in v0.6.0

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 added in v0.6.0

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 added in v0.16.0

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 added in v0.12.0

func (c *Client) GetAPIServerEndpoint() string

GetAPIServerEndpoint returns the full URL for the API server

func (*Client) GetClusterKubeConfig added in v0.0.2

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 added in v0.17.0

func (c *Client) GetClusterName() string

GetClusterName returns the friendly name of the Cluster from the KubeConfig

func (*Client) GetEventsForResource added in v1.8.0

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 added in v0.0.10

func (c *Client) GetHelmValues(name, namespace string, values interface{}) error

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 added in v1.9.0

func (c *Client) GetLogs(ctx context.Context, pod *corev1.Pod, numOfLines *int64) (string, error)

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.

func (*Client) GetNormalEventsForResource added in v1.8.0

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 added in v1.13.0

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 added in v1.9.0

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 added in v1.13.0

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 added in v1.8.0

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 added in v1.19.0

func (c *Client) IsTeleportKubeconfig() bool

IsTeleportKubeconfig checks if the kubeconfig being used is one provided by Teleport or not

type DoesNotHaveLabels added in v0.0.14

type DoesNotHaveLabels []string

DoesNotHaveLabels filters the list/delete operation for objects that don't have the given set of labels.

func (DoesNotHaveLabels) ApplyToDeleteAllOf added in v0.0.14

func (m DoesNotHaveLabels) ApplyToDeleteAllOf(opts *cr.DeleteAllOfOptions)

ApplyToDeleteAllOf applies this configuration to the given an List options.

func (DoesNotHaveLabels) ApplyToList added in v0.0.14

func (m DoesNotHaveLabels) ApplyToList(opts *cr.ListOptions)

ApplyToList applies this configuration to the given list options.

Jump to

Keyboard shortcuts

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