mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Add/fix some documentation and vars names.
This commit is contained in:
@@ -30,21 +30,21 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
// KunstructurerFactoryImpl hides construction using apimachinery types.
|
||||
type KunstructurerFactoryImpl struct {
|
||||
cmfactory *configmapandsecret.ConfigMapFactory
|
||||
secfactory *configmapandsecret.SecretFactory
|
||||
// KunstructuredFactoryImpl hides construction using apimachinery types.
|
||||
type KunstructuredFactoryImpl struct {
|
||||
cmFactory *configmapandsecret.ConfigMapFactory
|
||||
secretFactory *configmapandsecret.SecretFactory
|
||||
}
|
||||
|
||||
var _ ifc.KunstructuredFactory = &KunstructurerFactoryImpl{}
|
||||
var _ ifc.KunstructuredFactory = &KunstructuredFactoryImpl{}
|
||||
|
||||
// NewKunstructuredFactoryImpl returns a factory.
|
||||
func NewKunstructuredFactoryImpl() ifc.KunstructuredFactory {
|
||||
return &KunstructurerFactoryImpl{}
|
||||
return &KunstructuredFactoryImpl{}
|
||||
}
|
||||
|
||||
// SliceFromBytes returns a slice of Kunstructured.
|
||||
func (kf *KunstructurerFactoryImpl) SliceFromBytes(
|
||||
func (kf *KunstructuredFactoryImpl) SliceFromBytes(
|
||||
in []byte) ([]ifc.Kunstructured, error) {
|
||||
decoder := yaml.NewYAMLOrJSONDecoder(bytes.NewReader(in), 1024)
|
||||
var result []ifc.Kunstructured
|
||||
@@ -71,14 +71,14 @@ func isEmptyYamlError(err error) bool {
|
||||
}
|
||||
|
||||
// FromMap returns an instance of Kunstructured.
|
||||
func (kf *KunstructurerFactoryImpl) FromMap(
|
||||
func (kf *KunstructuredFactoryImpl) FromMap(
|
||||
m map[string]interface{}) ifc.Kunstructured {
|
||||
return &UnstructAdapter{Unstructured: unstructured.Unstructured{Object: m}}
|
||||
}
|
||||
|
||||
// MakeConfigMap returns an instance of Kunstructured for ConfigMap
|
||||
func (kf *KunstructurerFactoryImpl) MakeConfigMap(args *types.ConfigMapArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
|
||||
cm, err := kf.cmfactory.MakeConfigMap(args, options)
|
||||
func (kf *KunstructuredFactoryImpl) MakeConfigMap(args *types.ConfigMapArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
|
||||
cm, err := kf.cmFactory.MakeConfigMap(args, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -86,8 +86,8 @@ func (kf *KunstructurerFactoryImpl) MakeConfigMap(args *types.ConfigMapArgs, opt
|
||||
}
|
||||
|
||||
// MakeSecret returns an instance of Kunstructured for Secret
|
||||
func (kf *KunstructurerFactoryImpl) MakeSecret(args *types.SecretArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
|
||||
sec, err := kf.secfactory.MakeSecret(args, options)
|
||||
func (kf *KunstructuredFactoryImpl) MakeSecret(args *types.SecretArgs, options *types.GeneratorOptions) (ifc.Kunstructured, error) {
|
||||
sec, err := kf.secretFactory.MakeSecret(args, options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -95,13 +95,13 @@ func (kf *KunstructurerFactoryImpl) MakeSecret(args *types.SecretArgs, options *
|
||||
}
|
||||
|
||||
// Set sets loader, filesystem and workdirectory
|
||||
func (kf *KunstructurerFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) {
|
||||
kf.cmfactory = configmapandsecret.NewConfigMapFactory(fs, ldr)
|
||||
kf.secfactory = configmapandsecret.NewSecretFactory(fs, ldr.Root())
|
||||
func (kf *KunstructuredFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) {
|
||||
kf.cmFactory = configmapandsecret.NewConfigMapFactory(fs, ldr)
|
||||
kf.secretFactory = configmapandsecret.NewSecretFactory(fs, ldr.Root())
|
||||
}
|
||||
|
||||
// validate validates that u has kind and name
|
||||
func (kf *KunstructurerFactoryImpl) validate(u unstructured.Unstructured) error {
|
||||
func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error {
|
||||
if u.GetName() == "" {
|
||||
return fmt.Errorf("Missing metadata.name in object %v", u)
|
||||
}
|
||||
|
||||
@@ -121,9 +121,10 @@ func (m ResMap) DeepCopy(rf *resource.Factory) ResMap {
|
||||
return mcopy
|
||||
}
|
||||
|
||||
// FilterBy returns a ResMap containing ResIds with the same namespace and nameprefix
|
||||
// with the inputId
|
||||
// If inputId is a cluster level resource, return the original resmap
|
||||
// FilterBy returns a subset ResMap containing ResIds with
|
||||
// the same namespace and leftmost name prefix as the
|
||||
// inputId. If inputId is a cluster level resource, this
|
||||
// returns the original ResMap.
|
||||
func (m ResMap) FilterBy(inputId resid.ResId) ResMap {
|
||||
if inputId.Gvk().IsClusterKind() {
|
||||
return m
|
||||
|
||||
@@ -45,17 +45,17 @@ type KustTarget struct {
|
||||
kustomization *types.Kustomization
|
||||
ldr ifc.Loader
|
||||
fSys fs.FileSystem
|
||||
rf *resmap.Factory
|
||||
tcfg *config.TransformerConfig
|
||||
ptf transformer.Factory
|
||||
rFactory *resmap.Factory
|
||||
tConfig *config.TransformerConfig
|
||||
tFactory transformer.Factory
|
||||
}
|
||||
|
||||
// NewKustTarget returns a new instance of KustTarget primed with a Loader.
|
||||
func NewKustTarget(
|
||||
ldr ifc.Loader, fSys fs.FileSystem,
|
||||
rf *resmap.Factory,
|
||||
ptf transformer.Factory,
|
||||
tcfg *config.TransformerConfig) (*KustTarget, error) {
|
||||
rFactory *resmap.Factory,
|
||||
tFactory transformer.Factory,
|
||||
tConfig *config.TransformerConfig) (*KustTarget, error) {
|
||||
content, err := loadKustFile(ldr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -71,9 +71,9 @@ func NewKustTarget(
|
||||
kustomization: &k,
|
||||
ldr: ldr,
|
||||
fSys: fSys,
|
||||
rf: rf,
|
||||
tcfg: tcfg,
|
||||
ptf: ptf,
|
||||
rFactory: rFactory,
|
||||
tConfig: tConfig,
|
||||
tFactory: tFactory,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -100,15 +100,20 @@ func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
|
||||
|
||||
// resolveRefsToGeneratedResources fixes all name references.
|
||||
func (kt *KustTarget) resolveRefsToGeneratedResources(m resmap.ResMap) (resmap.ResMap, error) {
|
||||
if kt.kustomization.GeneratorOptions == nil || !kt.kustomization.GeneratorOptions.DisableNameSuffixHash {
|
||||
err := kt.ptf.MakeHashTransformer().Transform(m)
|
||||
if kt.kustomization.GeneratorOptions == nil ||
|
||||
!kt.kustomization.GeneratorOptions.DisableNameSuffixHash {
|
||||
// This effects only generated resources.
|
||||
// It changes only the Name field in the
|
||||
// resource held in the ResMap's value, not
|
||||
// the Name in the key in the ResMap.
|
||||
err := kt.tFactory.MakeHashTransformer().Transform(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var r []transformers.Transformer
|
||||
t, err := transformers.NewNameReferenceTransformer(kt.tcfg.NameReference)
|
||||
t, err := transformers.NewNameReferenceTransformer(kt.tConfig.NameReference)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -118,7 +123,7 @@ func (kt *KustTarget) resolveRefsToGeneratedResources(m resmap.ResMap) (resmap.R
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
t = transformers.NewRefVarTransformer(refVars, kt.tcfg.VarReference)
|
||||
t = transformers.NewRefVarTransformer(refVars, kt.tConfig.VarReference)
|
||||
r = append(r, t)
|
||||
|
||||
err = transformers.NewMultiTransformer(r).Transform(m)
|
||||
@@ -136,7 +141,7 @@ func (kt *KustTarget) loadCustomizedResMap() (resmap.ResMap, error) {
|
||||
errs.Append(errors.Wrap(err, "loadResMapFromBasesAndResources"))
|
||||
}
|
||||
crdTc, err := config.NewFactory(kt.ldr).LoadCRDs(kt.kustomization.Crds)
|
||||
kt.tcfg = kt.tcfg.Merge(crdTc)
|
||||
kt.tConfig = kt.tConfig.Merge(crdTc)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "LoadCRDs"))
|
||||
}
|
||||
@@ -149,7 +154,7 @@ func (kt *KustTarget) loadCustomizedResMap() (resmap.ResMap, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
patches, err := kt.rf.RF().SliceFromPatches(
|
||||
patches, err := kt.rFactory.RF().SliceFromPatches(
|
||||
kt.ldr, kt.kustomization.PatchesStrategicMerge)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "SliceFromPatches"))
|
||||
@@ -186,12 +191,14 @@ func (kt *KustTarget) loadCustomizedResMap() (resmap.ResMap, error) {
|
||||
|
||||
func (kt *KustTarget) generateConfigMapsAndSecrets(
|
||||
errs *interror.KustomizationErrors) (resmap.ResMap, error) {
|
||||
kt.rf.Set(kt.fSys, kt.ldr)
|
||||
cms, err := kt.rf.NewResMapFromConfigMapArgs(kt.kustomization.ConfigMapGenerator, kt.kustomization.GeneratorOptions)
|
||||
kt.rFactory.Set(kt.fSys, kt.ldr)
|
||||
cms, err := kt.rFactory.NewResMapFromConfigMapArgs(
|
||||
kt.kustomization.ConfigMapGenerator, kt.kustomization.GeneratorOptions)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "NewResMapFromConfigMapArgs"))
|
||||
}
|
||||
secrets, err := kt.rf.NewResMapFromSecretArgs(kt.kustomization.SecretGenerator, kt.kustomization.GeneratorOptions)
|
||||
secrets, err := kt.rFactory.NewResMapFromSecretArgs(
|
||||
kt.kustomization.SecretGenerator, kt.kustomization.GeneratorOptions)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "NewResMapFromSecretArgs"))
|
||||
}
|
||||
@@ -201,7 +208,7 @@ func (kt *KustTarget) generateConfigMapsAndSecrets(
|
||||
// Gets Bases and Resources as advertised.
|
||||
func (kt *KustTarget) loadResMapFromBasesAndResources() (resmap.ResMap, error) {
|
||||
bases, errs := kt.loadCustomizedBases()
|
||||
resources, err := kt.rf.FromFiles(
|
||||
resources, err := kt.rFactory.FromFiles(
|
||||
kt.ldr, kt.kustomization.Resources)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "rawResources failed to read Resources"))
|
||||
@@ -224,7 +231,8 @@ func (kt *KustTarget) loadCustomizedBases() (resmap.ResMap, *interror.Kustomizat
|
||||
continue
|
||||
}
|
||||
target, err := NewKustTarget(
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg)
|
||||
ldr, kt.fSys,
|
||||
kt.rFactory, kt.tFactory, kt.tConfig)
|
||||
if err != nil {
|
||||
errs.Append(errors.Wrap(err, "couldn't make target for "+path))
|
||||
continue
|
||||
@@ -254,7 +262,7 @@ func (kt *KustTarget) loadBasesAsFlatList() ([]*KustTarget, error) {
|
||||
continue
|
||||
}
|
||||
target, err := NewKustTarget(
|
||||
ldr, kt.fSys, kt.rf, kt.ptf, kt.tcfg)
|
||||
ldr, kt.fSys, kt.rFactory, kt.tFactory, kt.tConfig)
|
||||
if err != nil {
|
||||
errs.Append(err)
|
||||
continue
|
||||
@@ -270,27 +278,27 @@ func (kt *KustTarget) loadBasesAsFlatList() ([]*KustTarget, error) {
|
||||
// newTransformer makes a Transformer that does everything except resolve generated names.
|
||||
func (kt *KustTarget) newTransformer(patches []*resource.Resource) (transformers.Transformer, error) {
|
||||
var r []transformers.Transformer
|
||||
t, err := kt.ptf.MakePatchTransformer(patches, kt.rf.RF())
|
||||
t, err := kt.tFactory.MakePatchTransformer(patches, kt.rFactory.RF())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, t)
|
||||
r = append(r, transformers.NewNamespaceTransformer(
|
||||
string(kt.kustomization.Namespace), kt.tcfg.NameSpace))
|
||||
string(kt.kustomization.Namespace), kt.tConfig.NameSpace))
|
||||
t, err = transformers.NewNamePrefixTransformer(
|
||||
string(kt.kustomization.NamePrefix), kt.tcfg.NamePrefix)
|
||||
string(kt.kustomization.NamePrefix), kt.tConfig.NamePrefix)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, t)
|
||||
t, err = transformers.NewLabelsMapTransformer(
|
||||
kt.kustomization.CommonLabels, kt.tcfg.CommonLabels)
|
||||
kt.kustomization.CommonLabels, kt.tConfig.CommonLabels)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r = append(r, t)
|
||||
t, err = transformers.NewAnnotationsMapTransformer(
|
||||
kt.kustomization.CommonAnnotations, kt.tcfg.CommonAnnotations)
|
||||
kt.kustomization.CommonAnnotations, kt.tConfig.CommonAnnotations)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func NewNameReferenceTransformer(
|
||||
return &nameReferenceTransformer{backRefs: br}, nil
|
||||
}
|
||||
|
||||
// Transform does the fields update according to fieldSpecs.
|
||||
// Transform does the field update according to fieldSpecs.
|
||||
// The old name is in the key in the map and the new name is in the object
|
||||
// associated with the key. e.g. if <k, v> is one of the key-value pair in the map,
|
||||
// then the old name is k.Name and the new name is v.GetName()
|
||||
@@ -50,11 +50,11 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
||||
for id := range m {
|
||||
objMap := m[id].Map()
|
||||
for _, backRef := range o.backRefs {
|
||||
for _, path := range backRef.FieldSpecs {
|
||||
if !id.Gvk().IsSelected(&path.Gvk) {
|
||||
for _, fSpec := range backRef.FieldSpecs {
|
||||
if !id.Gvk().IsSelected(&fSpec.Gvk) {
|
||||
continue
|
||||
}
|
||||
err := mutateField(objMap, path.PathSlice(), path.CreateIfNotPresent,
|
||||
err := mutateField(objMap, fSpec.PathSlice(), fSpec.CreateIfNotPresent,
|
||||
o.updateNameReference(backRef.Gvk, m.FilterBy(id)))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -66,7 +66,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
|
||||
}
|
||||
|
||||
func (o *nameReferenceTransformer) updateNameReference(
|
||||
k gvk.Gvk, m resmap.ResMap) func(in interface{}) (interface{}, error) {
|
||||
backRef gvk.Gvk, m resmap.ResMap) func(in interface{}) (interface{}, error) {
|
||||
return func(in interface{}) (interface{}, error) {
|
||||
s, ok := in.(string)
|
||||
if !ok {
|
||||
@@ -74,7 +74,7 @@ func (o *nameReferenceTransformer) updateNameReference(
|
||||
}
|
||||
|
||||
for id, res := range m {
|
||||
if !id.Gvk().IsSelected(&k) {
|
||||
if !id.Gvk().IsSelected(&backRef) {
|
||||
continue
|
||||
}
|
||||
if id.Name() == s {
|
||||
|
||||
@@ -60,8 +60,10 @@ func NewNamePrefixTransformer(np string, pc []config.FieldSpec) (Transformer, er
|
||||
|
||||
// Transform prepends the name prefix.
|
||||
func (o *namePrefixTransformer) Transform(m resmap.ResMap) error {
|
||||
// Fill map "mf" with entries subject to name modification, and
|
||||
// delete these entries from "m", so that for now m retains only
|
||||
// the entries whose names will not be modified.
|
||||
mf := resmap.ResMap{}
|
||||
|
||||
for id := range m {
|
||||
found := false
|
||||
for _, path := range o.fieldSpecsToSkip {
|
||||
|
||||
@@ -22,7 +22,11 @@ import (
|
||||
|
||||
type mutateFunc func(interface{}) (interface{}, error)
|
||||
|
||||
func mutateField(m map[string]interface{}, pathToField []string, createIfNotPresent bool, fns ...mutateFunc) error {
|
||||
func mutateField(
|
||||
m map[string]interface{},
|
||||
pathToField []string,
|
||||
createIfNotPresent bool,
|
||||
fns ...mutateFunc) error {
|
||||
if len(pathToField) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user