Skip to content

Commit

Permalink
Merge pull request #211 from vmware-tanzu/fix-warning-linter
Browse files Browse the repository at this point in the history
chore: fix also the linter warnings
  • Loading branch information
tompizmor committed Nov 6, 2023
2 parents d4a3822 + 9ef8bfe commit c5efdb6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion cmd/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"

"github.com/spf13/cobra"

"github.com/vmware-tanzu/asset-relocation-tool-for-kubernetes/pkg/mover"
)

Expand Down Expand Up @@ -50,7 +51,7 @@ func init() {
rootCmd.AddCommand(chartCmd)
}

func validateChartArgs(cmd *cobra.Command, args []string) error {
func validateChartArgs(_ *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("requires a chart argument")
} else if len(args) > 1 {
Expand Down
10 changes: 5 additions & 5 deletions pkg/mover/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ func (l defaultLogger) Println(i ...interface{}) {

type noLogger struct{}

func (nl noLogger) Printf(format string, i ...interface{}) {}
func (nl noLogger) Printf(_ string, _ ...interface{}) {}

func (nl noLogger) Println(i ...interface{}) {}
func (nl noLogger) Println(_ ...interface{}) {}

// DefaultLogger to stdout
var DefaultLogger Logger = defaultLogger{}
Expand Down Expand Up @@ -352,7 +352,7 @@ func (cm *ChartMover) loadImageHints(src *Source) error {

// loadImageHintsFromBundle loads the image hints from the intermediate bundle
func (cm *ChartMover) loadImageHintsFromBundle() error {
rawHints, err := cm.intermediateBundle.loadImageHints(cm.logger)
rawHints, err := cm.intermediateBundle.loadImageHints()
if err != nil {
return err
}
Expand Down Expand Up @@ -716,7 +716,7 @@ func saveChart(chart *chart.Chart, toChartFilename string) error {
// load hints from either a given hints file or a chart-embedded hints file
func loadImageHints(imageHintsFile string, chart *chart.Chart, log Logger) ([]byte, error) {
if imageHintsFile != "" {
rawHints, err := notNilData(loadImageHintsFromFile(imageHintsFile, log))
rawHints, err := notNilData(loadImageHintsFromFile(imageHintsFile))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -744,7 +744,7 @@ func loadImageHintsFromChart(chart *chart.Chart, log Logger) ([]byte, error) {
}

// loadImageHintsFromFile from a file
func loadImageHintsFromFile(hintsFile string, log Logger) ([]byte, error) {
func loadImageHintsFromFile(hintsFile string) ([]byte, error) {
contents, err := notNilData(os.ReadFile(hintsFile))
if err != nil {
return nil, fmt.Errorf("failed to read the image patterns file: %w", err)
Expand Down
5 changes: 3 additions & 2 deletions pkg/mover/intermediate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import (
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/tarball"
"github.com/vmware-tanzu/asset-relocation-tool-for-kubernetes/internal"
"helm.sh/helm/v3/pkg/chart"

"github.com/vmware-tanzu/asset-relocation-tool-for-kubernetes/internal"
)

var (
Expand Down Expand Up @@ -183,7 +184,7 @@ func (ib *intermediateBundle) extractChartTo(dir string) error {
return nil
}

func (ib *intermediateBundle) loadImageHints(log Logger) ([]byte, error) {
func (ib *intermediateBundle) loadImageHints() ([]byte, error) {
r, err := openFromTar(ib.bundlePath, IntermediateBundleHintsFilename)
if err != nil {
return nil, fmt.Errorf("failed to extract %s from bundle at %s: %w",
Expand Down
6 changes: 3 additions & 3 deletions pkg/mover/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ func openFromTar(tarFile, filePath string) (io.ReadCloser, error) {
if err != nil {
return nil, fmt.Errorf("failed to open tar file %s: %w", tarFile, err)
}
close := true
closeTar := true
defer func() {
if close {
if closeTar {
f.Close()
}
}()
Expand All @@ -153,7 +153,7 @@ func openFromTar(tarFile, filePath string) (io.ReadCloser, error) {
currentDir := filepath.Dir(filePath)
return openFromTar(tarFile, path.Join(currentDir, hdr.Linkname))
}
close = false
closeTar = false
return tarredFile{
Reader: tf,
Closer: f,
Expand Down

0 comments on commit c5efdb6

Please sign in to comment.