...

Package resource

import "sigs.k8s.io/kustomize/api/resource"
Overview
Index

Overview ▾

Package resource implements representations of k8s API resources.

Index ▾

Variables
type Factory
    func NewFactory(h ifc.KustHasher) *Factory
    func (rf *Factory) DropLocalNodes(nodes []*yaml.RNode) ([]*Resource, error)
    func (rf *Factory) FromBytes(in []byte) (*Resource, error)
    func (rf *Factory) FromMap(m map[string]interface{}) *Resource
    func (rf *Factory) FromMapAndOption(m map[string]interface{}, args *types.GeneratorArgs) (*Resource, error)
    func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource
    func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource
    func (rf *Factory) Hasher() ifc.KustHasher
    func (rf *Factory) MakeConfigMap(kvLdr ifc.KvLoader, args *types.ConfigMapArgs) (*Resource, error)
    func (rf *Factory) MakeSecret(kvLdr ifc.KvLoader, args *types.SecretArgs) (*Resource, error)
    func (rf *Factory) RNodesFromBytes(b []byte) ([]*yaml.RNode, error)
    func (rf *Factory) ResourcesFromRNodes(nodes []*yaml.RNode) (result []*Resource, err error)
    func (rf *Factory) SliceFromBytes(in []byte) ([]*Resource, error)
    func (rf *Factory) SliceFromBytesWithNames(names []string, in []byte) ([]*Resource, error)
    func (rf *Factory) SliceFromPatches(ldr ifc.Loader, paths []types.PatchStrategicMerge) ([]*Resource, error)
type IdSet
    func MakeIdSet(slice []*Resource) *IdSet
    func (s IdSet) Contains(id resid.ResId) bool
    func (s IdSet) Size() int
type Origin
    func OriginFromCustomPlugin(res *Resource) (*Origin, error)
    func (origin *Origin) Append(path string) *Origin
    func (origin *Origin) Copy() Origin
    func (origin *Origin) String() (string, error)
type ResCtx
type ResCtxMatcher
type Resource
    func (r *Resource) AddNamePrefix(p string)
    func (r *Resource) AddNameSuffix(s string)
    func (r *Resource) AddTransformation(origin *Origin) error
    func (r *Resource) AllowKindChange()
    func (r *Resource) AllowNameChange()
    func (r *Resource) AppendRefBy(id fmt.Stringer)
    func (r *Resource) AppendRefVarName(variable types.Var)
    func (r *Resource) ApplyFilter(f kio.Filter) error
    func (r *Resource) ApplySmPatch(patch *Resource) error
    func (r *Resource) AsYAML() ([]byte, error)
    func (r *Resource) Behavior() types.GenerationBehavior
    func (r *Resource) ClearTransformations() error
    func (r *Resource) CopyMergeMetaDataFieldsFrom(other *Resource) error
    func (r *Resource) CurId() resid.ResId
    func (r *Resource) DeepCopy() *Resource
    func (r *Resource) EnableHashSuffix()
    func (r *Resource) ErrIfNotEquals(o *Resource) error
    func (r *Resource) GetGvk() resid.Gvk
    func (r *Resource) GetNamePrefixes() []string
    func (r *Resource) GetNameSuffixes() []string
    func (r *Resource) GetOrigin() (*Origin, error)
    func (r *Resource) GetRefBy() []resid.ResId
    func (r *Resource) GetRefVarNames() []string
    func (r *Resource) GetTransformations() (Transformations, error)
    func (r *Resource) Hash(h ifc.KustHasher) (string, error)
    func (r *Resource) KindChangeAllowed() bool
    func (r *Resource) MergeBinaryDataMapFrom(o *Resource)
    func (r *Resource) MergeDataMapFrom(o *Resource)
    func (r *Resource) MustYaml() string
    func (r *Resource) NameChangeAllowed() bool
    func (r *Resource) NeedHashSuffix() bool
    func (r *Resource) OrgId() resid.ResId
    func (r *Resource) PrefixesSuffixesEquals(o ResCtx, allowEmpty bool) bool
    func (r *Resource) PrevIds() []resid.ResId
    func (r *Resource) ReferencesEqual(other *Resource) bool
    func (r *Resource) RemoveBuildAnnotations()
    func (r *Resource) ResetRNode(incoming *Resource)
    func (r *Resource) SetBehavior(behavior types.GenerationBehavior)
    func (r *Resource) SetGvk(gvk resid.Gvk)
    func (r *Resource) SetOrigin(origin *Origin) error
    func (r *Resource) StorePreviousId()
    func (r *Resource) String() string
