From 3093f19b0b1fc72e9d2f108795093701ef7b4d5a Mon Sep 17 00:00:00 2001 From: charles-chenzz Date: Tue, 5 Sep 2023 20:55:55 +0800 Subject: [PATCH] api/internal/builtins: use plugin/builtin to re-generate files to receive changes in interface Generate --- api/internal/builtins/ConfigMapGenerator.go | 7 +++-- .../builtins/HelmChartInflationGenerator.go | 27 ++++++++++--------- api/internal/builtins/IAMPolicyGenerator.go | 9 ++++--- api/internal/builtins/SecretGenerator.go | 7 +++-- .../configmapgenerator/ConfigMapGenerator.go | 2 +- .../HelmChartInflationGenerator.go | 22 +++++++-------- .../iampolicygenerator/IAMPolicyGenerator.go | 4 +-- .../secretgenerator/SecretGenerator.go | 2 +- 8 files changed, 46 insertions(+), 34 deletions(-) diff --git a/api/internal/builtins/ConfigMapGenerator.go b/api/internal/builtins/ConfigMapGenerator.go index dc18bce858..6c5b393432 100644 --- a/api/internal/builtins/ConfigMapGenerator.go +++ b/api/internal/builtins/ConfigMapGenerator.go @@ -1,6 +1,8 @@ // Code generated by pluginator on ConfigMapGenerator; DO NOT EDIT. // pluginator {(devel) unknown } + + package builtins import ( @@ -16,6 +18,7 @@ type ConfigMapGeneratorPlugin struct { types.ConfigMapArgs } + func (p *ConfigMapGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { p.ConfigMapArgs = types.ConfigMapArgs{} err = yaml.Unmarshal(config, p) @@ -29,11 +32,11 @@ func (p *ConfigMapGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte return } -func (p *ConfigMapGeneratorPlugin) Generate() (resmap.ResMap, error) { +func (p *ConfigMapGeneratorPlugin) Generate() (resmap.ResMap, []string, error) { return p.h.ResmapFactory().FromConfigMapArgs( kv.NewLoader(p.h.Loader(), p.h.Validator()), p.ConfigMapArgs) } func NewConfigMapGeneratorPlugin() resmap.GeneratorPlugin { - return &ConfigMapGeneratorPlugin{} + return &ConfigMapGeneratorPlugin{} } diff --git a/api/internal/builtins/HelmChartInflationGenerator.go b/api/internal/builtins/HelmChartInflationGenerator.go index 113f56ea7c..4dc53e53b6 100644 --- a/api/internal/builtins/HelmChartInflationGenerator.go +++ b/api/internal/builtins/HelmChartInflationGenerator.go @@ -1,6 +1,8 @@ // Code generated by pluginator on HelmChartInflationGenerator; DO NOT EDIT. // pluginator {(devel) unknown } + + package builtins import ( @@ -28,6 +30,7 @@ type HelmChartInflationGeneratorPlugin struct { tmpDir string } + const ( valuesMergeOptionMerge = "merge" valuesMergeOptionOverride = "override" @@ -226,18 +229,18 @@ func (p *HelmChartInflationGeneratorPlugin) cleanup() { } // Generate implements generator -func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err error) { +func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, orderKeys []string, err error) { defer p.cleanup() if err = p.checkHelmVersion(); err != nil { - return nil, err + return nil, nil, err } if path, exists := p.chartExistsLocally(); !exists { if p.Repo == "" { - return nil, fmt.Errorf( + return nil, nil, fmt.Errorf( "no repo specified for pull, no chart found at '%s'", path) } if _, err := p.runHelmCommand(p.pullCommand()); err != nil { - return nil, err + return nil,nil, err } } if len(p.ValuesInline) > 0 { @@ -246,34 +249,34 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er p.ValuesFile, err = p.copyValuesFile() } if err != nil { - return nil, err + return nil, nil, err } var stdout []byte stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome())) if err != nil { - return nil, err + return nil, nil, err } rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout) if resMapErr == nil { - return rm, nil + return rm, nil, nil } // try to remove the contents before first "---" because // helm may produce messages to stdout before it r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true} nodes, err := r.Read() if err != nil { - return nil, fmt.Errorf("error reading helm output: %w", err) + return nil, nil, fmt.Errorf("error reading helm output: %w", err) } if len(nodes) != 0 { rm, err = p.h.ResmapFactory().NewResMapFromRNodeSlice(nodes) if err != nil { - return nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err) + return nil, nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err) } - return rm, nil + return rm, nil, nil } - return nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr) + return nil, nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr) } func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string { @@ -325,5 +328,5 @@ func (p *HelmChartInflationGeneratorPlugin) checkHelmVersion() error { } func NewHelmChartInflationGeneratorPlugin() resmap.GeneratorPlugin { - return &HelmChartInflationGeneratorPlugin{} + return &HelmChartInflationGeneratorPlugin{} } diff --git a/api/internal/builtins/IAMPolicyGenerator.go b/api/internal/builtins/IAMPolicyGenerator.go index cfb1fa81b6..b1819bd228 100644 --- a/api/internal/builtins/IAMPolicyGenerator.go +++ b/api/internal/builtins/IAMPolicyGenerator.go @@ -1,6 +1,8 @@ // Code generated by pluginator on IAMPolicyGenerator; DO NOT EDIT. // pluginator {(devel) unknown } + + package builtins import ( @@ -14,20 +16,21 @@ type IAMPolicyGeneratorPlugin struct { types.IAMPolicyGeneratorArgs } + func (p *IAMPolicyGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { p.IAMPolicyGeneratorArgs = types.IAMPolicyGeneratorArgs{} err = yaml.Unmarshal(config, p) return } -func (p *IAMPolicyGeneratorPlugin) Generate() (resmap.ResMap, error) { +func (p *IAMPolicyGeneratorPlugin) Generate() (resmap.ResMap, []string, error) { r := resmap.New() err := r.ApplyFilter(iampolicygenerator.Filter{ IAMPolicyGenerator: p.IAMPolicyGeneratorArgs, }) - return r, err + return r, nil, err } func NewIAMPolicyGeneratorPlugin() resmap.GeneratorPlugin { - return &IAMPolicyGeneratorPlugin{} + return &IAMPolicyGeneratorPlugin{} } diff --git a/api/internal/builtins/SecretGenerator.go b/api/internal/builtins/SecretGenerator.go index 2a4ef1c903..25836b492e 100644 --- a/api/internal/builtins/SecretGenerator.go +++ b/api/internal/builtins/SecretGenerator.go @@ -1,6 +1,8 @@ // Code generated by pluginator on SecretGenerator; DO NOT EDIT. // pluginator {(devel) unknown } + + package builtins import ( @@ -16,6 +18,7 @@ type SecretGeneratorPlugin struct { types.SecretArgs } + func (p *SecretGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { p.SecretArgs = types.SecretArgs{} err = yaml.Unmarshal(config, p) @@ -29,11 +32,11 @@ func (p *SecretGeneratorPlugin) Config(h *resmap.PluginHelpers, config []byte) ( return } -func (p *SecretGeneratorPlugin) Generate() (resmap.ResMap, error) { +func (p *SecretGeneratorPlugin) Generate() (resmap.ResMap, []string, error) { return p.h.ResmapFactory().FromSecretArgs( kv.NewLoader(p.h.Loader(), p.h.Validator()), p.SecretArgs) } func NewSecretGeneratorPlugin() resmap.GeneratorPlugin { - return &SecretGeneratorPlugin{} + return &SecretGeneratorPlugin{} } diff --git a/plugin/builtin/configmapgenerator/ConfigMapGenerator.go b/plugin/builtin/configmapgenerator/ConfigMapGenerator.go index a2f8352012..61ec233c7d 100644 --- a/plugin/builtin/configmapgenerator/ConfigMapGenerator.go +++ b/plugin/builtin/configmapgenerator/ConfigMapGenerator.go @@ -32,7 +32,7 @@ func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { return } -func (p *plugin) Generate() (resmap.ResMap, error) { +func (p *plugin) Generate() (resmap.ResMap, []string, error) { return p.h.ResmapFactory().FromConfigMapArgs( kv.NewLoader(p.h.Loader(), p.h.Validator()), p.ConfigMapArgs) } diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index 959528abe7..3d28b2b3e9 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -232,18 +232,18 @@ func (p *plugin) cleanup() { } // Generate implements generator -func (p *plugin) Generate() (rm resmap.ResMap, err error) { +func (p *plugin) Generate() (rm resmap.ResMap, orderKeys []string, err error) { defer p.cleanup() if err = p.checkHelmVersion(); err != nil { - return nil, err + return nil, nil, err } if path, exists := p.chartExistsLocally(); !exists { if p.Repo == "" { - return nil, fmt.Errorf( + return nil, nil, fmt.Errorf( "no repo specified for pull, no chart found at '%s'", path) } if _, err := p.runHelmCommand(p.pullCommand()); err != nil { - return nil, err + return nil,nil, err } } if len(p.ValuesInline) > 0 { @@ -252,34 +252,34 @@ func (p *plugin) Generate() (rm resmap.ResMap, err error) { p.ValuesFile, err = p.copyValuesFile() } if err != nil { - return nil, err + return nil, nil, err } var stdout []byte stdout, err = p.runHelmCommand(p.AsHelmArgs(p.absChartHome())) if err != nil { - return nil, err + return nil, nil, err } rm, resMapErr := p.h.ResmapFactory().NewResMapFromBytes(stdout) if resMapErr == nil { - return rm, nil + return rm, nil, nil } // try to remove the contents before first "---" because // helm may produce messages to stdout before it r := &kio.ByteReader{Reader: bytes.NewBufferString(string(stdout)), OmitReaderAnnotations: true} nodes, err := r.Read() if err != nil { - return nil, fmt.Errorf("error reading helm output: %w", err) + return nil, nil, fmt.Errorf("error reading helm output: %w", err) } if len(nodes) != 0 { rm, err = p.h.ResmapFactory().NewResMapFromRNodeSlice(nodes) if err != nil { - return nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err) + return nil, nil, fmt.Errorf("could not parse rnode slice into resource map: %w", err) } - return rm, nil + return rm, nil, nil } - return nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr) + return nil, nil, fmt.Errorf("could not parse bytes into resource map: %w", resMapErr) } func (p *plugin) pullCommand() []string { diff --git a/plugin/builtin/iampolicygenerator/IAMPolicyGenerator.go b/plugin/builtin/iampolicygenerator/IAMPolicyGenerator.go index e05ba1f32a..0327628283 100644 --- a/plugin/builtin/iampolicygenerator/IAMPolicyGenerator.go +++ b/plugin/builtin/iampolicygenerator/IAMPolicyGenerator.go @@ -23,10 +23,10 @@ func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { return } -func (p *plugin) Generate() (resmap.ResMap, error) { +func (p *plugin) Generate() (resmap.ResMap, []string, error) { r := resmap.New() err := r.ApplyFilter(iampolicygenerator.Filter{ IAMPolicyGenerator: p.IAMPolicyGeneratorArgs, }) - return r, err + return r, nil, err } diff --git a/plugin/builtin/secretgenerator/SecretGenerator.go b/plugin/builtin/secretgenerator/SecretGenerator.go index 6b31389b32..43ac9b672b 100644 --- a/plugin/builtin/secretgenerator/SecretGenerator.go +++ b/plugin/builtin/secretgenerator/SecretGenerator.go @@ -32,7 +32,7 @@ func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) { return } -func (p *plugin) Generate() (resmap.ResMap, error) { +func (p *plugin) Generate() (resmap.ResMap, []string, error) { return p.h.ResmapFactory().FromSecretArgs( kv.NewLoader(p.h.Loader(), p.h.Validator()), p.SecretArgs) }