transformations

package
v0.20.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultSummarizingRules

type DefaultSummarizingRules struct{}

DefaultSummarizingRules provides a default minimal implementation of SummarizingRules. It only adds a status field, which for now is always promoted (see comments below in the code).

func (*DefaultSummarizingRules) FieldsToSummarize

func (*DefaultSummarizingRules) SummarizingRulesFor

func (s *DefaultSummarizingRules) SummarizingRulesFor(resource metav1.Object) (SummarizingRules, error)

type Field

type Field interface {
	// Set allows setting the value of this field on a resource.
	Set(resource *unstructured.Unstructured, value interface{}) error
	// Get allows getting the value of this field from a resource.
	// The retrieved value should be deep-copied before mutation.
	Get(resource *unstructured.Unstructured) (interface{}, bool, error)
	// Delete allows deleting this field from a resource
	Delete(resource *unstructured.Unstructured)
	// Path provides the path of this field, which will be used as the key
	// in the map of overriding field values (for a SyncTarget),
	// stored on the resource as an annotation.
	Path() string
}

Field defines a Field that can be overridden by the Syncer for a given Synctarget. This is an interface since they would be several ways to identify a field. First implementation is very limited and doesn't support lists (ex: "status", "spec.ClusterIP"). It could also support JsonPath.

type FieldSummarizingRules

type FieldSummarizingRules interface {
	// IsStatus if the field is part of the status sub-resource.
	// This is important, since it drives how the field will be updated
	// during the transformation (according to the subresource
	// of the Update / Get action).
	IsStatus() bool
	// CanPromoteToUpstream defines if the field should be promoted to the upstream resource
	// (when the resource is scheduled on only one Synctarget of course).
	// Promoted fields are always owned by the Syncer.
	CanPromoteToUpstream() bool
}

FieldSummarizingRules defines rules according to which the summarized field should be managed. More rules might be added in the future.

type FieldToSummarize

type FieldToSummarize interface {
	Field
	FieldSummarizingRules
}

FieldToSummarize defines a Field that can be overridden by the Syncer for a given Synctarget, as well as the rules according to which it will be managed.

type SpecDiffTransformation

type SpecDiffTransformation struct{}

func (*SpecDiffTransformation) ToSyncerView

func (*SpecDiffTransformation) ToSyncerView(syncTargetKey string, gvr schema.GroupVersionResource, newUpstreamResource *unstructured.Unstructured, overridenSyncerViewFields map[string]interface{}, requestedSyncing map[string]helpers.SyncIntent) (newSyncerViewResource *unstructured.Unstructured, err error)

func (*SpecDiffTransformation) TransformationFor

func (t *SpecDiffTransformation) TransformationFor(resource metav1.Object) (Transformation, error)

type SummarizingRules

type SummarizingRules interface {
	FieldsToSummarize(gvr schema.GroupVersionResource) []FieldToSummarize
}

SummarizingRules defines rules that drive the way some specified fields (typically the status, but not limited to it), when updated by the Syncer, are managed by the Syncer Virtual Workspace with 2 possible options:

  • either stored in the SyncerView (as overriding field values in an annotation)
  • or promoted to the upstream object itself.

type SummarizingRulesProvider

type SummarizingRulesProvider interface {
	SummarizingRulesFor(resource metav1.Object) (SummarizingRules, error)
}

SummarizingRulesProvider provides appropriate SummarizingRules based on the content of a resource.

type SyncerResourceTransformer

type SyncerResourceTransformer struct {
	ShardExternalURL string

	TransformationProvider
	SummarizingRulesProvider
}

SyncerResourceTransformer manages both the transformation of resources exposed to a Syncer when syncing to downstream, and the management of fields updated by the Syncer when syncing back to upstream.

func (*SyncerResourceTransformer) AfterRead

AfterRead implements transforming.ResourceTransformer.AfterRead. It will be called when an upstream resource is read from the Syncer Virtual Workspace for a given SyncTarget (typically by the Syncer). It transforms the upstream resource according to the provided Transformation, and applies on top of the transformed resource every summarized fields previously updated by the Syncer.

func (*SyncerResourceTransformer) BeforeWrite

BeforeWrite implements transforming.ResourceTransformer.BeforeWrite. It will be called when the Syncer updates a given resource through the Syncer virtual workspace. It performs the appropriate cleanup of the resource if the Syncer doesn't own the resource anymore (syncer finalizer was removed). In all other cases, it applies every summarized fields updated by the Syncer to the Syncer View annotation, possibly promoting it to te upstream resource.

func (SyncerResourceTransformer) SummarizingRulesFor

func (srt SyncerResourceTransformer) SummarizingRulesFor(resource metav1.Object) (SummarizingRules, error)

SummarizingRulesFor implements [SummarizingRulesProvider.SummarizingRulesFor].

func (SyncerResourceTransformer) TransformationFor

func (srt SyncerResourceTransformer) TransformationFor(resource metav1.Object) (Transformation, error)

TransformationFor implements [TransformationProvider.TransformationFor].

type Transformation

type Transformation interface {
	ToSyncerView(SyncTargetKey string, gvr schema.GroupVersionResource, upstreamResource *unstructured.Unstructured, overridenSyncerViewFields map[string]interface{}, requestedSyncing map[string]helpers.SyncIntent) (newSyncerViewResource *unstructured.Unstructured, err error)
}

Transformation defines the action of transforming an resource when exposing it to the Syncer for a given SyncTarget through the Syncer Virtual Workspace. That's why the transformed resource is called the Syncer View.

In addition to the upstream resource to transform, the transformation parameters also involve:

  • the overriding values of Syncer View summarized fields (the fields that the

Syncer previously overrode, typically when updating the status, but this could also contain specific Spec fields)

  • the requested syncing intents for all SyncTargets.

type TransformationProvider

type TransformationProvider interface {
	TransformationFor(resource metav1.Object) (Transformation, error)
}

TransformationProvider provides an appropriate Transformation based on the content of a resource.

Jump to

Keyboard shortcuts

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