merge3

package
v1.0.2-pre.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package merge3 executes a 3-way merge update

Index

Constants

View Source
const (
	MergeCommentPrefix = "kpt-merge:"
)

Variables

This section is empty.

Functions

func FilterCrds

func FilterCrds(kos fn.KubeObjects) (filtered fn.KubeObjects, crds fn.KubeObjects)

FilterCrds splits the input between non-CRD and CRD KubeObjects.

func GetHandlingStrategy

func GetHandlingStrategy(original, updated, dest *yaml.RNode) filters.ResourceMergeStrategy

GetHandlingStrategy is an implementation of the ResourceHandler.Handle method from kyaml. It is used to decide how a resource should be handled during the 3-way merge. This differs from the default implementation in that if a resource is deleted from upstream, it will only be deleted from local if there is no diff between origin and local.

func IsCleared

func IsCleared(left, right *kyaml.RNode) bool

IsCleared returns if the node has not tagged null in `left` but explicitly removed in `right`

func IsCrd

func IsCrd(ko *fn.KubeObject) bool

func KeepNull

func KeepNull(n *kyaml.RNode) *kyaml.RNode

KeepNull marks a tagged null so FieldSetter will not drop it. Other nodes are returned unchanged.

func Merge

func Merge(original, updated, destination fn.KubeObjects, additionalSchemas []byte, preserveNulls bool) (fn.KubeObjects, error)

Merge performs a 3-way merge of original, updated and destination resources.

func MergeTuples

func MergeTuples(tl tuples) (kio.ResourceNodeSlice, error)

func NsAndNameForMerge

func NsAndNameForMerge(metadataComment string) []string

NsAndNameForMerge returns the namespace and name for merge from the line comment on the metadata field e.g. metadata: # kpt-merge: default/foo returns [default, foo]

func PersistedNull

func PersistedNull(n *kyaml.RNode) *kyaml.RNode

PersistedNull returns n's null as an RNode that survives kyaml's generic tagged-null clearing (see yaml.MakePersistentNullNode). The scalar value is kept so an explicit "null" and an implicit empty null stay distinct.

func SchemasFromCrdKubeObject

func SchemasFromCrdKubeObject(ko *fn.KubeObject) (map[string]spec.Schema, error)

SchemasFromCrdKubeObject extracts the Kustomize OpenApi definitions keyed with their GVK from a single CRD KubeObject

func SchemasFromCrdKubeObjects

func SchemasFromCrdKubeObjects(kos fn.KubeObjects) (map[string]spec.Schema, error)

SchemasFromCrdKubeObjects extracts the Kustomize OpenApi definitions keyed with their GVK from multiple CRD KubeObjects

func SchemasFromCrdRNode

func SchemasFromCrdRNode(node *kyaml.RNode) (map[string]spec.Schema, error)

SchemasFromCrdRNode extracts all the Kustomize OpenApi definitions keyed with their GVK from a single CRD RNode

func SchemasFromCrdRNodes

func SchemasFromCrdRNodes(nodes []*kyaml.RNode) (map[string]spec.Schema, error)

SchemasFromCrdRNodes extracts all the Kustomize OpenApi definitions keyed with their GVK from multiple CRD RNodes

Types

type MergeTestResources

type MergeTestResources struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata"`

	Spec MergeTestResourcesSpec `json:"spec"`
}

type MergeTestResourcesSpec

type MergeTestResourcesSpec struct {
	PackageName    string            `json:"packageName,omitempty"`
	WorkspaceName  string            `json:"workspaceName,omitempty"`
	Revision       int               `json:"revision,omitempty"`
	RepositoryName string            `json:"repository,omitempty"`
	Resources      map[string]string `json:"resources,omitempty"`
}

type NullPreservingVisitor

type NullPreservingVisitor struct{}

NullPreservingVisitor is a copy of our Visitor that preserves nulls. This behavior is necessary when the merged packages themselves are patches.

func (*NullPreservingVisitor) VisitList

func (*NullPreservingVisitor) VisitMap

func (*NullPreservingVisitor) VisitScalar

func (m *NullPreservingVisitor) VisitScalar(nodes walk.Sources, _ *openapi.ResourceSchema) (*yaml.RNode, error)

type Visitor

type Visitor struct{}

Visitor is a copy of kyaml's sigs.k8s.io/kustomize/kyaml/yaml/merge3.Visitor that only treats a null as a delete when the origin was not already null. kyaml drops the field whenever updated or dest is null, so an upstream value is lost when origin and dest were both null.

func (*Visitor) VisitList

func (m *Visitor) VisitList(nodes walk.Sources, s *openapi.ResourceSchema, kind walk.ListKind) (*yaml.RNode, error)

func (*Visitor) VisitMap

func (m *Visitor) VisitMap(nodes walk.Sources, _ *openapi.ResourceSchema) (*yaml.RNode, error)

func (*Visitor) VisitScalar

func (m *Visitor) VisitScalar(nodes walk.Sources, _ *openapi.ResourceSchema) (*yaml.RNode, error)

Jump to

Keyboard shortcuts

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