Skip to content

Commit

Permalink
chore(deps): update go, golangci, gorelease
Browse files Browse the repository at this point in the history
Address the warnings raised by latest version of golangci

Signed-off-by: Flavio Castelli <[email protected]>
  • Loading branch information
flavio committed May 21, 2024
1 parent bccfe8a commit 3d9d687
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
- run: go test ./...

golangci:
Expand All @@ -34,8 +34,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.55.2
version: v1.58.2
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x
- uses: sigstore/cosign-installer@v3
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5.0.0
uses: goreleaser/goreleaser-action@v5.1.0
with:
distribution: goreleaser
version: latest
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GO_VERSION_MAJ := $(shell echo $(GO_VERSION) | cut -f1 -d'.')
GO_VERSION_MIN := $(shell echo $(GO_VERSION) | cut -f2 -d'.')

# golangci linter
GOLANGCI_LINT_VER := v1.55.2
GOLANGCI_LINT_VER := v1.58.2
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(BINPATH)/$(GOLANGCI_LINT_BIN)

Expand Down
2 changes: 1 addition & 1 deletion cmd/kuberlr/bins.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewBinsCmd() *cobra.Command {
return &cobra.Command{
Use: "bins",
Short: "Print information about the kubectl binaries found",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
kubectlFinder := finder.NewKubectlFinder("", "")
systemBins, err := kubectlFinder.SystemKubectlBinaries()

Expand Down
2 changes: 1 addition & 1 deletion cmd/kuberlr/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewGetCmd() *cobra.Command {
Versions can be specified with, or without the 'v' prefix:
$ kuberlr get v1.19.1`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(_ *cobra.Command, args []string) error {
version, err := semver.ParseTolerant(args[0])
if err != nil {
return fmt.Errorf("invalid version: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/kuberlr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewKubectlWrapperCmd() *cobra.Command {
Use: "kubectl",
Short: "Wrap and exec a suitable version kubectl command",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
kubectlWrapperMode(args)
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/kuberlr/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func NewVersionCmd() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Print version information",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
//nolint: forbidigo
fmt.Printf("%s\n", kuberlr.CurrentVersion().String())
},
Expand Down
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"github.com/flavio/kuberlr/internal/common"
)

const DefaultTimeout = 5

// Cfg is used to retrieve the configuration of kuberlr
type Cfg struct {
Paths []string
Expand All @@ -29,7 +31,7 @@ func (c *Cfg) Load() (*viper.Viper, error) {
v := viper.New()
v.SetDefault("AllowDownload", true)
v.SetDefault("SystemPath", common.SystemPath)
v.SetDefault("Timeout", 5)
v.SetDefault("Timeout", DefaultTimeout)
v.SetDefault("KubeMirrorUrl", "https://dl.k8s.io")

v.SetConfigType("toml")
Expand Down
7 changes: 4 additions & 3 deletions internal/downloader/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (d *Downloder) UpstreamStableVersion() (semver.Version, error) {
if err != nil {
return semver.Version{}, err
}
url, err := url.Parse(fmt.Sprintf("%s/release/stable.txt", baseURL))
url, err := url.Parse(baseURL + "/release/stable.txt")
if err != nil {
return semver.Version{}, err
}
Expand Down Expand Up @@ -101,6 +101,7 @@ func (d *Downloder) GetKubectlBinary(version semver.Version, destination string)
}
}

//nolint: mnd
err = d.download(fmt.Sprintf("kubectl%s%s", version, osexec.Ext), downloadURL, hashing, destination, 0755)
if err == nil {
return nil
Expand Down Expand Up @@ -188,8 +189,8 @@ func (d *Downloder) download(desc string, urlToGet string, hashing *Hashing, des
progressbar.OptionSetDescription(desc),
progressbar.OptionSetWriter(os.Stderr),
progressbar.OptionShowBytes(true),
progressbar.OptionSetWidth(40),
progressbar.OptionThrottle(10*time.Millisecond),
progressbar.OptionSetWidth(40), //nolint: mnd
progressbar.OptionThrottle(10*time.Millisecond), //nolint: mnd
progressbar.OptionShowCount(),
progressbar.OptionOnCompletion(func() {
fmt.Fprintln(os.Stderr, " done.")
Expand Down
1 change: 1 addition & 0 deletions internal/finder/kubectl_finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func lowerBoundVersion(v semver.Version) semver.Version {
}

func upperBoundVersion(v semver.Version) semver.Version {
//nolint: mnd
return semver.Version{
Major: v.Major,
Minor: v.Minor + 2,
Expand Down
2 changes: 1 addition & 1 deletion internal/finder/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func createFakeKubectlBinaries(bins KubectlBinaries) error {
_, err := os.Stat(dir)
if err != nil {
if os.IsNotExist(err) {
err = os.MkdirAll(dir, 0755)
err = os.MkdirAll(dir, 0755) //nolint: mnd
if err != nil {
return err
}
Expand Down
12 changes: 9 additions & 3 deletions internal/finder/versioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func NewVersioner(f iFinder) *Versioner {
}
}

const (
_ = iota
VerbosityOne
VerbosityTwo
)

// KubectlVersionToUse returns the kubectl version to be used to interact with
// the remote server. The method takes into account different failure scenarios
// and acts accordingly.
Expand All @@ -56,15 +62,15 @@ func (v *Versioner) KubectlVersionToUse(timeout int64) (semver.Version, error) {
if isUnreachable(err) {
// the remote server is unreachable, let's get
// the latest version of kubectl that is available on the system
klog.V(2).Info("Remote kubernetes server unreachable")
klog.V(VerbosityTwo).Info("Remote kubernetes server unreachable")
} else {
klog.V(1).Info(err)
klog.V(VerbosityOne).Info(err)
}
kubectl, internalErr := v.kFinder.MostRecentKubectlAvailable()
if internalErr == nil {
return kubectl.Version, nil
} else if common.IsNoVersionFound(internalErr) {
klog.V(2).Info("No local kubectl binary found, fetching latest stable release version")
klog.V(VerbosityTwo).Info("No local kubectl binary found, fetching latest stable release version")
return v.downloader.UpstreamStableVersion()
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/finder/versioner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func TestEnsureCompatibleKubectlAvailableLocalBinaryFound(t *testing.T) {
expectedPath := "/tmp/kubectl-1.9.0"

finderMock := mockFinder{}
finderMock.findCompatibleKubectl = func(v semver.Version) (KubectlBinary, error) {
finderMock.findCompatibleKubectl = func(_ semver.Version) (KubectlBinary, error) {
return KubectlBinary{
Version: expectedVersion,
Path: expectedPath,
Expand All @@ -106,7 +106,7 @@ func TestEnsureCompatibleKubectlAvailableLocalBinaryFound(t *testing.T) {
// keep
func TestEnsureCompatibleKubectlAvailableLocalBinaryNotFound(t *testing.T) {
finderMock := mockFinder{}
finderMock.findCompatibleKubectl = func(v semver.Version) (KubectlBinary, error) {
finderMock.findCompatibleKubectl = func(_ semver.Version) (KubectlBinary, error) {
return KubectlBinary{}, &common.NoVersionFoundError{}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ func TestKubectlVersionToUseTimeoutAndNoKubectlAvailable(t *testing.T) {
// keep
func genericTestKubectlVersionToUseTimeout(localBins, systemBins KubectlBinaries, expected KubectlBinary, downloader *mockDownloader) error {
apiMock := mockAPIServer{}
apiMock.version = func(timeout int64) (semver.Version, error) {
apiMock.version = func(_ int64) (semver.Version, error) {
return semver.Version{}, &mockTimeoutError{}
}

Expand Down

0 comments on commit 3d9d687

Please sign in to comment.