type Transformations
    func (transformations *Transformations) String() (string, error)

Package files

doc.go factory.go idset.go origin.go resource.go

Variables

var BuildAnnotations = []string{
    utils.BuildAnnotationPreviousKinds,
    utils.BuildAnnotationPreviousNames,
    utils.BuildAnnotationPrefixes,
    utils.BuildAnnotationSuffixes,
    utils.BuildAnnotationPreviousNamespaces,
    utils.BuildAnnotationAllowNameChange,
    utils.BuildAnnotationAllowKindChange,
    utils.BuildAnnotationsRefBy,
    utils.BuildAnnotationsGenBehavior,
    utils.BuildAnnotationsGenAddHashSuffix,

    kioutil.PathAnnotation,
    kioutil.IndexAnnotation,
    kioutil.SeqIndentAnnotation,
    kioutil.IdAnnotation,
    kioutil.InternalAnnotationsMigrationResourceIDAnnotation,

    kioutil.LegacyPathAnnotation,
    kioutil.LegacyIndexAnnotation,
    kioutil.LegacyIdAnnotation,
}

type Factory

Factory makes instances of Resource.

type Factory struct {

    // When set to true, IncludeLocalConfigs indicates
    // that Factory should include resources with the
    // annotation 'config.kubernetes.io/local-config'.
    // By default these resources are ignored.
    IncludeLocalConfigs bool
    // contains filtered or unexported fields
}

func NewFactory

func NewFactory(h ifc.KustHasher) *Factory

NewFactory makes an instance of Factory.

func (*Factory) DropLocalNodes

func (rf *Factory) DropLocalNodes(nodes []*yaml.RNode) ([]*Resource, error)

DropLocalNodes removes the local nodes by default. Local nodes are detected via the annotation `config.kubernetes.io/local-config: "true"`

func (*Factory) FromBytes

func (rf *Factory) FromBytes(in []byte) (*Resource, error)

FromBytes unmarshalls bytes into one Resource.

func (*Factory) FromMap

func (rf *Factory) FromMap(m map[string]interface{}) *Resource

FromMap returns a new instance of Resource.

func (*Factory) FromMapAndOption

func (rf *Factory) FromMapAndOption(
    m map[string]interface{}, args *types.GeneratorArgs) (*Resource, error)

FromMapAndOption returns a new instance of Resource with given options.

func (*Factory) FromMapWithName

func (rf *Factory) FromMapWithName(n string, m map[string]interface{}) *Resource

FromMapWithName returns a new instance with the given "original" name.

func (*Factory) FromMapWithNamespaceAndName

func (rf *Factory) FromMapWithNamespaceAndName(ns string, n string, m map[string]interface{}) *Resource

FromMapWithNamespaceAndName returns a new instance with the given "original" namespace.

func (*Factory) Hasher

func (rf *Factory) Hasher() ifc.KustHasher

Hasher returns an ifc.KustHasher

func (*Factory) MakeConfigMap

func (rf *Factory) MakeConfigMap(kvLdr ifc.KvLoader, args *types.ConfigMapArgs) (*Resource, error)

MakeConfigMap makes an instance of Resource for ConfigMap

func (*Factory) MakeSecret

func (rf *Factory) MakeSecret(kvLdr ifc.KvLoader, args *types.SecretArgs) (*Resource, error)

MakeSecret makes an instance of Resource for Secret

func (*Factory) RNodesFromBytes

func (rf *Factory) RNodesFromBytes(b []byte) ([]*yaml.RNode, error)

func (*Factory) ResourcesFromRNodes

func (rf *Factory) ResourcesFromRNodes(
    nodes []*yaml.RNode) (result []*Resource, err error)

ResourcesFromRNodes converts RNodes to Resources.

func (*Factory) SliceFromBytes

func (rf *Factory) SliceFromBytes(in []byte) ([]*Resource, error)

SliceFromBytes unmarshals bytes into a Resource slice.

func (*Factory) SliceFromBytesWithNames

func (rf *Factory) SliceFromBytesWithNames(names []string, in []byte) ([]*Resource, error)

SliceFromBytesWithNames unmarshals bytes into a Resource slice with specified original name.

func (*Factory) SliceFromPatches

func (rf *Factory) SliceFromPatches(
    ldr ifc.Loader, paths []types.PatchStrategicMerge) ([]*Resource, error)

SliceFromPatches returns a slice of resources given a patch path slice from a kustomization file.

type IdSet

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

func MakeIdSet

func MakeIdSet(slice []*Resource) *IdSet

func (IdSet) Contains

