k8stools

package
v0.42.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerMajorVersion uint64
	ServerMinorVersion uint64
)

Functions

func CompareObjectMeta

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

func GetTestClientWithObjects

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

func HandleDeployUpdate added in v0.22.1

func HandleDeployUpdate(ctx context.Context, rclient client.Client, newDeploy *appsv1.Deployment, waitDeadline time.Duration) error

HandleDeployUpdate performs an update or create operator for deployment and waits until it's replicas is ready

func HandleSTSUpdate added in v0.20.0

func HandleSTSUpdate(ctx context.Context, rclient client.Client, cr STSOptions, newSts *appsv1.StatefulSet, c *config.BaseOperatorConf) error

HandleSTSUpdate performs create and update operations for given statefulSet with STSOptions

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 MergeAnnotations added in v0.22.0

func MergeAnnotations(prev, current map[string]string) map[string]string

MergeAnnotations adds annotations with kubernetes.io/ to the current map from prev It's needed for kubectl restart, correct updates such annotations managed by kubernetes controller and shouldn't be changed by operator

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 PodIsFailedWithReason added in v0.26.0

func PodIsFailedWithReason(pod corev1.Pod) (bool, string)

PodIsFailedWithReason reports if pod failed and the reason of fail

func PodIsReady added in v0.20.0

func PodIsReady(pod corev1.Pod, minReadySeconds int32) bool

PodIsReady check is pod is ready

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

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

Types

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

type STSOptions added in v0.20.0

type STSOptions struct {
	HasClaim           bool
	SelectorLabels     func() map[string]string
	VolumeName         func() string
	UpdateStrategy     func() appsv1.StatefulSetUpdateStrategyType
	HPA                *victoriametricsv1beta1.EmbeddedHPA
	UpdateReplicaCount func(count *int32)
}

STSOptions options for StatefulSet update HPA and UpdateReplicaCount optional

Jump to

Keyboard shortcuts

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