diff --git a/api/internal/plugins/execplugin/execplugin.go b/api/internal/plugins/execplugin/execplugin.go index a7df41981..d780121e6 100644 --- a/api/internal/plugins/execplugin/execplugin.go +++ b/api/internal/plugins/execplugin/execplugin.go @@ -140,11 +140,6 @@ func (p *ExecPlugin) Transform(rm resmap.ResMap) error { return p.updateResMapValues(output, rm) } -func (p *ExecPlugin) Validate(rm resmap.ResMap) error { - // Validate works exactly same with Transformer - return p.Transform(rm) -} - // invokePlugin writes plugin config to a temp file, then // passes the full temp file path as the first arg to a process // running the plugin binary. Process output is returned. diff --git a/api/internal/plugins/loader/loader.go b/api/internal/plugins/loader/loader.go index 1d1fe8e80..09dc3a167 100644 --- a/api/internal/plugins/loader/loader.go +++ b/api/internal/plugins/loader/loader.go @@ -87,32 +87,6 @@ func (l *Loader) LoadTransformer( return t, nil } -func (l *Loader) LoadValidators( - ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap) ([]resmap.Validator, error) { - var result []resmap.Validator - for _, res := range rm.Resources() { - t, err := l.LoadValidator(ldr, v, res) - if err != nil { - return nil, err - } - result = append(result, t) - } - return result, nil -} - -func (l *Loader) LoadValidator( - ldr ifc.Loader, v ifc.Validator, res *resource.Resource) (resmap.Validator, error) { - c, err := l.loadAndConfigurePlugin(ldr, v, res) - if err != nil { - return nil, err - } - t, ok := c.(resmap.Validator) - if !ok { - return nil, fmt.Errorf("plugin %s not a validator", res.OrgId()) - } - return t, nil -} - func relativePluginPath(id resid.ResId) string { return filepath.Join( id.Group, diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index 9337e5057..275ebc990 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -264,7 +264,7 @@ func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error { return err } r = append(r, lts...) - lts, err = kt.configureExternalTransformers() + lts, err = kt.configureExternalTransformers(kt.kustomization.Transformers) if err != nil { return err } @@ -273,9 +273,10 @@ func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error { return ra.Transform(t) } -func (kt *KustTarget) configureExternalTransformers() ([]resmap.Transformer, error) { +func (kt *KustTarget) configureExternalTransformers(transformers []string) ([]resmap.Transformer, error) { ra := accumulator.MakeEmptyAccumulator() - ra, err := kt.accumulateResources(ra, kt.kustomization.Transformers) + ra, err := kt.accumulateResources(ra, transformers) + if err != nil { return nil, err } @@ -283,14 +284,14 @@ func (kt *KustTarget) configureExternalTransformers() ([]resmap.Transformer, err } func (kt *KustTarget) runValidators(ra *accumulator.ResAccumulator) error { - validators, err := kt.configureExternalValidators() + validators, err := kt.configureExternalTransformers(kt.kustomization.Validators) if err != nil { return err } for _, v := range validators { // Validators shouldn't modify the resource map orignal := ra.ResMap().DeepCopy() - err = v.Validate(ra.ResMap()) + err = v.Transform(ra.ResMap()) if err != nil { return err } @@ -304,15 +305,14 @@ func (kt *KustTarget) runValidators(ra *accumulator.ResAccumulator) error { } func (kt *KustTarget) removeValidatedByLabel(rm resmap.ResMap) { - var validatedByLabelName string = "validated-by" resources := rm.Resources() for _, r := range resources { labels := r.GetLabels() - if _, found := labels[validatedByLabelName]; !found { + if _, found := labels[konfig.ValidatedByLabelKey]; !found { continue } - delete(labels, validatedByLabelName) + delete(labels, konfig.ValidatedByLabelKey) if len(labels) == 0 { r.SetLabels(nil) } else { @@ -321,15 +321,6 @@ func (kt *KustTarget) removeValidatedByLabel(rm resmap.ResMap) { } } -func (kt *KustTarget) configureExternalValidators() ([]resmap.Validator, error) { - ra := accumulator.MakeEmptyAccumulator() - ra, err := kt.accumulateResources(ra, kt.kustomization.Validators) - if err != nil { - return nil, err - } - return kt.pLdr.LoadValidators(kt.ldr, kt.validator, ra.ResMap()) -} - // accumulateResources fills the given resourceAccumulator // with resources read from the given list of paths. func (kt *KustTarget) accumulateResources( diff --git a/api/konfig/general.go b/api/konfig/general.go index 80a7d9be1..de0292415 100644 --- a/api/konfig/general.go +++ b/api/konfig/general.go @@ -36,4 +36,7 @@ const ( // An environment variable to turn on/off adding the ManagedByLabelKey EnableManagedbyLabelEnv = "KUSTOMIZE_ENABLE_MANAGEDBY_LABEL" + + // Label key that indicates the resources are validated by a validator + ValidatedByLabelKey = "validated-by" ) diff --git a/api/resmap/resmap.go b/api/resmap/resmap.go index db971b462..91e87df66 100644 --- a/api/resmap/resmap.go +++ b/api/resmap/resmap.go @@ -30,12 +30,6 @@ type Generator interface { Generate() (ResMap, error) } -// A Validator checkes the ResMap and return an error -// if it's not valid. -type Validator interface { - Validate(m ResMap) error -} - // Something that's configurable accepts an // instance of PluginHelpers and a raw config // object (YAML in []byte form). @@ -79,11 +73,6 @@ type TransformerPlugin interface { Configurable } -type ValidatorPlugin interface { - Validator - Configurable -} - // ResMap is an interface describing operations on the // core kustomize data structure, a list of Resources. // diff --git a/examples/multibases/validatorPlugin.md b/examples/validatorPlugin.md similarity index 100% rename from examples/multibases/validatorPlugin.md rename to examples/validatorPlugin.md