kubernetes

package
v0.192.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 33 Imported by: 34

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendFlattened

func AppendFlattened(components *metav1.List, component runtime.RawExtension) error

AppendFlattened will append newItem to list; making sure that raw newItem is decoded and flattened with another list

func CheckNamespaceExists

func CheckNamespaceExists(clientSet Interface, name string) (bool, error)

CheckNamespaceExists check if a namespace with a given name already exists, and returns boolean or an error

func CheckServiceAccountExists

func CheckServiceAccountExists(clientSet Interface, meta metav1.ObjectMeta) (bool, bool, error)

CheckServiceAccountExists check if a serviceaccount with a given name already exists, and if it is managed by eksctl

func ConcatManifests

func ConcatManifests(manifests ...[]byte) []byte

ConcatManifests joins the provided manifests (as byte arrays) into one single manifest. This can be useful to only have one I/O operation with Kubernetes down the line, when trying to apply these manifests.

func GetNodegroupKubernetesVersion added in v0.54.0

func GetNodegroupKubernetesVersion(nodes v1.NodeInterface, ngName string) (string, error)

func MaybeCreateNamespace

func MaybeCreateNamespace(clientSet Interface, name string) error

MaybeCreateNamespace will only create namespace with the given name if it doesn't already exist

func MaybeCreateServiceAccountOrUpdateMetadata

func MaybeCreateServiceAccountOrUpdateMetadata(clientSet Interface, meta metav1.ObjectMeta) error

MaybeCreateServiceAccountOrUpdateMetadata will only create serviceaccount with the given name if it doesn't already exist, it will also create namespace if needed; if serviceaccount exists, new labels and annotations will get added, all user-set label and annotation keys that are not set in meta will be retained

func MaybeDeleteServiceAccount

func MaybeDeleteServiceAccount(clientSet Interface, meta metav1.ObjectMeta) error

MaybeDeleteServiceAccount will only delete the serviceaccount if it exists

func NewList

func NewList(data []byte) (*metav1.List, error)

NewList decodes data into a list of Kubernetes resources, ignoring any whitespace and comment nodes

func NewNamespace

func NewNamespace(name string) *corev1.Namespace

NewNamespace creates a corev1.Namespace object using the provided name.

func NewNamespaceYAML

func NewNamespaceYAML(name string) []byte

NewNamespaceYAML returns a YAML string for a Kubernetes Namespace object. N.B.: Kubernetes' serializers are not used as unnecessary fields are being generated, e.g.: spec, status, creatimeTimestamp.

func NewRawExtension

func NewRawExtension(manifest []byte) (runtime.RawExtension, error)

NewRawExtension decodes the provided manifest into runtime.RawExtension

func NewRawExtensions

func NewRawExtensions(manifest []byte) ([]runtime.RawExtension, error)

NewRawExtensions decodes the provided manifest's bytes into "raw extension" Kubernetes objects. These can then be passed to NewRawResource.

func NewServiceAccount

func NewServiceAccount(meta metav1.ObjectMeta) *corev1.ServiceAccount

NewServiceAccount creates a corev1.ServiceAccount object using the provided meta.

func RefreshSecrets added in v0.39.0

func RefreshSecrets(ctx context.Context, c v1.CoreV1Interface) error

RefreshSecrets updates all secrets to apply KMS encryption

Types

type APIServerUnreachableError added in v0.112.0

type APIServerUnreachableError struct {
	Err error
}

APIServerUnreachableError represents an error reaching the API server.

func (*APIServerUnreachableError) Error added in v0.112.0

func (ae *APIServerUnreachableError) Error() string

Error implements the error interface.

type CachedClientSet

type CachedClientSet struct {
	CachedClientSet Interface
}

CachedClientSet provides a basic implementation of ClientSetGetter where the client is a field of a struct

func NewCachedClientSet

func NewCachedClientSet(clientSet Interface) *CachedClientSet

NewCachedClientSet constructs a new CachedClientSet.

func (*CachedClientSet) ClientSet

func (g *CachedClientSet) ClientSet() (Interface, error)

ClientSet returns g.CachedClientSet or an error it is nil

type CallbackClientSet

type CallbackClientSet struct {
	Callback func() (Interface, error)
}

CallbackClientSet provides an implementation of ClientSetGetter where the client is provided via a callback

func (*CallbackClientSet) ClientSet

func (g *CallbackClientSet) ClientSet() (Interface, error)

ClientSet returns g.ClientSet or an error it is nil

type ClientSetGetter

type ClientSetGetter interface {
	ClientSet() (Interface, error)
}

