k8sutils

package module
v0.0.0-...-eafc3ef Latest Latest
Warning

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

Go to latest
Published: May 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

go-k8sutils

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNamespacedName

func GetNamespacedName(k8sObjYaml string) (types.NamespacedName, error)

func RemoveFieldRecusive

func RemoveFieldRecusive(obj map[string]interface{}, field string) error

func RemoveFieldRecusiveL

func RemoveFieldRecusiveL(objs []interface{}, field string) error

func TransformRemoveCreationTimestamp

func TransformRemoveCreationTimestamp(obj map[string]interface{}) error

TransformRemoveCreationTimestamp ensures we do not write the metadata.creationTimestamp field.

func TransformRemoveCreationTimestampRecursive

func TransformRemoveCreationTimestampRecursive(obj map[string]interface{}) error

TransformRemoveCreationTimestampRecursive removes all fields "creationTimestamp" recusively.

func TransformRemoveCreationTimestampRecursiveL

func TransformRemoveCreationTimestampRecursiveL(objs []interface{}) error

func TransformRemoveStatus

func TransformRemoveStatus(obj map[string]interface{}) error

TransformRemoveStatus remove status field.

func UnmarshalToRuntimeObject

func UnmarshalToRuntimeObject(objYaml string) (runtime.Object, *schema.GroupVersionKind, error)

UnmarshalToRuntimeObject unmarshal yaml to runtime.Object.

after you got the returned runObj runtime.Object, you can apply type switch to runObj to get concrete type, eg:

 switch obj := runObj.(type) {
	case *corev1.Service:
		clusterIP := obj.Spec.ClusterIP
		port := obj.Spec.Ports[0].Port
	default:
}

or apply type assertion, eg:

if obj, ok := runObj.(*corev1.Service); ok {
}

func UnmarshalToUnstructured

func UnmarshalToUnstructured(objYaml string) (*unstructured.Unstructured, error)

func WithNamespacedName

func WithNamespacedName(ns string, name string) types.NamespacedName

apimachinery/pkg defines

type NamespacedName struct {
	Namespace string
	Name      string
}

controller-runtime defines

type ObjectKey = types.NamespacedName

They are the same thing.

func YAMLMarshal

func YAMLMarshal(o interface{}, options ...*TransformYAMLOption) ([]byte, error)

Usage:

b, err := YAMLMarshal(vm,
	WithTransform(TransformRemoveCreationTimestampRecursive),
	WithTransform(TransformRemoveStatus))
if err != nil {
}

Types

type TransformYAMLOption

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

func WithTransform

func WithTransform(transform func(obj map[string]interface{}) error) *TransformYAMLOption

WithTransform applies a transformation to objects just before writing them.

Jump to

Keyboard shortcuts

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