helper

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package helper contains decode helper methods for transforming kubernetes metav1.Objects into K8sObjects

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertObject

func ConvertObject[T metav1.Object](o any) metav1.Object

ConvertObject attempts to cast an object to the specified metav1.Object type. If the cast fails, it logs an error and returns nil.

func EncodeRuntimeObject

func EncodeRuntimeObject(runtimeObj runtime.Object) ([]byte, error)

EncodeRuntimeObject encodes a given runtime.Object into raw bytes using the registered schemes.

func EncodeToRawBytes

func EncodeToRawBytes(obj metav1.Object) ([]byte, error)

EncodeToRawBytes encodes a Kubernetes resource object into raw bytes. It accepts any object that implements metav1.Object and runtime.Object.

func NewDynamicObjectCreator

func NewDynamicObjectCreator() types.ObjectCreator

NewDynamicObjectCreator returns a object creator that knows how to return objects from raw JSON data without the need of knowing the type.

To be able to infer the types the types need to be registered on the global client Scheme. Normally when a user tries casting the metav1.Object to a specific type, the object is already registered. In case the type is not registered and the object can't be created it will fallback to an `Unstructured` type.

Some types like pod/exec (`corev1.PodExecOptions`) implement `runtime.Object` however they don't implement `metav1.Object`. In that case we also fallback to `Unstructured`.

Useful to make dynamic webhooks that expect multiple or unknown types.

func NewStaticObjectCreator

func NewStaticObjectCreator(obj metav1.Object) types.ObjectCreator

NewStaticObjectCreator doesn't need to infer the type, it will create a new schema and create a new object with the same type from the received object type.

func RegisterSchemes

func RegisterSchemes(scheme *runtime.Scheme) error

RegisterSchemes registers the API schemes for various Kubernetes resource types. It ensures that the runtime.Scheme is aware of the resource types used in the application.

Types

This section is empty.

Jump to

Keyboard shortcuts

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