resource

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: Apache-2.0 Imports: 10 Imported by: 80

Documentation

Overview

Package resource implements representations of k8s API resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

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

Factory makes instances of Resource.

func NewFactory

func NewFactory(kf ifc.KunstructuredFactory) *Factory

NewFactory makes an instance of Factory.

func (*Factory) FromBytes

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

FromBytes unmarshals bytes into one Resource.

func (*Factory) FromKunstructured

func (rf *Factory) FromKunstructured(u ifc.Kunstructured) *Resource

FromKunstructured returns a new instance of 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

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) FromMapWithNamespace

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

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

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.KunstructuredHasher

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) SliceFromBytes

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

SliceFromBytes unmarshals bytes into a Resource slice.

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 ResCtx

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

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 ResCtxMatcher

type ResCtxMatcher func(ResCtx) bool

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

type Resource

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

Resource is a representation of a Kubernetes Resource Model object paired with metadata used by kustomize.

At time of writing Resource is changing from being based on an object sitting behind

sigs.k8s.io/kustomize/api/ifc.Unstructured

to being based on an instance of

sigs.k8s.io/kustomize/kyaml/yaml.RNode

Ultimately, use of the Resource struct in kustomize should be entirely replaced by instances of RNode for direct use in kyaml, with all metadata stored directly in the RNodes as short-lived annotations, to be deleted before final output as part of a final filtration step. Using annotations will allow pipelined KRM Config Functions to share metadata that would otherwise be hidden in kustomize-only structures.

ifc.Unstructured is an interface hiding an instance of

sigs.k8s.io/kustomize/api/k8sdeps/kunstruct.UnstructAdapter

which in turn adapts an instance of

k8s.io/apimachinery/pkg/apis/meta/v1/unstructured

to the ifc.Unstructured interface. This latter code handles mutations in the old code.

The rule in kustomize development has been

                        api/
              k8sdeps/ ifc/ krusty/ theRest/

1) Depend on k8s.io/ only via sigs.k8s.io/kustomize/api/k8sdeps.

2) Instances created in k8sdeps/ can only be injected into theRest/
   behind interfaces defined in ifc/, arranged by a small bit of code
   in krusty/.  Nothing in theRest/ can import k8sdeps/.

This was to allow for importing kustomize code into kubectl, which also depends on k8s.io/apimachinery, albeit via a strange, old arrangement predating Go modules. The idea was to copy the k8sdeps/ tree into kubectl via a large PR, and depend on the rest via vendoring (and a small copy of krusty/ code). Over 2019, however, kubectl underwent large code changes including a switch to Go modules, and an attempt to extract it from the k8s repo, and this made large kustomize integration PRs hard to get through code review.

The new plan is to eliminate k8sdeps/ entirely, along with its k8s.io/ dependence, switch to kyaml, and thus allow kustomize to be imported into kubectl via normal Go module imports.

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) AppendRefBy

func (r *Resource) AppendRefBy(id resid.ResId)

AppendRefBy appends a ResId into the refBy list

func (*Resource) AppendRefVarName

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

AppendRefVarName appends a name of a var into the refVar list

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) Copy added in v0.4.2

func (r *Resource) Copy() ifc.Kunstructured

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) Equals

func (r *Resource) Equals(o *Resource) bool

func (*Resource) GetAnnotations added in v0.4.2

func (r *Resource) GetAnnotations() map[string]string

func (*Resource) GetBool added in v0.4.2

func (r *Resource) GetBool(p string) (bool, error)

func (*Resource) GetFieldValue added in v0.4.2

func (r *Resource) GetFieldValue(f string) (interface{}, error)

func (*Resource) GetFloat64 added in v0.4.2

func (r *Resource) GetFloat64(p string) (float64, error)

func (*Resource) GetGvk added in v0.4.2

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

func (*Resource) GetInt64 added in v0.4.2

func (r *Resource) GetInt64(p string) (int64, error)

func (*Resource) GetKind added in v0.4.2

func (r *Resource) GetKind() string

func (*Resource) GetLabels added in v0.4.2

func (r *Resource) GetLabels() map[string]string

func (*Resource) GetMap added in v0.4.2

func (r *Resource) GetMap(p string) (map[string]interface{}, error)

func (*Resource) GetName added in v0.4.2

func (r *Resource) GetName() string

