Skip to content

Commit

Permalink
Fix other linters on modified lines
Browse files Browse the repository at this point in the history
  • Loading branch information
KnVerey committed Aug 10, 2022
1 parent f6b7207 commit ee67024
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Expand Up @@ -102,6 +102,9 @@ linters-settings:
arguments:
- [ "ID", "API", "JSON" ] # AllowList
- [ ] # DenyList
gomnd:
ignored-functions:
- os.WriteFile
gomoddirectives:
replace-local: true
gosec:
Expand Down
2 changes: 1 addition & 1 deletion api/internal/builtins/HelmChartInflationGenerator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion cmd/config/internal/commands/cmdinit.go
Expand Up @@ -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)
}
5 changes: 4 additions & 1 deletion kyaml/filesys/fsondisk.go
Expand Up @@ -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) {
content, err := os.ReadFile(name)
return content, errors.Wrap(err)
}

// WriteFile delegates to os.WriteFile with read/write permissions.
func (fsOnDisk) WriteFile(name string, c []byte) error {
Expand Down
3 changes: 2 additions & 1 deletion kyaml/fn/framework/parser/parser.go
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions kyaml/setters2/add_test.go
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion kyaml/setters2/delete_test.go
Expand Up @@ -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()
}
Expand Down
4 changes: 2 additions & 2 deletions kyaml/setters2/settersutil/deletecreator_test.go
Expand Up @@ -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()
}
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion kyaml/yaml/rnode.go
Expand Up @@ -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.
Expand Down
Expand Up @@ -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() {
Expand Down

0 comments on commit ee67024

Please sign in to comment.