Documentation
¶
Overview ¶
Package helper contains decode helper methods for transforming kubernetes metav1.Objects into K8sObjects
Index ¶
- func ConvertObject[T metav1.Object](o any) metav1.Object
- func EncodeRuntimeObject(runtimeObj runtime.Object) ([]byte, error)
- func EncodeToRawBytes(obj metav1.Object) ([]byte, error)
- func NewDynamicObjectCreator() types.ObjectCreator
- func NewStaticObjectCreator(obj metav1.Object) types.ObjectCreator
- func RegisterSchemes(scheme *runtime.Scheme) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConvertObject ¶
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 ¶
EncodeRuntimeObject encodes a given runtime.Object into raw bytes using the registered schemes.
func EncodeToRawBytes ¶
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 ¶
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.