From 55a37de686ce569b6b3024dffff09601b1a10f2b Mon Sep 17 00:00:00 2001 From: Katrina Verey Date: Wed, 10 Aug 2022 18:50:28 -0400 Subject: [PATCH] Fix other linters on modified lines --- .golangci.yml | 3 +++ api/internal/builtins/HelmChartInflationGenerator.go | 2 +- cmd/config/internal/commands/cmdinit.go | 3 ++- kyaml/filesys/fsondisk.go | 5 ++++- kyaml/fn/framework/parser/parser.go | 3 ++- kyaml/setters2/add_test.go | 4 ++-- kyaml/setters2/delete_test.go | 2 +- kyaml/setters2/settersutil/deletecreator_test.go | 4 ++-- kyaml/yaml/rnode.go | 2 +- .../HelmChartInflationGenerator.go | 2 +- 10 files changed, 19 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4b5fd9b40..4def368bb 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -102,6 +102,9 @@ linters-settings: arguments: - [ "ID", "API", "JSON" ] # AllowList - [ ] # DenyList + gomnd: + ignored-functions: + - os.WriteFile gomoddirectives: replace-local: true gosec: diff --git a/api/internal/builtins/HelmChartInflationGenerator.go b/api/internal/builtins/HelmChartInflationGenerator.go index 69a063ec9..2ce0469f9 100644 --- a/api/internal/builtins/HelmChartInflationGenerator.go +++ b/api/internal/builtins/HelmChartInflationGenerator.go @@ -210,7 +210,7 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes( return "", fmt.Errorf("cannot create tmp dir to write helm values") } path := filepath.Join(p.tmpDir, p.Name+"-kustomize-values.yaml") - return path, os.WriteFile(path, b, 0644) + return path, errors.Wrap(os.WriteFile(path, b, 0644), "failed to write values file") } func (p *HelmChartInflationGeneratorPlugin) cleanup() { diff --git a/cmd/config/internal/commands/cmdinit.go b/cmd/config/internal/commands/cmdinit.go index d8fa771cf..f6e3ad26b 100644 --- a/cmd/config/internal/commands/cmdinit.go +++ b/cmd/config/internal/commands/cmdinit.go @@ -55,8 +55,9 @@ func (r *InitRunner) runE(c *cobra.Command, args []string) error { return errors.Errorf("directory already initialized with a Krmfile") } - return os.WriteFile(filename, []byte(strings.TrimSpace(` + err := os.WriteFile(filename, []byte(strings.TrimSpace(` apiVersion: config.k8s.io/v1alpha1 kind: Krmfile `)), 0600) + return errors.Wrap(err) } diff --git a/kyaml/filesys/fsondisk.go b/kyaml/filesys/fsondisk.go index fa2a781b4..a92833923 100644 --- a/kyaml/filesys/fsondisk.go +++ b/kyaml/filesys/fsondisk.go @@ -125,7 +125,10 @@ func (fsOnDisk) ReadDir(name string) ([]string, error) { } // ReadFile delegates to os.ReadFile. -func (fsOnDisk) ReadFile(name string) ([]byte, error) { return os.ReadFile(name) } +func (fsOnDisk) ReadFile(name string) ([]byte, error) { + //nolint:wrapcheck + return os.ReadFile(name) +} // WriteFile delegates to os.WriteFile with read/write permissions. func (fsOnDisk) WriteFile(name string, c []byte) error { diff --git a/kyaml/fn/framework/parser/parser.go b/kyaml/fn/framework/parser/parser.go index a8168184d..4cdc3ca5e 100644 --- a/kyaml/fn/framework/parser/parser.go +++ b/kyaml/fn/framework/parser/parser.go @@ -100,5 +100,6 @@ func (l parser) readFile(path string) ([]byte, error) { } defer f.Close() - return io.ReadAll(f) + content, err := io.ReadAll(f) + return content, errors.Wrap(err) } diff --git a/kyaml/setters2/add_test.go b/kyaml/setters2/add_test.go index 82b7576cc..18695d675 100644 --- a/kyaml/setters2/add_test.go +++ b/kyaml/setters2/add_test.go @@ -281,7 +281,7 @@ func TestAdd_Filter2(t *testing.T) { path := filepath.Join(os.TempDir(), "resourcefile") // write initial resourcefile to temp path - err := os.WriteFile(path, []byte(resourcefile), 0666) + err := os.WriteFile(path, []byte(resourcefile), 0644) if !assert.NoError(t, err) { t.FailNow() } @@ -342,7 +342,7 @@ func TestAddUpdateSubstitution(t *testing.T) { path := filepath.Join(os.TempDir(), "resourcefile") // write initial resourcefile to temp path - err := os.WriteFile(path, []byte(resourcefile), 0666) + err := os.WriteFile(path, []byte(resourcefile), 0644) if !assert.NoError(t, err) { t.FailNow() } diff --git a/kyaml/setters2/delete_test.go b/kyaml/setters2/delete_test.go index 7a805b806..03850f1aa 100644 --- a/kyaml/setters2/delete_test.go +++ b/kyaml/setters2/delete_test.go @@ -42,7 +42,7 @@ func TestDelete_Filter2(t *testing.T) { path := filepath.Join(os.TempDir(), "resourcefile2") // write initial resourcefile to temp path - err := os.WriteFile(path, []byte(resourcefile2), 0666) + err := os.WriteFile(path, []byte(resourcefile2), 0644) if !assert.NoError(t, err) { t.FailNow() } diff --git a/kyaml/setters2/settersutil/deletecreator_test.go b/kyaml/setters2/settersutil/deletecreator_test.go index 70009e708..f1ebd3250 100644 --- a/kyaml/setters2/settersutil/deletecreator_test.go +++ b/kyaml/setters2/settersutil/deletecreator_test.go @@ -48,7 +48,7 @@ func TestDeleterCreator_Delete(t *testing.T) { } defer os.Remove(openAPI.Name()) // write openapi to temp dir - err = os.WriteFile(openAPI.Name(), []byte(openAPIFile), 0666) + err = os.WriteFile(openAPI.Name(), []byte(openAPIFile), 0644) if !assert.NoError(t, err) { t.FailNow() } @@ -59,7 +59,7 @@ func TestDeleterCreator_Delete(t *testing.T) { t.FailNow() } defer os.Remove(resource.Name()) - err = os.WriteFile(resource.Name(), []byte(resourceFile), 0666) + err = os.WriteFile(resource.Name(), []byte(resourceFile), 0644) if !assert.NoError(t, err) { t.FailNow() } diff --git a/kyaml/yaml/rnode.go b/kyaml/yaml/rnode.go index b7a6cf4b8..01b2ef6da 100644 --- a/kyaml/yaml/rnode.go +++ b/kyaml/yaml/rnode.go @@ -66,7 +66,7 @@ func WriteFile(node *RNode, path string) error { if err != nil { return err } - return os.WriteFile(path, []byte(out), 0600) + return errors.WrapPrefixf(os.WriteFile(path, []byte(out), 0600), "writing RNode to file") } // UpdateFile reads the file at path, applies the filter to it, and write the result back. diff --git a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go index c06b946db..41e6ffac7 100644 --- a/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go +++ b/plugin/builtin/helmchartinflationgenerator/HelmChartInflationGenerator.go @@ -215,7 +215,7 @@ func (p *HelmChartInflationGeneratorPlugin) writeValuesBytes( return "", fmt.Errorf("cannot create tmp dir to write helm values") } path := filepath.Join(p.tmpDir, p.Name+"-kustomize-values.yaml") - return path, os.WriteFile(path, b, 0644) + return path, errors.Wrap(os.WriteFile(path, b, 0644), "failed to write values file") } func (p *HelmChartInflationGeneratorPlugin) cleanup() {