k8stools

package
v0.43.5 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ServerMajorVersion defines major number for current kubernetes API server version
	ServerMajorVersion uint64
	// ServerMinorVersion defines minor number for current kubernetes API server version
	ServerMinorVersion uint64
)

Functions

func CompareObjectMeta

func CompareObjectMeta(t *testing.T, got, want metav1.ObjectMeta)

CompareObjectMeta compares metadata objects

func GetCredFromConfigMap added in v0.43.0

func GetCredFromConfigMap(
	ctx context.Context,
	rclient client.Client,
	ns string,
	sel v1.ConfigMapKeySelector,
	cacheKey string,
	cache map[string]*v1.ConfigMap,
) (string, error)

GetCredFromConfigMap fetches content of configmap by given key

func GetCredFromSecret added in v0.43.0

func GetCredFromSecret(
	ctx context.Context,
	rclient client.Client,
	ns string,
	sel *v1.SecretKeySelector,
	cacheKey string,
	cache map[string]*v1.Secret,
) (string, error)

GetCredFromSecret fetch content of secret by given key

func GetTestClientWithObjects

func GetTestClientWithObjects(predefinedObjects []runtime.Object) client.Client

GetTestClientWithObjects returns testing client with optional predefined objects

func IsFSGroupChangePolicySupported added in v0.36.0

func IsFSGroupChangePolicySupported() bool

IsFSGroupChangePolicySupported checks if `fsGroupChangePolicy` is supported, Supported since 1.20 https://kubernetes.io/blog/2020/12/14/kubernetes-release-1.20-fsgroupchangepolicy-fsgrouppolicy/#allow-users-to-skip-recursive-permission-changes-on-mount

func IsPDBV1APISupported added in v0.23.0

func IsPDBV1APISupported() bool

IsPDBV1APISupported check if new v1 API is supported by kubernetes API server deprecated since 1.21 https://kubernetes.io/docs/reference/using-api/deprecation-guide/#poddisruptionbudget-v125

func IsPSPSupported added in v0.23.0

func IsPSPSupported() bool

IsPSPSupported check if PodSecurityPolicy is supported by kubernetes API server https://kubernetes.io/docs/reference/using-api/deprecation-guide/#psp-v125

func ListObjectsByNamespace added in v0.42.0

func ListObjectsByNamespace[T any, PT interface {
	*T
	client.ObjectList
}](ctx context.Context, rclient client.Client, nss []string, collect func(PT), opts ...client.ListOption) error

ListObjectsByNamespace performs object list for given namespaces

func MergePatchContainers

func MergePatchContainers(base, patches []v1.Container) ([]v1.Container, error)

MergePatchContainers adds patches to base using a strategic merge patch and iterating by container name, failing on the first error

func MustConvertObjectVersionsJSON added in v0.30.3

func MustConvertObjectVersionsJSON[A, B any](src *A, objectName string) *B

MustConvertObjectVersionsJSON objects with json serialize and deserialize it could be used only for converting BETA apis to Stable version

func NewHPAEmptyObject added in v0.30.3

func NewHPAEmptyObject(opts ...func(obj client.Object)) client.Object

NewHPAEmptyObject returns HorizontalPodAutoscaler object

func NewObjectWatcherForNamespaces added in v0.42.0

func NewObjectWatcherForNamespaces[T any, PT interface {
	*T
	client.ObjectList
}](ctx context.Context, rclient client.WithWatch, crdTypeName string, namespaces []string) (watch.Interface, error)

NewObjectWatcherForNamespaces returns a watcher for events at multiple namespaces for given object in case of empty namespaces, performs cluster wide watch

func NewReadyDeployment added in v0.42.0

func NewReadyDeployment(name, namespace string) *appsv1.Deployment

NewReadyDeployment returns a new deployment with ready status condition

func RenderPlaceholders added in v0.31.0

func RenderPlaceholders[T any](resource *T, placeholders map[string]string) (*T, error)

RenderPlaceholders replaces placeholders at resource with given values placeholder must be in %NAME% format resource must be reference to json serializable struct

func SanitizeVolumeName

func SanitizeVolumeName(name string) string

SanitizeVolumeName replaces all incompatible with k8s characters with -

func SelectNamespaces added in v0.43.0

func SelectNamespaces(ctx context.Context, rclient client.Client, selector labels.Selector) ([]string, error)

SelectNamespaces select namespaces by given label selector

func SetKubernetesVersionWithDefaults added in v0.23.2

func SetKubernetesVersionWithDefaults(vi *version.Info, defaultMinor, defaultMajor uint64) error

SetKubernetesVersionWithDefaults parses kubernetes version response with given default versions

func UpdatePodAnnotations

func UpdatePodAnnotations(ctx context.Context, rclient client.Client, selector map[string]string, ns string) error

UpdatePodAnnotations - updates configmap-sync-time annotation it triggers config rules reload for vmalert

func VisitObjectsForSelectorsAtNs added in v0.43.0

func VisitObjectsForSelectorsAtNs[T any, PT interface {
	*T
	client.ObjectList
}](ctx context.Context, rclient client.Client,
	nsSelector, objectSelector *metav1.LabelSelector,
	objNamespace string, selectAllByDefault bool, cb func(PT),
) error

VisitObjectsForSelectorsAtNs applies given function to any object matched given selectors

Types

type BasicAuthCredentials added in v0.43.0

type BasicAuthCredentials struct {
	Username string
	Password string
}

BasicAuthCredentials represents a username password pair to be used with basic http authentication, see https://tools.ietf.org/html/rfc7617.

func LoadBasicAuthSecret added in v0.43.0

func LoadBasicAuthSecret(ctx context.Context, rclient client.Client, ns string, basicAuth *victoriametricsv1beta1.BasicAuth, secretCache map[string]*v1.Secret) (BasicAuthCredentials, error)

LoadBasicAuthSecret fetch content of kubernetes secrets and returns it within plain text

type OAuthCreds added in v0.43.0

type OAuthCreds struct {
	ClientSecret string
	ClientID     string
}

OAuthCreds represents OAuth2 secret values within plain text

func LoadOAuthSecrets added in v0.43.0

func LoadOAuthSecrets(ctx context.Context, rclient client.Client, oauth2 *victoriametricsv1beta1.OAuth2, ns string, cache map[string]*v1.Secret, cmCache map[string]*v1.ConfigMap) (*OAuthCreds, error)

LoadOAuthSecrets fetches content of OAuth secret and retruns it plain text value

type ObjectWatcherForNamespaces added in v0.42.0

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

ObjectWatcherForNamespaces performs a watch operation for multiple namespaces without using cluster wide permissions with empty namaspaces uses cluster wide mode

func (*ObjectWatcherForNamespaces) ResultChan added in v0.42.0

func (ow *ObjectWatcherForNamespaces) ResultChan() <-chan watch.Event

ResultChan returns a channel with events

func (*ObjectWatcherForNamespaces) Stop added in v0.42.0

func (ow *ObjectWatcherForNamespaces) Stop()

Stop performs a stop on all watchers and waits for it's finish

Jump to

Keyboard shortcuts

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