kubeobject

package
v0.0.0-...-c7cb2fe Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2025 License: Apache-2.0 Imports: 8 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

TheScheme holds the mapping between Go types and schema.GroupVersionKinds. Types have to be registered in it before they are used with the generic functions below. The typical way of registering is by using the AddToScheme function of the package holding the API types. E.g.:

_ = nephioreqv1alpha1.AddToScheme(kubeobject.TheScheme)

Functions

func FilterByType

func FilterByType[T any, PT PtrIsRuntimeObject[T]](objs fn.KubeObjects) ([]*T, fn.KubeObjects, error)

FilterByType returns the objects in `objs` whose Group-Version-Kind matches with the Go type `T`. Panics if `T` is not registered in `TheScheme`. FilterByType returns with

  • the list of matching KubeObjects converted to `*T`.
  • the rest of the `objs` list (KubeObjects that don't match)
  • a potential error

func GetGVKOrPanic

func GetGVKOrPanic[T any, PT PtrIsRuntimeObject[T]]() schema.GroupVersionKind

GetKindOrPanic returns with the Kind of a Kubernetes API resource type `T`. Panics if `T` is not registered in `TheScheme`.

func GetSingleton

func GetSingleton[T any, PT PtrIsRuntimeObject[T]](objs fn.KubeObjects) (*T, error)

GetSingleton returns with the one-and-only resource in `objs` whose Go type is `T`, or an error if there is not exactly 1 instance of type `T` is present in `objs`. Panics if `T` is not registered in `TheScheme`.

func KubeObjectToStruct

func KubeObjectToStruct[T any](obj *fn.KubeObject) (*T, error)

KubeObjectToStruct is a lightweight wrapper around `obj.As()`, only meant to slightly improve code readability

func SetNestedFieldKeepFormatting

func SetNestedFieldKeepFormatting(obj *fn.KubeObject, value interface{}, fields ...string) error

setNestedFieldKeepFormatting is similar to KubeObject.SetNestedField(), but keeps the comments and the order of fields in the YAML wherever it is possible.

NOTE: This functionality should be solved in the upstream SDK. Merging the code below to the upstream SDK is in progress and tracked in this issue: https://github.com/GoogleContainerTools/kpt/issues/3923

Types

type KubeObjectExt

type KubeObjectExt[T1 any] struct {
	fn.KubeObject
}

func NewFromGoStruct

func NewFromGoStruct[T1 any](x *T1) (*KubeObjectExt[T1], error)

NewFromGoStruct returns a KubeObjectExt struct It expects a go struct representing the interface krm resource

func NewFromKubeObject

func NewFromKubeObject[T1 any](o *fn.KubeObject) (*KubeObjectExt[T1], error)

NewFromKubeObject returns a KubeObjectExt struct It expects a fn.KubeObject as input representing the serialized yaml file

func NewFromYaml

func NewFromYaml[T1 any](b []byte) (*KubeObjectExt[T1], error)

NewFromYaml returns a KubeObjectExt struct It expects raw byte slice as input representing the serialized yaml file

func (*KubeObjectExt[T1]) GetGoStruct

func (r *KubeObjectExt[T1]) GetGoStruct() (*T1, error)

func (*KubeObjectExt[T1]) SetFromTypedObject

func (o *KubeObjectExt[T1]) SetFromTypedObject(value *T1) error

SetFromTypedObject sets the value of `o` to `value`, while keeping most of the YAML formatting. It can be seen as an in-place version of fn.NewFromTypedObject

func (*KubeObjectExt[T1]) SetNestedFieldKeepFormatting

func (o *KubeObjectExt[T1]) SetNestedFieldKeepFormatting(value interface{}, fields ...string) error

func (*KubeObjectExt[T1]) SetSpec

func (o *KubeObjectExt[T1]) SetSpec(value *T1) error

SetSpec sets the `spec` field of a KubeObjectExt to the value of `newSpec`, while trying to keep as much formatting as possible

func (*KubeObjectExt[T1]) SetStatus

func (o *KubeObjectExt[T1]) SetStatus(value *T1) error

SetStatus sets the `status` field of a KubeObjectExt to the value of `newStatus`, while trying to keep as much formatting as possible

func (*KubeObjectExt[T1]) UnsafeSetSpec

func (o *KubeObjectExt[T1]) UnsafeSetSpec(newSpec interface{}) error

UnsafeSetSpec sets the `spec` field of a KubeObjectExt to the value of `newSpec`, while trying to keep as much formatting as possible

func (*KubeObjectExt[T1]) UnsafeSetStatus

func (o *KubeObjectExt[T1]) UnsafeSetStatus(newStatus interface{}) error

UnsafeSetStatus sets the `status` field of a KubeObjectExt to the value of `newStatus`, while trying to keep as much formatting as possible

type PtrIsRuntimeObject

type PtrIsRuntimeObject[T any] interface {
	runtime.Object
	*T
}

Type constraint for checking if *T implements the runtime.Object interface

Jump to

Keyboard shortcuts

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