func (s IdSet) Contains(id resid.ResId) bool

func (IdSet) Size

func (s IdSet) Size() int

type Origin

Origin retains information about the origin of resources and transformer configs that contributed to the output of `kustomize build`

type Origin struct {
    // Path is the path to the resource. If a local resource, this path is
    // rooted from the directory upon which `kustomize build` was invoked. If a
    // remote resource, this path is rooted from the root of the remote repo.
    Path string `json:"path,omitempty" yaml:"path,omitempty"`

    // Repo is the remote repository that the resource or transformer originated from if it is
    // not from a local file
    Repo string `json:"repo,omitempty" yaml:"repo,omitempty"`

    // Ref is the ref of the remote repository that the resource or transformer originated from
    // if it is not from a local file
    Ref string `json:"ref,omitempty" yaml:"ref,omitempty"`

    // ConfiguredIn is the file path to the generator or transformer config that created the
    // resource
    ConfiguredIn string `json:"configuredIn,omitempty" yaml:"configuredIn,omitempty"`

    // ConfiguredBy is the ObjectReference of the generator or transformer config
    ConfiguredBy kyaml.ResourceIdentifier `json:"configuredBy,omitempty" yaml:"configuredBy,omitempty"`
}

func OriginFromCustomPlugin

func OriginFromCustomPlugin(res *Resource) (*Origin, error)

OriginFromCustomPlugin takes a custom plugin defined as a resource and returns an origin object to describe it

func (*Origin) Append

func (origin *Origin) Append(path string) *Origin

Append returns a copy of origin with a path appended to it

func (*Origin) Copy

func (origin *Origin) Copy() Origin

Copy returns a copy of origin

func (*Origin) String

func (origin *Origin) String() (string, error)

String returns a string version of origin

type ResCtx

ResCtx is an interface describing the contextual added kept kustomize in the context of each Resource object. Currently mainly the name prefix and name suffix are added.

type ResCtx interface {
    AddNamePrefix(p string)
    AddNameSuffix(s string)
    GetNamePrefixes() []string
    GetNameSuffixes() []string
}

type ResCtxMatcher

ResCtxMatcher returns true if two Resources are being modified in the same kustomize context.

type ResCtxMatcher func(ResCtx) bool

type Resource

Resource is an RNode, representing a Kubernetes Resource Model object, paired with metadata used by kustomize.

type Resource struct {
    kyaml.RNode
    // contains filtered or unexported fields
}

func (*Resource) AddNamePrefix

func (r *Resource) AddNamePrefix(p string)

Implements ResCtx AddNamePrefix

func (*Resource) AddNameSuffix

func (r *Resource) AddNameSuffix(s string)

Implements ResCtx AddNameSuffix

func (*Resource) AddTransformation

func (r *Resource) AddTransformation(origin *Origin) error

func (*Resource) AllowKindChange

func (r *Resource) AllowKindChange()

AllowKindChange allows kind changes to the resource.

func (*Resource) AllowNameChange

func (r *Resource) AllowNameChange()

AllowNameChange allows name changes to the resource.

func (*Resource) AppendRefBy

func (r *Resource) AppendRefBy(id fmt.Stringer)

AppendRefBy appends a ResId into the refBy list Using any type except fmt.Stringer here results in a compilation error

func (*Resource) AppendRefVarName

func (r *Resource) AppendRefVarName(variable types.Var)

AppendRefVarName appends a name of a var into the refVar list

func (*Resource) ApplyFilter

func (r *Resource) ApplyFilter(f kio.Filter) error

func (*Resource) ApplySmPatch

func (r *Resource) ApplySmPatch(patch *Resource) error

ApplySmPatch applies the provided strategic merge patch.

func (*Resource) AsYAML

func (r *Resource) AsYAML() ([]byte, error)

AsYAML returns the resource in Yaml form. Easier to read than JSON.

func (*Resource) Behavior

func (r *Resource) Behavior() types.GenerationBehavior

Behavior returns the behavior for the resource.

func (*Resource) ClearTransformations

func (r *Resource) ClearTransformations() error

func (*Resource) CopyMergeMetaDataFieldsFrom

func (r *Resource) CopyMergeMetaDataFieldsFrom(other *Resource) error

CopyMergeMetaDataFieldsFrom copies everything but the non-metadata in the resource. TODO: move to RNode, use GetMeta to improve performance. TODO: make a version of mergeStringMaps that is build-annotation aware

to avoid repeatedly setting refby and genargs annotations

Must remove the kustomize bit at the end.

func (*Resource) CurId

