k8s

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Patch

func Patch[T any, PT ObjectWithDeepCopy[T]](
	ctx context.Context,
	k8sClient client.Client,
	obj PT,
	modify func(),
) error

Patch updates k8s objects by subsequently calling k8s client `Patch()` and `Status().Patch()` The `modify` lambda is expected to mutate the `obj` but does not take the object as an argument as the object should be visible in the parent scope Example:

var pod *corev1.Pod

patchErr = k8s.Patch(ctx, fakeClient, pod, func() {
	pod.Spec.RestartPolicy = corev1.RestartPolicyOnFailure
	pod.Status.Message = "hello"
})

Types

type ObjectReconciler

type ObjectReconciler[T any, PT ObjectWithDeepCopy[T]] interface {
	ReconcileResource(ctx context.Context, obj PT) (ctrl.Result, error)
	SetupWithManager(mgr ctrl.Manager) *builder.Builder
}

type ObjectWithDeepCopy

type ObjectWithDeepCopy[T any] interface {
	*T

	client.Object
	DeepCopy() *T
}

type PatchingReconciler

type PatchingReconciler[T any, PT ObjectWithDeepCopy[T]] struct {
	// contains filtered or unexported fields
}

func NewPatchingReconciler

func NewPatchingReconciler[T any, PT ObjectWithDeepCopy[T]](log logr.Logger, k8sClient client.Client, objectReconciler ObjectReconciler[T, PT]) *PatchingReconciler[T, PT]

func (*PatchingReconciler[T, PT]) Reconcile

func (r *PatchingReconciler[T, PT]) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

func (*PatchingReconciler[T, PT]) SetupWithManager

func (r *PatchingReconciler[T, PT]) SetupWithManager(mgr ctrl.Manager) error

Jump to

Keyboard shortcuts

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