ClientSetGetter is an interface used for anything that requires to obtain Kubernetes client whe it's not possible to pass the client directly

type Interface

type Interface = kubeclient.Interface

Interface is an alias to avoid having to import k8s.io/client-go/kubernetes along with this package, so that most of our packages only care to import our kubernetes package

type RawClient

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

RawClient stores information about the client config

func NewRawClient

func NewRawClient(clientSet Interface, config *restclient.Config) (*RawClient, error)

NewRawClient creates a new raw REST client

func (*RawClient) ClientSet

func (c *RawClient) ClientSet() Interface

ClientSet returns the underlying ClientSet

func (*RawClient) CreateOrReplace

func (c *RawClient) CreateOrReplace(manifest []byte, plan bool) error

CreateOrReplace will check if the resources in the provided manifest exists, and create or update them as needed.

func (*RawClient) Delete

func (c *RawClient) Delete(manifest []byte) error

Delete attempts to delete the Kubernetes resources in the provided manifest, or do nothing if they do not exist.

func (*RawClient) Exists

func (c *RawClient) Exists(manifest []byte) (map[string]map[string]bool, error)

Exists checks if the Kubernetes resources in the provided manifest exist or not, and returns a map[<namespace>]map[<name>]bool to indicate each resource's existence.

func (*RawClient) NewHelperFor

func (c *RawClient) NewHelperFor(gvk schema.GroupVersionKind) (*resource.Helper, error)

NewHelperFor construct a raw client helper instance for a give gvk (it's based on k8s.io/kubernetes/pkg/kubectl/cmd/util/factory_client_access.go)

func (*RawClient) NewRawResource

func (c *RawClient) NewRawResource(object runtime.Object) (*RawResource, error)

NewRawResource constructs a type-specific instance or RawClient for object

func (*RawClient) ServerVersion

func (c *RawClient) ServerVersion() (string, error)

ServerVersion will use discovery API to fetch version of Kubernetes control plane

type RawClientInterface

type RawClientInterface interface {
	ClientSet() Interface
	NewRawResource(runtime.Object) (*RawResource, error)
}

RawClientInterface defines high level abstraction for RawClient for testing

type RawResource

type RawResource struct {
	Helper *resource.Helper
	Info   *resource.Info
	GVK    *schema.GroupVersionKind
}

RawResource holds info about a resource along with a type-specific raw client instance

func (*RawResource) CreateOrReplace

func (r *RawResource) CreateOrReplace(plan bool) (string, error)

CreateOrReplace will check if the given resource exists, and create or update it as needed

func (*RawResource) CreatePatchOrReplace

func (r *RawResource) CreatePatchOrReplace() error

CreatePatchOrReplace attempts patching the resource before replacing it TODO: it needs more testing and the issue with strategic patch has to be understood before we decide whether to use it or not

func (*RawResource) DeleteSync

func (r *RawResource) DeleteSync() (string, error)

DeleteSync attempts to delete this Kubernetes resource, or returns doing nothing if it does not exist. It blocks until the resource has been deleted.

func (*RawResource) Exists

func (r *RawResource) Exists() (bool, error)

Exists checks if this Kubernetes resource exists or not, and returns true if so, or false otherwise.

func (*RawResource) Get

func (r *RawResource) Get() (runtime.Object, bool, error)

Get returns the Kubernetes resource from the server

func (*RawResource) LogAction

func (r *RawResource) LogAction(plan bool, verb string) string

LogAction returns an info message that can be used to log a particular actions

func (*RawResource) String

func (r *RawResource) String() string

String returns a canonical name of the resource

type SimpleRESTClientGetter added in v0.82.0

type SimpleRESTClientGetter struct {
	Namespace  string
	KubeConfig string
}

Credit https://github.com/helm/helm/issues/6910#issuecomment-601277026

func NewRESTClientGetter added in v0.82.0

func NewRESTClientGetter(namespace, kubeConfig string) *SimpleRESTClientGetter

func (*SimpleRESTClientGetter) ToDiscoveryClient added in v0.82.0

func (*SimpleRESTClientGetter) ToRESTConfig added in v0.82.0

func (c *SimpleRESTClientGetter) ToRESTConfig() (*rest.Config, error)

func (*SimpleRESTClientGetter) ToRESTMapper added in v0.82.0

func (c *SimpleRESTClientGetter) ToRESTMapper() (meta.RESTMapper, error)

func (*SimpleRESTClientGetter) ToRawKubeConfigLoader added in v0.82.0

func (c *SimpleRESTClientGetter) ToRawKubeConfigLoader() clientcmd.ClientConfig

Jump to

Keyboard shortcuts

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