Fix pluginator incompatibility with nolint lines

This commit is contained in:
Katrina Verey
2022-11-28 19:11:09 -05:00
parent 832b552076
commit a612cd2b7e
27 changed files with 54 additions and 87 deletions

View File

@@ -19,8 +19,7 @@ import (
"sigs.k8s.io/yaml"
)
// HelmChartInflationGeneratorPlugin is a plugin to generate resources
// from a remote or local helm chart.
// Generate resources from a remote or local helm chart.
type HelmChartInflationGeneratorPlugin struct {
h *resmap.PluginHelpers
types.HelmGlobals
@@ -28,8 +27,6 @@ type HelmChartInflationGeneratorPlugin struct {
tmpDir string
}
var KustomizePlugin HelmChartInflationGeneratorPlugin
const (
valuesMergeOptionMerge = "merge"
valuesMergeOptionOverride = "override"

View File

@@ -72,10 +72,7 @@ func ConvertToBuiltInPlugin() (retErr error) {
if strings.HasPrefix(l, "//go:generate") {
continue
}
if strings.HasPrefix(l, "//noinspection") {
continue
}
if l == "var "+konfig.PluginSymbol+" plugin" {
if strings.HasPrefix(l, "var "+konfig.PluginSymbol+" plugin") {
continue
}
if strings.Contains(l, " Transform(") {
@@ -136,9 +133,12 @@ func newWriter(r string) (*writer, error) {
}
// Assume that this command is running with a $PWD of
// $HOME/kustomize/plugin/builtin/secretGenerator
//
// $HOME/kustomize/plugin/builtin/secretGenerator
//
// (for example). Then we want to write to
// $HOME/kustomize/api/builtins
//
// $HOME/kustomize/api/builtins
func makeOutputFileName(root string) string {
return filepath.Join(
"..", "..", "..", "api/internal", packageForGeneratedCode, root+".go")

View File

@@ -34,8 +34,7 @@ type plugin struct{
FieldSpecs []types.FieldSpec ` + "`json:\"fieldSpecs,omitempty\" yaml:\"fieldSpecs,omitempty\"`" + `
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, config []byte) (err error) {
@@ -171,8 +170,7 @@ type plugin struct {
types.ConfigMapArgs
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.ConfigMapArgs = types.ConfigMapArgs{}

View File

@@ -9,8 +9,7 @@ import (
type plugin struct{}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, _ []byte) (err error) {

View File

@@ -17,8 +17,7 @@ type plugin struct {
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -17,8 +17,7 @@ type plugin struct {
types.ConfigMapArgs
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.ConfigMapArgs = types.ConfigMapArgs{}

View File

@@ -15,8 +15,7 @@ type plugin struct {
hasher ifc.KustHasher
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
h *resmap.PluginHelpers, _ []byte) (err error) {

View File

@@ -23,17 +23,15 @@ import (
"sigs.k8s.io/yaml"
)
// HelmChartInflationGeneratorPlugin is a plugin to generate resources
// from a remote or local helm chart.
type HelmChartInflationGeneratorPlugin struct {
// Generate resources from a remote or local helm chart.
type plugin struct {
h *resmap.PluginHelpers
types.HelmGlobals
types.HelmChart
tmpDir string
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin HelmChartInflationGeneratorPlugin
var KustomizePlugin plugin //nolint:gochecknoglobals
const (
valuesMergeOptionMerge = "merge"
@@ -49,7 +47,7 @@ var legalMergeOptions = []string{
// Config uses the input plugin configurations `config` to setup the generator
// options
func (p *HelmChartInflationGeneratorPlugin) Config(
func (p *plugin) Config(
h *resmap.PluginHelpers, config []byte) (err error) {
if h.GeneralConfig() == nil {
return fmt.Errorf("unable to access general config")
@@ -72,7 +70,7 @@ func (p *HelmChartInflationGeneratorPlugin) Config(
// filesystem since we allow the user to use previously
// downloaded charts. This is safe since this plugin is
// owned by kustomize.
func (p *HelmChartInflationGeneratorPlugin) establishTmpDir() (err error) {
func (p *plugin) establishTmpDir() (err error) {
if p.tmpDir != "" {
// already done.
return nil
@@ -81,7 +79,7 @@ func (p *HelmChartInflationGeneratorPlugin) establishTmpDir() (err error) {
return err
}
func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) {
func (p *plugin) validateArgs() (err error) {
if p.Name == "" {
return fmt.Errorf("chart name cannot be empty")
}
@@ -116,7 +114,7 @@ func (p *HelmChartInflationGeneratorPlugin) validateArgs() (err error) {
return nil
}
func (p *HelmChartInflationGeneratorPlugin) errIfIllegalValuesMerge() error {
func (p *plugin) errIfIllegalValuesMerge() error {
if p.ValuesMerge == "" {
// Use the default.
p.ValuesMerge = valuesMergeOptionOverride
@@ -130,14 +128,14 @@ func (p *HelmChartInflationGeneratorPlugin) errIfIllegalValuesMerge() error {
return fmt.Errorf("valuesMerge must be one of %v", legalMergeOptions)
}
func (p *HelmChartInflationGeneratorPlugin) absChartHome() string {
func (p *plugin) absChartHome() string {
if filepath.IsAbs(p.ChartHome) {
return p.ChartHome
}
return filepath.Join(p.h.Loader().Root(), p.ChartHome)
}
func (p *HelmChartInflationGeneratorPlugin) runHelmCommand(
func (p *plugin) runHelmCommand(
args []string) ([]byte, error) {
stdout := new(bytes.Buffer)
stderr := new(bytes.Buffer)
@@ -163,7 +161,7 @@ func (p *HelmChartInflationGeneratorPlugin) runHelmCommand(
}
// createNewMergedValuesFile replaces/merges original values file with ValuesInline.
func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFile() (
func (p *plugin) createNewMergedValuesFile() (
path string, err error) {
if p.ValuesMerge == valuesMergeOptionMerge ||
p.ValuesMerge == valuesMergeOptionOverride {
@@ -179,7 +177,7 @@ func (p *HelmChartInflationGeneratorPlugin) createNewMergedValuesFile() (
return p.writeValuesBytes(b)
}
func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline() error {
func (p *plugin) replaceValuesInline() error {
pValues, err := p.h.Loader().Load(p.ValuesFile)
if err != nil {
return err
@@ -200,7 +198,7 @@ func (p *HelmChartInflationGeneratorPlugin) replaceValuesInline() error {
}
// copyValuesFile to avoid branching. TODO: get rid of this.
func (p *HelmChartInflationGeneratorPlugin) copyValuesFile() (string, error) {
func (p *plugin) copyValuesFile() (string, error) {
b, err := p.h.Loader().Load(p.ValuesFile)
if err != nil {
return "", err
@@ -209,7 +207,7 @@ func (p *HelmChartInflationGeneratorPlugin) copyValuesFile() (string, error) {
}
// Write a absolute path file in the tmp file system.
func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes(
func (p *plugin) writeValuesBytes(
b []byte) (string, error) {
if err := p.establishTmpDir(); err != nil {
return "", fmt.Errorf("cannot create tmp dir to write helm values")
@@ -218,14 +216,14 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes(
return path, errors.Wrap(os.WriteFile(path, b, 0644), "failed to write values file")
}
func (p *HelmChartInflationGeneratorPlugin) cleanup() {
func (p *plugin) cleanup() {
if p.tmpDir != "" {
os.RemoveAll(p.tmpDir)
}
}
// Generate implements generator
func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err error) {
func (p *plugin) Generate() (rm resmap.ResMap, err error) {
defer p.cleanup()
if err = p.checkHelmVersion(); err != nil {
return nil, err
@@ -266,7 +264,7 @@ func (p *HelmChartInflationGeneratorPlugin) Generate() (rm resmap.ResMap, err er
return nil, err
}
func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
func (p *plugin) templateCommand() []string {
args := []string{"template"}
if p.ReleaseName != "" {
args = append(args, p.ReleaseName)
@@ -293,7 +291,7 @@ func (p *HelmChartInflationGeneratorPlugin) templateCommand() []string {
return args
}
func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
func (p *plugin) pullCommand() []string {
args := []string{
"pull",
"--untar",
@@ -308,7 +306,7 @@ func (p *HelmChartInflationGeneratorPlugin) pullCommand() []string {
// chartExistsLocally will return true if the chart does exist in
// local chart home.
func (p *HelmChartInflationGeneratorPlugin) chartExistsLocally() (string, bool) {
func (p *plugin) chartExistsLocally() (string, bool) {
path := filepath.Join(p.absChartHome(), p.Name)
s, err := os.Stat(path)
if err != nil {
@@ -318,7 +316,7 @@ func (p *HelmChartInflationGeneratorPlugin) chartExistsLocally() (string, bool)
}
// checkHelmVersion will return an error if the helm version is not V3
func (p *HelmChartInflationGeneratorPlugin) checkHelmVersion() error {
func (p *plugin) checkHelmVersion() error {
stdout, err := p.runHelmCommand([]string{"version", "-c", "--short"})
if err != nil {
return err

View File

@@ -15,8 +15,7 @@ type plugin struct {
types.IAMPolicyGeneratorArgs
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.IAMPolicyGeneratorArgs = types.IAMPolicyGeneratorArgs{}

View File

@@ -18,8 +18,7 @@ type plugin struct {
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -17,8 +17,7 @@ type plugin struct {
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -19,8 +19,7 @@ import (
// (like ValidatingWebhookConfiguration) last.
type plugin struct{}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
// Nothing needed for configuration.
func (p *plugin) Config(

View File

@@ -22,8 +22,7 @@ type plugin struct {
SetRoleBindingSubjects namespace.RoleBindingSubjectMode `json:"setRoleBindingSubjects" yaml:"setRoleBindingSubjects"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -25,8 +25,7 @@ type plugin struct {
JsonOp string `json:"jsonOp,omitempty" yaml:"jsonOp,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -19,8 +19,7 @@ type plugin struct {
Patches string `json:"patches,omitempty" yaml:"patches,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -26,8 +26,7 @@ type plugin struct {
Options map[string]bool `json:"options,omitempty" yaml:"options,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
h *resmap.PluginHelpers, c []byte) error {

View File

@@ -20,8 +20,7 @@ type plugin struct {
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
// TODO: Make this gvk skip list part of the config.
var prefixFieldSpecsToSkip = types.FsSlice{

View File

@@ -20,8 +20,7 @@ type plugin struct {
Replacements []types.Replacement `json:"omitempty" yaml:"omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
h *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -21,8 +21,7 @@ type plugin struct {
FieldSpecs []types.FieldSpec `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(
_ *resmap.PluginHelpers, c []byte) (err error) {

View File

@@ -17,8 +17,7 @@ type plugin struct {
types.SecretArgs
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.SecretArgs = types.SecretArgs{}

View File

@@ -20,8 +20,7 @@ type plugin struct {
FieldSpecs types.FsSlice `json:"fieldSpecs,omitempty" yaml:"fieldSpecs,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
// TODO: Make this gvk skip list part of the config.
var suffixFieldSpecsToSkip = types.FsSlice{

View File

@@ -49,8 +49,7 @@ type Target struct {
FilePathPosition int `json:"filePathPosition,omitempty" yaml:"filePathPosition,omitempty"`
}
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(h *resmap.PluginHelpers, c []byte) error {
err := yaml.Unmarshal(c, p)

View File

@@ -22,9 +22,7 @@ type plugin struct {
Count int `json:"count,omitempty" yaml:"count,omitempty"`
}
//nolint: golint
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) Config(_ *resmap.PluginHelpers, c []byte) error {
return yaml.Unmarshal(c, p)

View File

@@ -21,9 +21,7 @@ type plugin struct {
t resmap.Transformer
}
//nolint: golint
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) makePrefixPluginConfig() ([]byte, error) {
var s struct {
@@ -55,7 +53,9 @@ func (p *plugin) Config(h *resmap.PluginHelpers, _ []byte) error {
}
// Returns a constant, rather than
// time.Now().Format("2006-01-02")
//
// time.Now().Format("2006-01-02")
//
// to make tests happy.
// This is just an example.
func getDate() string {

View File

@@ -19,9 +19,7 @@ type plugin struct {
Keys []string `json:"keys,omitempty" yaml:"keys,omitempty"`
}
//nolint: golint
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
var database = map[string]string{
"TREE": "oak",

View File

@@ -19,9 +19,7 @@ type plugin struct {
Port string `json:"port,omitempty" yaml:"port,omitempty"`
}
//nolint: golint
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
const tmpl = `
apiVersion: v1

View File

@@ -22,9 +22,7 @@ type plugin struct {
t resmap.Transformer
}
//nolint: golint
//noinspection GoUnusedGlobalVariable
var KustomizePlugin plugin
var KustomizePlugin plugin //nolint:gochecknoglobals
func (p *plugin) makePrefixPluginConfig(n string) ([]byte, error) {
var s struct {