Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go linter rules #18

Merged
merged 4 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: "--verbose --print-issued-lines --print-linter-name --out-${NO_FUTURE}format colored-line-number --timeout 300s --max-issues-per-linter 0 --max-same-issues 0"
args: "--print-issued-lines --print-linter-name --out-${NO_FUTURE}format colored-line-number --timeout 300s --max-issues-per-linter 0 --max-same-issues 0"

- name: Test Go
run: go test ./... --cover
34 changes: 34 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
run:
timeout: 10m

linters:
disable-all: true # Disable defaults, then enable the ones we want
enable:
- unused
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- bodyclose
- stylecheck
- gosec
- goimports
- gci
- revive
- gocritic
- unconvert

linters-settings:
goimports:
local-prefixes: github.com/ArmDeveloperEcosystem
gci:
sections:
- Standard
- Default
- Prefix(github.com/ArmDeveloperEcosystem)
testifylint:
# Enable all checkers (https://github.com/Antonboom/testifylint#checkers).
enable-all: true
1 change: 1 addition & 0 deletions changes/18.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add Go linter rules
50 changes: 24 additions & 26 deletions cmd/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"log"
"sort"

"github.com/spf13/cobra"

"github.com/ArmDeveloperEcosystem/kubearchinspect/internal/images"
"github.com/ArmDeveloperEcosystem/kubearchinspect/internal/k8s"
"github.com/spf13/cobra"
)

const (
Expand All @@ -40,58 +41,55 @@ var imagesCmd = &cobra.Command{
Run: imagesCmdRun,
}

func imagesCmdRun(cmd *cobra.Command, args []string) {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
log.Fatal(err)
}
func imagesCmdRun(_ *cobra.Command, _ []string) {

k8sClient, err := k8s.NewKubernetesClient()
if err != nil {
log.Fatal(err)
}

imageList, err := k8sClient.GetAllImages()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Legend:\n-------\n%s - arm64 supported\n%s - arm64 supported (with update)\n%s - arm64 not supported\n%s - error occurred\n", successIcon, upgradeIcon, failedIcon, errorIcon)
fmt.Print("------------------------------------------------------------------------------------------------\n\n")

fmt.Printf(
"Legend:\n-------\n%s - arm64 supported\n%s - arm64 supported (with update)\n%s - arm64 not supported\n%s - error occurred\n%s",
successIcon,
upgradeIcon,
failedIcon,
errorIcon,
"------------------------------------------------------------------------------------------------\n\n",
)

sort.Strings(imageList)
for _, image := range imageList {
var icon string
supportsArm, err := images.CheckLinuxArm64Support(image)
if err != nil {
if debug {
var (
icon string
supportsArm, err = images.CheckLinuxArm64Support(image)
)

switch {
case err != nil:
if debugEnabled {
fmt.Printf("error: %s\n", err)
}
icon = errorIcon
} else if supportsArm {
case supportsArm:
icon = successIcon
} else {
default:
latestSupportsArm, _ := images.CheckLatestLinuxArm64Support(image)
if latestSupportsArm {
icon = upgradeIcon
} else {
icon = failedIcon
}
}

fmt.Printf("%s %s\n", icon, image)
}
}

func init() {
rootCmd.AddCommand(imagesCmd)

imagesCmd.Flags().BoolP("debug", "d", false, "Enable debug mode")

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// imagesCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// imagesCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
12 changes: 3 additions & 9 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"github.com/spf13/cobra"
)

var debugEnabled bool

var rootCmd = &cobra.Command{
Use: "kubearchinspect",
Short: "Check how ready your Kubernetes cluster is to run on Arm.",
Expand All @@ -36,13 +38,5 @@ func Execute() {
}

func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.

// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.kubearchinspect.yaml)")

// Cobra also supports local flags, which will only run
// when this action is called directly.
// rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.PersistentFlags().BoolVarP(&debugEnabled, "debug", "d", false, "Enable debug mode")
}