k8s

package module
v0.0.0-...-1099530 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2024 License: MIT Imports: 25 Imported by: 0

README

go-k8s-toolkit

K8s clients helpers and wrappers used by other Adevinta tools&operators

Documentation

Index

Constants

View Source
const DefaultVersion = "v0.11.1"

Variables

View Source
var DefaultKind = KinD{
	Dir:     "./.kind",
	Version: DefaultVersion,
}

Functions

func KubeConfigPath

func KubeConfigPath(configPath string) string

func ParseKubernetesObjects

func ParseKubernetesObjects(r io.Reader, as runtime.Object) ([]runtime.Object, error)

func ParseUnstructured

func ParseUnstructured(r io.Reader) ([]*unstructured.Unstructured, error)

func ReadOnlyClient

func ReadOnlyClient(client client.Client, mutators ...func(c *readOnlyClient)) client.Client

func SerialiseObjects

func SerialiseObjects(scheme *runtime.Scheme, w io.Writer, objects ...runtime.Object) error

func ToClientObject

func ToClientObject(unstructuredObjects []*unstructured.Unstructured) []client.Object

func ToUnstructured

func ToUnstructured(scheme *runtime.Scheme, objects ...client.Object) ([]*unstructured.Unstructured, error)

func WithError

func WithError() func(c *readOnlyClient)

func WithErrorBuilder

func WithErrorBuilder(newError func(string) error) func(c *readOnlyClient)

func WithNoError

func WithNoError() func(c *readOnlyClient)

Types

type ClientConfigBuilder

type ClientConfigBuilder struct {
	ClientConfigLoadingRules *clientcmd.ClientConfigLoadingRules
	ConfigOverrides          *clientcmd.ConfigOverrides
	DefaultServerURL         string
	// contains filtered or unexported fields
}

func NewClientConfigBuilder

func NewClientConfigBuilder() ClientConfigBuilder

NewClientConfigBuilder allows the creation of a flexible Kubernetes client configuration creator

func (ClientConfigBuilder) Build

Build generates a new rest client config for the current builder.

func (ClientConfigBuilder) WithContext

func (b ClientConfigBuilder) WithContext(ctx string) ClientConfigBuilder

WithContext allows to define the kubernetes context to use. Equivalent to `kubectl --context ${ctx}`

func (ClientConfigBuilder) WithDefaultServerURL

func (b ClientConfigBuilder) WithDefaultServerURL(url string) ClientConfigBuilder

WithDefaultServerURL allows to fallback to a given Kubernetes server URL in case no config path exist or server URL is not provided

func (ClientConfigBuilder) WithImpersonateUserGroups

func (b ClientConfigBuilder) WithImpersonateUserGroups(userGroups ...string) ClientConfigBuilder

WithImpersonateUserGroups allows to create a client configuration with impersonation. Equivalent to `kubectl --as my-user --as-group ${group}`

func (ClientConfigBuilder) WithImpersonateUserName

func (b ClientConfigBuilder) WithImpersonateUserName(userName string) ClientConfigBuilder

WithImpersonateUserName allows to create a client configuration with impersonation. Equivalent to `kubectl --as ${user}`

func (ClientConfigBuilder) WithKubeConfigPath

func (b ClientConfigBuilder) WithKubeConfigPath(path string) ClientConfigBuilder

WithKubeConfigPath defines the kubeconfig file path to be loaded. If the filepath is empty or does not exist, the client will fallback to the default kubeconfig paths pointed by the ${KUBECONFIG} environment variable and ${HOME}/.kube/config

func (ClientConfigBuilder) WithServerURL

func (b ClientConfigBuilder) WithServerURL(url string) ClientConfigBuilder

WithServerURL forces the Kubernetes server URL regardless of the kubeconfig content

func (ClientConfigBuilder) WithTokenFile

func (b ClientConfigBuilder) WithTokenFile(token string) ClientConfigBuilder

WithServerURL forces the Kubernetes server URL regardless of the kubeconfig content

type KinD

type KinD struct {
	Dir     string
	Version string
}

func KinDForVersion

func KinDForVersion(version string) *KinD

func (*KinD) Delete

func (k *KinD) Delete(cluster *KinDCluster) error

func (*KinD) DownloadKubeConfig

func (k *KinD) DownloadKubeConfig(name string) (string, error)

func (*KinD) Exists

func (k *KinD) Exists(name string) bool

func (*KinD) Install

func (k *KinD) Install() error

func (*KinD) ListClusters

func (k *KinD) ListClusters() []string

func (*KinD) Start

func (k *KinD) Start(name, version string) (*KinDCluster, error)

type KinDCluster

type KinDCluster struct {
	// contains filtered or unexported fields
}

func (*KinDCluster) DownloadKubeConfig

func (k *KinDCluster) DownloadKubeConfig() error

func (*KinDCluster) Exists

func (k *KinDCluster) Exists() bool

func (*KinDCluster) ID

func (k *KinDCluster) ID() string

func (*KinDCluster) KubeConfigPath

func (k *KinDCluster) KubeConfigPath() string

type KubeCluster

type KubeCluster interface {
	KubeConfigPath() string
}

type ParseError

type ParseError struct {
	Data []byte
	Err  error
}

func (*ParseError) Error

func (p *ParseError) Error() string

Jump to

Keyboard shortcuts

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