kubeconfig

package
v0.0.0-...-b8e83fa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Prefix is a prefix that is added when writing temporary kubeconfig files
	Prefix = "kubeconfig-"
)

Variables

This section is empty.

Functions

func IsErrAllSourcesFailedErr

func IsErrAllSourcesFailedErr(err error) bool

IsErrAllSourcesFailedErr returns true if error is of type ErrAllSourcesFailedErr

Types

type Builder

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

Builder is an object that allows to build a kubeconfig based on various provided sources such as path to kubeconfig, path to bundle that should contain kubeconfig and parent cluster

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns instance of kubeconfig builder.

func (*Builder) Build

func (b *Builder) Build() Interface

Build site kubeconfig, ignores, but logs, errors that happen when building individual kubeconfigs. We need this behavior because, some clusters may not yet be deployed and their kubeconfig is inaccessible yet, but will be accessible at later phases If builder can't build kubeconfig for specific cluster, its context will not be present in final kubeconfig. User of kubeconfig, will receive error stating that context doesn't exist To request site-wide kubeconfig use builder method SiteWide(true). To request a single cluster kubeconfig use methods WithClusterName("my-cluster").SiteWide(false) ClusterName is ignored if SiteWide(true) is used.

func (*Builder) SiteWide

func (b *Builder) SiteWide(t bool) *Builder

SiteWide allows to build kubeconfig for the entire site. If set to true ClusterName will be ignored, since all clusters are requested.

func (*Builder) WithBundle

func (b *Builder) WithBundle(bundle document.Bundle) *Builder

WithBundle allows to set document.Bundle object that should contain kubeconfig api object

func (*Builder) WithClusterMap

func (b *Builder) WithClusterMap(cMap clustermap.ClusterMap) *Builder

WithClusterMap allows to set a parent cluster, that can be used to extract kubeconfig for target cluster

func (*Builder) WithClusterNames

func (b *Builder) WithClusterNames(clusterNames ...string) *Builder

WithClusterNames allows to reach to a cluster to download kubeconfig from there

func (*Builder) WithCoreV1Client

func (b *Builder) WithCoreV1Client(c corev1.CoreV1Interface) *Builder

WithCoreV1Client allows to set core v1 client, use for unit tests only

func (*Builder) WithFilesystem

func (b *Builder) WithFilesystem(fs fs.FileSystem) *Builder

WithFilesystem allows to set filesystem

func (*Builder) WithTempRoot

func (b *Builder) WithTempRoot(root string) *Builder

WithTempRoot allows to set temp root for kubeconfig

type Cleanup

type Cleanup func()

Cleanup is a function which cleans up kubeconfig file from filesystem

type ErrAllSourcesFailed

type ErrAllSourcesFailed struct {
	ClusterName string
}

ErrAllSourcesFailed returned when kubeconfig path is not specified

func (*ErrAllSourcesFailed) Error

func (e *ErrAllSourcesFailed) Error() string

type ErrClusterNameEmpty

type ErrClusterNameEmpty struct {
}

ErrClusterNameEmpty returned when cluster name is not provided

func (ErrClusterNameEmpty) Error

func (e ErrClusterNameEmpty) Error() string

type ErrKubeconfigMergeFailed

type ErrKubeconfigMergeFailed struct {
	Message string
}

ErrKubeconfigMergeFailed is returned when builder doesn't know which context to merge

func (*ErrKubeconfigMergeFailed) Error

func (e *ErrKubeconfigMergeFailed) Error() string

type ErrMalformedKubeconfig

type ErrMalformedKubeconfig struct {
	ClusterName string
}

ErrMalformedKubeconfig error returned if kubeconfig is empty

func (ErrMalformedKubeconfig) Error

func (e ErrMalformedKubeconfig) Error() string

type ErrUnknownKubeconfigSourceType

type ErrUnknownKubeconfigSourceType struct {
	Type string
}

ErrUnknownKubeconfigSourceType returned type of kubeconfig source is unknown

func (*ErrUnknownKubeconfigSourceType) Error

type Interface

type Interface interface {
	// GetFile returns path to kubeconfig file and a function to remove it
	// if error is returned cleanup is not needed
	GetFile() (string, Cleanup, error)
	// Write will write kubeconfig to the provided writer
	Write(w io.Writer) error
	// WriteFile will write kubeconfig data to specified path
	// WriteOptions holds additional option when writing kubeconfig to file
	WriteFile(path string, options WriteOptions) error
	// WriteTempFile writes a file a temporary file, returns path to it, cleanup function and error
	// it is responsibility of the caller to use the cleanup function to make sure that there are no leftovers
	WriteTempFile(dumpRoot string) (string, Cleanup, error)
}

Interface provides a uniform way to interact with kubeconfig file

func NewKubeConfig

func NewKubeConfig(source KubeSourceFunc, options ...Option) Interface

NewKubeConfig serves as a constructor for kubeconfig Interface first argument is a function that should return bytes with kubeconfig and error see FromByte() FromAPIalphaV1() FromFile() functions or extend with your own second argument are options that can be used to inject various supported options into it see InjectTempRoot(), InjectFileSystem(), InjectFilePath() functions for more info

type KubeSourceFunc

type KubeSourceFunc func() ([]byte, error)

KubeSourceFunc is a function which returns bytes array to construct new kubeConfig object

func FromAPIalphaV1

func FromAPIalphaV1(apiObj *v1alpha1.KubeConfig) KubeSourceFunc

FromAPIalphaV1 returns KubeSource type, uses API Config array as source to construct kubeconfig object

func FromBundle

func FromBundle(bundle document.Bundle) KubeSourceFunc

FromBundle returns KubeSource type, uses path to document bundle to find kubeconfig

func FromByte

func FromByte(b []byte) KubeSourceFunc

FromByte returns KubeSource type, uses plain bytes array as source to construct kubeconfig object

func FromConfig

func FromConfig(cfg *api.Config) KubeSourceFunc

FromConfig returns KubeSource type, write passed config as bytes

func FromFile

func FromFile(path string, fSys fs.FileSystem) KubeSourceFunc

FromFile returns KubeSource type, uses path to kubeconfig on FS as source to construct kubeconfig object

func FromSecret

FromSecret returns KubeSource type, uses client interface to kubernetes cluster

type Option

type Option func(*kubeConfig)

Option is a function that allows to modify kubeConfig object

func InjectFilePath

func InjectFilePath(path string, fSys fs.FileSystem) Option

InjectFilePath enables setting kubeconfig path, useful when you have kubeconfig from the actual filesystem, if this option is used, please also make sure that FromFile option is also used as a first argument in NewKubeConfig function

func InjectFileSystem

func InjectFileSystem(fSys fs.FileSystem) Option

InjectFileSystem sets fileSystem to be used, mostly to be used for tests

func InjectTempRoot

func InjectTempRoot(dumpRoot string) Option

InjectTempRoot sets root for temporary file system, if not set default OS temp dir will be used

type WriteOptions

type WriteOptions struct {
	Merge bool
}

WriteOptions holds additional option while writing kubeconfig to the file

Jump to

Keyboard shortcuts

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