Ease doing custom configuration of builtin plugins.

This commit is contained in:
jregan
2019-09-11 20:17:33 -07:00
committed by Jeffrey Regan
parent 7e71009283
commit 2050afdeb4
33 changed files with 596 additions and 432 deletions

View File

@@ -15,11 +15,6 @@ type AnnotationsTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewAnnotationsTransformerPlugin() *AnnotationsTransformerPlugin {
return &AnnotationsTransformerPlugin{}
}
func (p *AnnotationsTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.Annotations = nil
@@ -37,3 +32,7 @@ func (p *AnnotationsTransformerPlugin) Transform(m resmap.ResMap) error {
}
return t.Transform(m)
}
func NewAnnotationsTransformerPlugin() resmap.TransformerPlugin {
return &AnnotationsTransformerPlugin{}
}

View File

@@ -16,11 +16,6 @@ type ConfigMapGeneratorPlugin struct {
types.ConfigMapArgs
}
//noinspection GoUnusedGlobalVariable
func NewConfigMapGeneratorPlugin() *ConfigMapGeneratorPlugin {
return &ConfigMapGeneratorPlugin{}
}
func (p *ConfigMapGeneratorPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) {
p.GeneratorOptions = types.GeneratorOptions{}
@@ -40,3 +35,7 @@ func (p *ConfigMapGeneratorPlugin) Config(
func (p *ConfigMapGeneratorPlugin) Generate() (resmap.ResMap, error) {
return p.rf.FromConfigMapArgs(p.ldr, &p.GeneratorOptions, p.ConfigMapArgs)
}
func NewConfigMapGeneratorPlugin() resmap.GeneratorPlugin {
return &ConfigMapGeneratorPlugin{}
}

View File

@@ -12,11 +12,6 @@ type HashTransformerPlugin struct {
hasher ifc.KunstructuredHasher
}
//noinspection GoUnusedGlobalVariable
func NewHashTransformerPlugin() *HashTransformerPlugin {
return &HashTransformerPlugin{}
}
func (p *HashTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) {
p.hasher = rf.RF().Hasher()
@@ -36,3 +31,7 @@ func (p *HashTransformerPlugin) Transform(m resmap.ResMap) error {
}
return nil
}
func NewHashTransformerPlugin() resmap.TransformerPlugin {
return &HashTransformerPlugin{}
}

View File

@@ -21,11 +21,6 @@ type ImageTagTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewImageTagTransformerPlugin() *ImageTagTransformerPlugin {
return &ImageTagTransformerPlugin{}
}
func (p *ImageTagTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ImageTag = image.Image{}
@@ -183,3 +178,7 @@ func split(imageName string) (name string, tag string) {
tag = imageName[i:]
return
}
func NewImageTagTransformerPlugin() resmap.TransformerPlugin {
return &ImageTagTransformerPlugin{}
}

View File

@@ -22,11 +22,6 @@ type InventoryTransformerPlugin struct {
Policy string `json:"policy,omitempty" yaml:"policy,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewInventoryTransformerPlugin() *InventoryTransformerPlugin {
return &InventoryTransformerPlugin{}
}
func (p *InventoryTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ldr = ldr
@@ -127,3 +122,7 @@ func computeRefs(
}
return
}
func NewInventoryTransformerPlugin() resmap.TransformerPlugin {
return &InventoryTransformerPlugin{}
}

View File

@@ -15,11 +15,6 @@ type LabelTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewLabelTransformerPlugin() *LabelTransformerPlugin {
return &LabelTransformerPlugin{}
}
func (p *LabelTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.Labels = nil
@@ -37,3 +32,7 @@ func (p *LabelTransformerPlugin) Transform(m resmap.ResMap) error {
}
return t.Transform(m)
}
func NewLabelTransformerPlugin() resmap.TransformerPlugin {
return &LabelTransformerPlugin{}
}

View File

@@ -16,11 +16,6 @@ import (
// (like ValidatingWebhookConfiguration) last.
type LegacyOrderTransformerPlugin struct{}
//noinspection GoUnusedGlobalVariable
func NewLegacyOrderTransformerPlugin() *LegacyOrderTransformerPlugin {
return &LegacyOrderTransformerPlugin{}
}
// Nothing needed for configuration.
func (p *LegacyOrderTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
@@ -43,3 +38,7 @@ func (p *LegacyOrderTransformerPlugin) Transform(m resmap.ResMap) (err error) {
}
return nil
}
func NewLegacyOrderTransformerPlugin() resmap.TransformerPlugin {
return &LegacyOrderTransformerPlugin{}
}

View File

@@ -20,11 +20,6 @@ type NamespaceTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewNamespaceTransformerPlugin() *NamespaceTransformerPlugin {
return &NamespaceTransformerPlugin{}
}
func (p *NamespaceTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.Namespace = ""
@@ -129,3 +124,7 @@ func (o *NamespaceTransformerPlugin) changeNamespace(
}
}
}
func NewNamespaceTransformerPlugin() resmap.TransformerPlugin {
return &NamespaceTransformerPlugin{}
}

View File

@@ -21,11 +21,6 @@ type PatchJson6902TransformerPlugin struct {
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewPatchJson6902TransformerPlugin() *PatchJson6902TransformerPlugin {
return &PatchJson6902TransformerPlugin{}
}
func (p *PatchJson6902TransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ldr = ldr
@@ -97,3 +92,7 @@ func (p *PatchJson6902TransformerPlugin) Transform(m resmap.ResMap) error {
}
return obj.UnmarshalJSON(modifiedObj)
}
func NewPatchJson6902TransformerPlugin() resmap.TransformerPlugin {
return &PatchJson6902TransformerPlugin{}
}

View File

@@ -18,11 +18,6 @@ type PatchStrategicMergeTransformerPlugin struct {
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewPatchStrategicMergeTransformerPlugin() *PatchStrategicMergeTransformerPlugin {
return &PatchStrategicMergeTransformerPlugin{}
}
func (p *PatchStrategicMergeTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ldr = ldr
@@ -88,3 +83,7 @@ func (p *PatchStrategicMergeTransformerPlugin) Transform(m resmap.ResMap) error
}
return nil
}
func NewPatchStrategicMergeTransformerPlugin() resmap.TransformerPlugin {
return &PatchStrategicMergeTransformerPlugin{}
}

View File

@@ -22,11 +22,6 @@ type PatchTransformerPlugin struct {
Target *types.Selector `json:"target,omitempty", yaml:"target,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewPatchTransformerPlugin() *PatchTransformerPlugin {
return &PatchTransformerPlugin{}
}
func (p *PatchTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
p.ldr = ldr
@@ -146,3 +141,7 @@ func jsonPatchFromBytes(
}
return jsonpatch.DecodePatch([]byte(ops))
}
func NewPatchTransformerPlugin() resmap.TransformerPlugin {
return &PatchTransformerPlugin{}
}

View File

@@ -21,11 +21,6 @@ type PrefixSuffixTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewPrefixSuffixTransformerPlugin() *PrefixSuffixTransformerPlugin {
return &PrefixSuffixTransformerPlugin{}
}
// Not placed in a file yet due to lack of demand.
var prefixSuffixFieldSpecsToSkip = []config.FieldSpec{
{
@@ -118,3 +113,7 @@ func (p *PrefixSuffixTransformerPlugin) addPrefixSuffix(
}
return fmt.Sprintf("%s%s%s", p.Prefix, s, p.Suffix), nil
}
func NewPrefixSuffixTransformerPlugin() resmap.TransformerPlugin {
return &PrefixSuffixTransformerPlugin{}
}

View File

@@ -20,11 +20,6 @@ type ReplicaCountTransformerPlugin struct {
FieldSpecs []config.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
func NewReplicaCountTransformerPlugin() *ReplicaCountTransformerPlugin {
return &ReplicaCountTransformerPlugin{}
}
func (p *ReplicaCountTransformerPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, c []byte) (err error) {
@@ -88,3 +83,7 @@ func (p *ReplicaCountTransformerPlugin) addReplicas(in interface{}) (interface{}
}
return p.Replica.Count, nil
}
func NewReplicaCountTransformerPlugin() resmap.TransformerPlugin {
return &ReplicaCountTransformerPlugin{}
}

View File

@@ -16,11 +16,6 @@ type SecretGeneratorPlugin struct {
types.SecretArgs
}
//noinspection GoUnusedGlobalVariable
func NewSecretGeneratorPlugin() *SecretGeneratorPlugin {
return &SecretGeneratorPlugin{}
}
func (p *SecretGeneratorPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) {
p.GeneratorOptions = types.GeneratorOptions{}
@@ -40,3 +35,7 @@ func (p *SecretGeneratorPlugin) Config(
func (p *SecretGeneratorPlugin) Generate() (resmap.ResMap, error) {
return p.rf.FromSecretArgs(p.ldr, &p.GeneratorOptions, p.SecretArgs)
}
func NewSecretGeneratorPlugin() resmap.GeneratorPlugin {
return &SecretGeneratorPlugin{}
}

View File

@@ -7,7 +7,6 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/plugin/builtin"
"sigs.k8s.io/yaml"
@@ -16,7 +15,7 @@ import (
// Add a date prefix to the name.
// A plugin that adapts another plugin.
type plugin struct {
t transformers.Transformer
t resmap.Transformer
}
//nolint: golint

View File

@@ -7,7 +7,6 @@ import (
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/v3/pkg/ifc"
"sigs.k8s.io/kustomize/v3/pkg/resmap"
"sigs.k8s.io/kustomize/v3/pkg/transformers"
"sigs.k8s.io/kustomize/v3/pkg/transformers/config"
"sigs.k8s.io/kustomize/v3/pkg/types"
"sigs.k8s.io/kustomize/v3/plugin/builtin"
@@ -18,7 +17,7 @@ import (
// A plugin that adapts another plugin.
type plugin struct {
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
t transformers.Transformer
t resmap.Transformer
}
//nolint: golint