k8stools

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: Apache-2.0 Imports: 34 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 GetTestClientWithClientObjects added in v0.60.0

func GetTestClientWithClientObjects(predefinedObjects []client.Object) client.Client

GetTestClientWithClientObjects returns testing client with optional predefined objects

func GetTestClientWithObjects

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

GetTestClientWithObjects returns testing client with optional predefined objects

func IsFSGroupChangePolicySupported

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 ListObjectsByNamespace

func ListObjectsByNamespace[T any, PT listing[T]](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 []corev1.Container) ([]corev1.Container, error)

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

func NewObjectWatcherForNamespaces

func NewObjectWatcherForNamespaces[T any, PT listing[T]](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

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

NewReadyDeployment returns a new deployment with ready status condition

func RenderPlaceholders

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 SetKubernetesVersionWithDefaults

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 VisitSelected added in v0.60.0

func VisitSelected[T any, PT listing[T]](ctx context.Context, rclient client.Client, s *SelectorOpts, cb func(PT)) error

VisitSelected applies given function to any T child object matched by selectors defined in parent obj selectors

Types

type ObjectWatcherForNamespaces

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

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

func (*ObjectWatcherForNamespaces) ResultChan

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

ResultChan returns a channel with events

func (*ObjectWatcherForNamespaces) Stop

func (ow *ObjectWatcherForNamespaces) Stop()

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

type SelectorOpts added in v0.60.0

type SelectorOpts struct {
	SelectAll         bool
	NamespaceSelector *metav1.LabelSelector
	ObjectSelector    *metav1.LabelSelector
	DefaultNamespace  string
}

SelectorOpts defines object query objects for given selectors

type TestClientWithStatsTrack added in v0.48.0

type TestClientWithStatsTrack struct {
	ApplyCalls     atomic.Int64
	GetCalls       atomic.Int64
	DeleteCalls    atomic.Int64
	CreateCalls    atomic.Int64
	UpdateCalls    atomic.Int64
	ListCalls      atomic.Int64
	PatchCalls     atomic.Int64
	DeleteAllCalls atomic.Int64
	// contains filtered or unexported fields
}

TestClientWithStatsTrack helps to track actual requests to the api server

func (*TestClientWithStatsTrack) Apply added in v0.65.0

func (*TestClientWithStatsTrack) Create added in v0.48.0

func (*TestClientWithStatsTrack) Delete added in v0.48.0

func (*TestClientWithStatsTrack) DeleteAllOf added in v0.48.0

func (tcs *TestClientWithStatsTrack) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf deletes all objects of the given type matching the given options.

func (*TestClientWithStatsTrack) Get added in v0.48.0

func (*TestClientWithStatsTrack) GroupVersionKindFor added in v0.48.0

func (tcs *TestClientWithStatsTrack) GroupVersionKindFor(obj runtime.Object) (schema.GroupVersionKind, error)

func (*TestClientWithStatsTrack) IsObjectNamespaced added in v0.48.0

func (tcs *TestClientWithStatsTrack) IsObjectNamespaced(obj runtime.Object) (bool, error)

func (*TestClientWithStatsTrack) List added in v0.48.0

func (*TestClientWithStatsTrack) Patch added in v0.48.0

func (*TestClientWithStatsTrack) RESTMapper added in v0.48.0

func (tcs *TestClientWithStatsTrack) RESTMapper() meta.RESTMapper

func (*TestClientWithStatsTrack) Scheme added in v0.48.0

func (tcs *TestClientWithStatsTrack) Scheme() *runtime.Scheme

func (*TestClientWithStatsTrack) Status added in v0.48.0

func (*TestClientWithStatsTrack) SubResource added in v0.48.0

func (tcs *TestClientWithStatsTrack) SubResource(subResource string) client.SubResourceClient

func (*TestClientWithStatsTrack) Update added in v0.48.0

Jump to

Keyboard shortcuts

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