func (r *Resource) CurId() resid.ResId

CurId returns a ResId for the resource using the mutable parts of the resource. This should be unique in any ResMap.

func (*Resource) DeepCopy

func (r *Resource) DeepCopy() *Resource

DeepCopy returns a new copy of resource

func (*Resource) EnableHashSuffix

func (r *Resource) EnableHashSuffix()

EnableHashSuffix marks the resource as needing a content hash to be appended to the name of the resource.

func (*Resource) ErrIfNotEquals

func (r *Resource) ErrIfNotEquals(o *Resource) error

func (*Resource) GetGvk

func (r *Resource) GetGvk() resid.Gvk

func (*Resource) GetNamePrefixes

func (r *Resource) GetNamePrefixes() []string

Implements ResCtx GetNamePrefixes

func (*Resource) GetNameSuffixes

func (r *Resource) GetNameSuffixes() []string

Implements ResCtx GetNameSuffixes

func (*Resource) GetOrigin

func (r *Resource) GetOrigin() (*Origin, error)

func (*Resource) GetRefBy

func (r *Resource) GetRefBy() []resid.ResId

GetRefBy returns the ResIds that referred to current resource

func (*Resource) GetRefVarNames

func (r *Resource) GetRefVarNames() []string

GetRefVarNames returns vars that refer to current resource

func (*Resource) GetTransformations

func (r *Resource) GetTransformations() (Transformations, error)

func (*Resource) Hash

func (r *Resource) Hash(h ifc.KustHasher) (string, error)

func (*Resource) KindChangeAllowed

func (r *Resource) KindChangeAllowed() bool

KindChangeAllowed checks if a patch resource is allowed to change another resource's kind.

func (*Resource) MergeBinaryDataMapFrom

func (r *Resource) MergeBinaryDataMapFrom(o *Resource)

func (*Resource) MergeDataMapFrom

func (r *Resource) MergeDataMapFrom(o *Resource)

func (*Resource) MustYaml

func (r *Resource) MustYaml() string

MustYaml returns YAML or panics.

func (*Resource) NameChangeAllowed

func (r *Resource) NameChangeAllowed() bool

NameChangeAllowed checks if a patch resource is allowed to change another resource's name.

func (*Resource) NeedHashSuffix

func (r *Resource) NeedHashSuffix() bool

NeedHashSuffix returns true if a resource content hash should be appended to the name of the resource.

func (*Resource) OrgId

func (r *Resource) OrgId() resid.ResId

OrgId returns the original, immutable ResId for the resource. This doesn't have to be unique in a ResMap.

func (*Resource) PrefixesSuffixesEquals

func (r *Resource) PrefixesSuffixesEquals(o ResCtx, allowEmpty bool) bool

PrefixesSuffixesEquals is conceptually doing the same task as OutermostPrefixSuffix but performs a deeper comparison of the suffix and prefix slices. The allowEmpty flag determines whether an empty prefix/suffix should be considered a match on anything. This is used when filtering, starting with a coarser pass allowing empty matches, before requiring exact matches if there are multiple remaining candidates.

func (*Resource) PrevIds

func (r *Resource) PrevIds() []resid.ResId

PrevIds returns a list of ResIds that includes every previous ResId the resource has had through all of its GVKN transformations, in the order that it had that ID. I.e. the oldest ID is first. The returned array does not include the resource's current ID. If there are no previous IDs, this will return nil.

func (*Resource) ReferencesEqual

func (r *Resource) ReferencesEqual(other *Resource) bool

func (*Resource) RemoveBuildAnnotations

func (r *Resource) RemoveBuildAnnotations()

RemoveBuildAnnotations removes annotations created by the build process. These are internal-only to kustomize, added to the data pipeline to track name changes so name references can be fixed.

func (*Resource) ResetRNode

func (r *Resource) ResetRNode(incoming *Resource)

func (*Resource) SetBehavior

func (r *Resource) SetBehavior(behavior types.GenerationBehavior)

SetBehavior sets the behavior for the resource.

func (*Resource) SetGvk

func (r *Resource) SetGvk(gvk resid.Gvk)

func (*Resource) SetOrigin

func (r *Resource) SetOrigin(origin *Origin) error

func (*Resource) StorePreviousId

func (r *Resource) StorePreviousId()

StorePreviousId stores the resource's current ID via build annotations.

func (*Resource) String

func (r *Resource) String() string

String returns resource as JSON.

type Transformations

Transformations is a list of Origin

type Transformations []*Origin

func (*Transformations) String

func (transformations *Transformations) String() (string, error)

String returns a string version of Transformations