fieldmanager

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

README

Please check the doc.go file for more details about
how to use and maintain the code in this package.

Documentation

Overview

Package fieldmanager is a special package as its main purpose is to expose the dependencies required by structured-merge-diff library to calculate diffs when server-side apply option is enabled. The dependency tree necessary to have a `merge.Updater` instance isn't trivial to implement and the strategy used is borrowing a copy from Kubernetes apiserver codebase in order to expose the required functionality.

Below there is a list of borrowed files and a reference to which package/file in Kubernetes they were copied from:

- borrowed_fields.go: k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/fields.go - borrowed_managedfields.go: k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/internal/managedfields.go - borrowed_typeconverter.go: k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/typeconverter.go - borrowed_versionconverter.go: k8s.io/apiserver/pkg/endpoints/handlers/fieldmanager/versionconverter.go

In order to keep maintenance as minimal as possible the borrowed files are verbatim copy from Kubernetes. The private objects that need to be exposed are wrapped in the wrapper.go file. Updating the borrowed files should be trivial in most cases but must be done manually as we have no control over future refactorings Kubernetes might do.

Index

Constants

This section is empty.

Variables

View Source
var EmptyFields = func() metav1.FieldsV1 {
	f, err := SetToFields(*fieldpath.NewSet())
	if err != nil {
		panic("should never happen")
	}
	return f
}()

EmptyFields represents a set with no paths It looks like metav1.Fields{Raw: []byte("{}")}

Functions

func BuildManagerIdentifier

func BuildManagerIdentifier(encodedManager *metav1.ManagedFieldsEntry) (manager string, err error)

BuildManagerIdentifier creates a manager identifier string from a ManagedFieldsEntry

func EncodeObjectManagedFields

func EncodeObjectManagedFields(obj runtime.Object, managed ManagedInterface) error

EncodeObjectManagedFields converts and stores the fieldpathManagedFields into the objects ManagedFields

func FieldsToSet

func FieldsToSet(f metav1.FieldsV1) (s fieldpath.Set, err error)

FieldsToSet creates a set paths from an input trie of fields

func NewVersionConverter

func NewVersionConverter(gvkParser *managedfields.GvkParser, o runtime.ObjectConvertor, h schema.GroupVersion) merge.Converter

NewVersionConverter will expose the version converter from the borrowed private function from k8s apiserver handler.

func RemoveObjectManagedFields

func RemoveObjectManagedFields(obj runtime.Object)

RemoveObjectManagedFields removes the ManagedFields from the object before we merge so that it doesn't appear in the ManagedFields recursively.

func SetToFields

func SetToFields(s fieldpath.Set) (f metav1.FieldsV1, err error)

SetToFields creates a trie of fields from an input set of paths

Types

type DeducedTypeConverter

type DeducedTypeConverter struct{}

DeducedTypeConverter is a TypeConverter for CRDs that don't have a schema. It does implement the same interface though (and create the same types of objects), so that everything can still work the same. CRDs are merged with all their fields being "atomic" (lists included).

Note that this is not going to be sufficient for converting to/from CRDs that have a schema defined (we don't support that schema yet). TODO(jennybuckley): Use the schema provided by a CRD if it exists.

func (DeducedTypeConverter) ObjectToTyped

func (DeducedTypeConverter) ObjectToTyped(obj runtime.Object) (*typed.TypedValue, error)

ObjectToTyped converts an object into a TypedValue with a "deduced type".

func (DeducedTypeConverter) TypedToObject

func (DeducedTypeConverter) TypedToObject(value *typed.TypedValue) (runtime.Object, error)

TypedToObject transforms the typed value into a runtime.Object. That is not specific to deduced type.

type ManagedInterface

type ManagedInterface interface {
	// Fields gets the fieldpath.ManagedFields.
	Fields() fieldpath.ManagedFields

	// Times gets the timestamps associated with each operation.
	Times() map[string]*metav1.Time
}

ManagedInterface groups a fieldpath.ManagedFields together with the timestamps associated with each operation.

func DecodeManagedFields

func DecodeManagedFields(encodedManagedFields []metav1.ManagedFieldsEntry) (ManagedInterface, error)

DecodeManagedFields converts ManagedFields from the wire format (api format) to the format used by sigs.k8s.io/structured-merge-diff

func NewEmptyManaged

func NewEmptyManaged() ManagedInterface

NewEmptyManaged creates an empty ManagedInterface.

func NewManaged

NewManaged creates a ManagedInterface from a fieldpath.ManagedFields and the timestamps associated with each operation.

type TypeConverter

type TypeConverter interface {
	ObjectToTyped(runtime.Object) (*typed.TypedValue, error)
	TypedToObject(*typed.TypedValue) (runtime.Object, error)
}

TypeConverter allows you to convert from runtime.Object to typed.TypedValue and the other way around.

func NewTypeConverter

func NewTypeConverter(models proto.Models, preserveUnknownFields bool) (TypeConverter, error)

NewTypeConverter builds a TypeConverter from a proto.Models. This will automatically find the proper version of the object, and the corresponding schema information.

Jump to

Keyboard shortcuts

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