func (*Resource) GetNamePrefixes

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

Implements ResCtx GetNamePrefixes

func (*Resource) GetNameSuffixes

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

Implements ResCtx GetNameSuffixes

func (*Resource) GetNamespace

func (r *Resource) GetNamespace() string

GetNamespace returns the namespace the resource thinks it's in.

func (*Resource) GetOriginalName

func (r *Resource) GetOriginalName() string

func (*Resource) GetOriginalNs

func (r *Resource) GetOriginalNs() string

func (*Resource) GetOutermostNamePrefix

func (r *Resource) GetOutermostNamePrefix() string

Implements ResCtx GetOutermostNamePrefix

func (*Resource) GetOutermostNameSuffix

func (r *Resource) GetOutermostNameSuffix() string

Implements ResCtx GetOutermostNameSuffix

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) GetSlice added in v0.4.2

func (r *Resource) GetSlice(p string) ([]interface{}, error)

func (*Resource) GetString added in v0.4.2

func (r *Resource) GetString(p string) (string, error)

func (*Resource) GetStringMap added in v0.4.2

func (r *Resource) GetStringMap(p string) (map[string]string, error)

func (*Resource) GetStringSlice added in v0.4.2

func (r *Resource) GetStringSlice(p string) ([]string, error)

func (*Resource) InSameKustomizeCtx

func (r *Resource) InSameKustomizeCtx(rctxm ResCtxMatcher) bool

This is used to compute if a referrer could potentially be impacted by the change of name of a referral.

func (*Resource) KunstructEqual

func (r *Resource) KunstructEqual(o *Resource) bool

func (*Resource) Map added in v0.4.2

func (r *Resource) Map() map[string]interface{}

func (*Resource) MarshalJSON added in v0.4.2

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

func (*Resource) MatchesAnnotationSelector added in v0.4.2

func (r *Resource) MatchesAnnotationSelector(selector string) (bool, error)

func (*Resource) MatchesLabelSelector added in v0.4.2

func (r *Resource) MatchesLabelSelector(selector string) (bool, error)

func (*Resource) Merge

func (r *Resource) Merge(other *Resource)

Merge performs merge with other resource.

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. TODO: compute this once and save it in the resource.

func (*Resource) OutermostPrefixSuffixEquals

func (r *Resource) OutermostPrefixSuffixEquals(o ResCtx) bool

OutermostPrefixSuffixEquals returns true if both resources outer suffix and prefix matches.

func (*Resource) Patch added in v0.4.2

func (r *Resource) Patch(other ifc.Kunstructured) error

func (*Resource) PrefixesSuffixesEquals

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

PrefixesSuffixesEquals is conceptually doing the same task as OutermostPrefixSuffix but performs a deeper comparison of the suffix and prefix slices.

Important note: The PrefixSuffixTransformer is stacking the prefix values in the reverse order of appearance in the transformed name. For this reason the sameEndingSubarray method is used (as opposed to the sameBeginningSubarray) to compare the prefix slice. In the same spirit, the GetOutermostNamePrefix is using the last element of the nameprefix slice and not the first.

func (*Resource) ReferencesEqual

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

func (*Resource) Replace

func (r *Resource) Replace(other *Resource)

Replace performs replace with other resource.

func (*Resource) ResetPrimaryData added in v0.4.2

func (r *Resource) ResetPrimaryData(incoming *Resource)

func (*Resource) SetAnnotations added in v0.4.2

func (r *Resource) SetAnnotations(m map[string]string)

func (*Resource) SetGvk added in v0.4.2

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

func (*Resource) SetLabels added in v0.4.2

func (r *Resource) SetLabels(m map[string]string)

func (*Resource) SetMap added in v0.4.2

func (r *Resource) SetMap(m map[string]interface{})

func (*Resource) SetName added in v0.4.2

func (r *Resource) SetName(n string)

func (*Resource) SetNamespace added in v0.4.2

func (r *Resource) SetNamespace(n string)

func (*Resource) SetOptions

func (r *Resource) SetOptions(o *types.GenArgs)

SetOptions updates the generator options for the resource.

func (*Resource) String

func (r *Resource) String() string

String returns resource as JSON.

func (*Resource) UnmarshalJSON added in v0.4.2

func (r *Resource) UnmarshalJSON(s []byte) error

Jump to

Keyboard shortcuts

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