kubeclient

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCredential

func GetCredential(ctx context.Context, cfg *rest.Config) (string, error)

GetCredential implements a hacky method of gleaning the bearer token that is used for authentication to a given Kubernetes API server. It works by building an HTTP client using the provided *rest.Config as well as a custom http.RoundTripper. The custom http.RoundTripper copies the Authorization header from an outbound request to the X-Kargo-User-Credential header in the corresponding inbound response. This client is used to make a request to the Kubernetes API server and the value of the X-Kargo-User-Credential header is read from the response and returned.

Note: The reason the token isn't simply read directly from the *rest.Config is because that strategy would not account for cases where the bearer token is actually supplied by a credential plugin.

This method will not work when authentication to the Kubernetes API server is achieved using a client certificate, but that methods of authentication does not seem to be widely used beyond kind and k3d.

func IgnoreInvalid added in v0.6.0

func IgnoreInvalid(err error) error

IgnoreInvalid returns nil on Invalid errors. All other values that are not Invalid errors or nil are returned unmodified.

func PatchStatus

func PatchStatus[T HasStatus[S], S any](
	ctx context.Context, kubeClient client.Client, resource T, update func(status S)) error

PatchStatus patches evaluate changes applied by the callback to the status of a resource and patches resource status if there are any changes.

func PatchUnstructured added in v0.8.5

func PatchUnstructured(ctx context.Context, c client.Client, obj ObjectWithKind, modify UnstructuredPatchFn) error

PatchUnstructured patches a Kubernetes object using unstructured objects. It fetches the object from the API server, applies modifications via the provided UnstructuredPatchFn, and patches the object back to the server.

The UnstructuredPatchFn is called with src (a copy of the original object converted to unstructured format) and dest (the object fetched from the API server).

It returns an error if it fails to fetch the object, apply modifications, patch the object, or convert the result back to its typed form.

Types

type HasStatus

type HasStatus[S any] interface {
	client.Object
	GetStatus() S
}

type ObjectWithKind added in v0.8.5

type ObjectWithKind interface {
	client.Object
	schema.ObjectKind
}

type UnstructuredPatchFn added in v0.8.5

type UnstructuredPatchFn func(src, dest unstructured.Unstructured) error

UnstructuredPatchFn is a function which modifies the destination unstructured object based on the source unstructured object.

Jump to

Keyboard shortcuts

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