Skip to content
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
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
lint:
runs-on: ubuntu-24.04
steps:
- uses: actions/setup-go@v2.1.4
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.21
- uses: actions/checkout@v2.4.0
go-version-file: go.mod
- name: "Lint the code"
run: make lint
- name: "Verify generate"
Expand Down
47 changes: 43 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: "2"

linters:
enable:
- arangolint
- asasalint
- asciicheck
- bidichk
Expand All @@ -15,6 +16,7 @@ linters:
- dupl
- dupword
- durationcheck
- embeddedstructfieldcheck
- errcheck
- errchkjson
- errname
Expand All @@ -24,6 +26,8 @@ linters:
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- godoclint
- godot
- gochecknoinits
- gochecksumtype
- goconst
Expand All @@ -37,9 +41,12 @@ linters:
- govet
- grouper
- iface
- inamedparam
- importas
- ineffassign
- interfacebloat
- intrange
- iotamixing
- lll
- loggercheck
- makezero
Expand Down Expand Up @@ -67,6 +74,7 @@ linters:
- tparallel
- unconvert
- unparam
- unqueryvet
- unused
- usestdlibvars
- usetesting
Expand All @@ -78,36 +86,67 @@ linters:
# These linters are disabled ONLY because fixing/investigating their complaints initially was too overwhelming.
# We SHOULD try and evaluate each of them eventually and either fix their reports
# or comment here on why we decided to not listen to them.
# 15 issues: many functions exceed default cyclomatic complexity threshold
- cyclop
# 50 issues: needs allowlist configuration for all imports
- depguard
# 50 issues: requires wrapping all errors with fmt.Errorf
- err113
# 6 issues: requires error type assertions to use errors.As/errors.Is
- errorlint
# 50 issues: requires initializing every struct field explicitly
- exhaustruct
# 6 issues: forbids fmt.Print*/os.Stdout usage
- forbidigo
# 18 issues: enforces function declaration ordering within files
- funcorder
# 28 issues: many functions exceed default length limit
- funlen
# 15 issues: flags all package-level variables
- gochecknoglobals
# 4 issues: similar to cyclop, flags high cognitive complexity
- gocognit
- godot
# 9 issues: flags TODO/FIXME comments
- godox
# 11 issues: flags potential security issues (hardcoded credentials, weak crypto, etc.)
- gosec
- inamedparam
- intrange
# 28 issues: forbids returning interfaces
- ireturn
- gochecknoglobals
# 2 issues: flags functions with low maintainability index
- maintidx
# 20 issues: flags magic numbers throughout the code
- mnd
# 7 issues: suggests using modern Go idioms (e.g. slices.Contains)
- modernize
# 4 issues: requires struct tags on marshaled types
- musttag
# 7 issues: flags deeply nested if statements
- nestif
# 3 issues: flags functions returning both nil error and nil value
- nilnil
# 7 issues: requires blank lines before return/branch statements
- nlreturn
# 3 issues: forbids inline error handling (if err := ...; err != nil)
- noinlineerr
# 13 issues: forbids named return values
- nonamedreturns
# 50 issues: requires t.Parallel() in every test
- paralleltest
# 8 issues: suggests replacing fmt.Sprintf with faster alternatives
- perfsprint
# 4 issues: suggests preallocating slices
- prealloc
# 27 issues: enforces struct tag alignment
- tagalign
# 27 issues: enforces testify best practices
- testifylint
# 31 issues: requires using separate _test packages
- testpackage
# 6 issues: requires t.Helper() in test helper functions
- thelper
# 50 issues: enforces minimum variable name length
- varnamelen
# 50 issues: requires wrapping errors from external packages
- wrapcheck
settings:
errcheck:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BUILD_DATE := $(shell date -u -d "@$SOURCE_DATE_EPOCH" "+${DATE_FMT}" 2>/dev/nul
LDFLAGS := -X ${GIT_VERSION_PATH}=${GIT_VERSION} -X ${GIT_COMMIT_PATH}=${GIT_COMMIT} -X ${BUILD_DATE_PATH}=${BUILD_DATE}

# Please update the list of linters in .golagci.yml when bumping the version.
GOLANGCI_LINT_VER = 2.7.2
GOLANGCI_LINT_VER = 2.11.4
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION ?= 1.25.0

Expand Down
8 changes: 4 additions & 4 deletions internal/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/kudobuilder/kuttl/internal/step"
)

// Assert checks all provided assert files against a namespace. Upon assert failure, it prints the failures and returns an error
// Assert checks all provided assert files against a namespace. Upon assert failure, it prints the failures and returns an error.
func Assert(namespace string, timeout int, assertFiles ...string) error {
var objects []client.Object

Expand All @@ -31,7 +31,7 @@ func Assert(namespace string, timeout int, assertFiles ...string) error {
s := setupStep()

var testErrors []error
for i := 0; i < timeout; i++ {
for range timeout {
// start fresh
testErrors = []error{}
for _, expected := range objects {
Expand All @@ -56,7 +56,7 @@ func Assert(namespace string, timeout int, assertFiles ...string) error {
return errors.New("asserts not valid")
}

// Errors checks all provided errors files against a namespace. Upon assert failure, it prints the failures and returns an error
// Errors checks all provided errors files against a namespace. Upon assert failure, it prints the failures and returns an error.
func Errors(namespace string, timeout int, errorFiles ...string) error {
var objects []client.Object

Expand All @@ -71,7 +71,7 @@ func Errors(namespace string, timeout int, errorFiles ...string) error {
s := setupStep()

var testErrors []error
for i := 0; i < timeout; i++ {
for range timeout {
// start fresh
testErrors = []error{}
for _, expected := range objects {
Expand Down
2 changes: 1 addition & 1 deletion internal/assert/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package assert

import "testing"

// TestDummy is a no-op test to satisfy coverage tools
// TestDummy is a no-op test to satisfy coverage tools.
func TestDummy(_ *testing.T) {
// This test exists only to ensure the package is recognized by go test
// and to avoid "go: no such tool 'covdata'" warnings
Expand Down
2 changes: 1 addition & 1 deletion internal/expressions/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package expressions

import "testing"

// TestDummy is a no-op test to satisfy coverage tools
// TestDummy is a no-op test to satisfy coverage tools.
func TestDummy(_ *testing.T) {
// This test exists only to ensure the package is recognized by go test
// and to avoid "go: no such tool 'covdata'" warnings
Expand Down
4 changes: 2 additions & 2 deletions internal/file/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func ToObjects(paths []string) ([]client.Object, error) {
}

// FromPath from a file or dir path returns an array of flat file paths.
// pattern is a filepath.Match pattern to limit files to a pattern
// pattern is a filepath.Match pattern to limit files to a pattern.
func FromPath(path, pattern string) ([]string, error) {
files := []string{}

Expand Down Expand Up @@ -61,7 +61,7 @@ func FromPath(path, pattern string) ([]string, error) {
return files, nil
}

// TrimExt removes the ext of a file path, foo.tar == foo
// TrimExt removes the ext of a file path, foo.tar == foo.
func TrimExt(path string) string {
return strings.TrimSuffix(path, filepath.Ext(path))
}
4 changes: 2 additions & 2 deletions internal/file/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// UntarInPlace untars a .tar file using the same name as the file as the sub-folder name in the folder it was referenced in.
// i.e., /opt/foo.tar will land in /opt/foo
// supports tar and tgz file formats
// supports tar and tgz file formats.
func UntarInPlace(path string) error {
folder := TrimExt(path)
file, err := os.Open(path)
Expand All @@ -26,7 +26,7 @@ func UntarInPlace(path string) error {
// UnTar untars a tar or tgz file into the dest folder.
// dest is the folder location
// io.Reader is a reader that is tar (or compressed tar) format
// compressed is true if reader is a compressed format
// compressed is true if reader is a compressed format.
func UnTar(dest string, r io.Reader, compressed bool) (err error) {
if compressed {
gzr, err := gzip.NewReader(r)
Expand Down
8 changes: 4 additions & 4 deletions internal/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (h *Harness) RunKIND() (*rest.Config, error) {
}

// initTempPath creates the temp folder if needed.
// various parts of system may need it, starting with kind, or working with tar test suites
// various parts of system may need it, starting with kind, or working with tar test suites.
func (h *Harness) initTempPath() (err error) {
if h.tempPath == "" {
h.tempPath, err = os.MkdirTemp("", "kuttl")
Expand Down Expand Up @@ -430,7 +430,7 @@ func (h *Harness) RunTests() {
h.T.Log("run tests finished")
}

// testPreProcessing provides preprocessing bring all tests suites local if there are any refers to URLs
// testPreProcessing provides preprocessing bring all tests suites local if there are any refers to URLs.
func (h *Harness) testPreProcessing() []string {
testDirs := []string{}
// preprocessing step
Expand Down Expand Up @@ -617,7 +617,7 @@ func (h *Harness) Stop() {
}

// wraps Test.Fatal in order to clean up harness
// fatal should NOT be used with a go routine, it is not thread safe
// fatal should NOT be used with a go routine, it is not thread safe.
func (h *Harness) fatal(err error) {
// clean up on fatal in setup
if !h.stopping {
Expand All @@ -644,7 +644,7 @@ func (h *Harness) Report() {
}
}

// NewSuiteReport creates and assigns a TestSuite to the TestSuites (then returns the suite),
// NewSuiteReport creates and assigns a TestSuite to the TestSuites (then returns the suite).
func (h *Harness) NewSuiteReport(name string) *report.Testsuite {
suite := report.NewSuite(name, h.TestSuite.ReportGranularity)
h.report.AddTestSuite(suite)
Expand Down
2 changes: 1 addition & 1 deletion internal/harness/harness_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestHarnessRunIntegrationWithConfig(t *testing.T) {
}
}

// This test requires external KinD support to run thus is an integration test
// This test requires external KinD support to run thus is an integration test.
func TestRunBackgroundCommands(t *testing.T) {
h := Harness{
T: t,
Expand Down
8 changes: 4 additions & 4 deletions internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/kudobuilder/kuttl/internal/version"
)

// Client is client used to simplified http requests for tarballs
// Client is client used to simplified http requests for tarballs.
type Client struct {
client *http.Client
UserAgent string
Expand All @@ -35,7 +35,7 @@ func (c *Client) Get(url string) (*http.Response, error) {
}

// GetByteBuffer performs HTTP get, retrieves the contents and returns a bytes.Buffer of the entire contents
// this could be dangerous against an extremely large file
// this could be dangerous against an extremely large file.
func (c *Client) GetByteBuffer(url string) (*bytes.Buffer, error) {
buf := bytes.NewBuffer(nil)

Expand Down Expand Up @@ -139,7 +139,7 @@ func (wc *writeCounter) Write(p []byte) (int, error) {
return n, nil
}

// PrintProgress prints the progress of a file write
// PrintProgress prints the progress of a file write.
func (wc *writeCounter) PrintProgress() {
// Clear the line by using a character return to go back to the start and remove
// the remaining characters by filling it with spaces
Expand All @@ -150,7 +150,7 @@ func (wc *writeCounter) PrintProgress() {
fmt.Printf("\rDownloading (%s) %s complete", wc.Name, humanize.Bytes(wc.Total))
}

// NewClient creates HTTP client
// NewClient creates HTTP client.
func NewClient() *Client {
var client Client
tr := &http.Transport{
Expand Down
4 changes: 2 additions & 2 deletions internal/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/kudobuilder/kuttl/internal/kubernetes"
)

// IsURL returns true if string is an URL
// IsURL returns true if string is an URL.
func IsURL(str string) bool {
u, err := url.Parse(str)
return err == nil && u.Scheme != "" && u.Host != ""
Expand All @@ -35,7 +35,7 @@ func ToObjects(urlPath string) ([]client.Object, error) {
return apply, nil
}

// Read returns a buffer for the file at the url
// Read returns a buffer for the file at the url.
func Read(urlPath string) (*bytes.Buffer, error) {
c := NewClient()
return c.GetByteBuffer(urlPath)
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/fake/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package fake

import "testing"

// TestDummy is a no-op test to satisfy coverage tools
// TestDummy is a no-op test to satisfy coverage tools.
func TestDummy(_ *testing.T) {
// This test exists only to ensure the package is recognized by go test
// and to avoid "go: no such tool 'covdata'" warnings
Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/retry_client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestMain(m *testing.M) {

func TestCreateOrUpdate(t *testing.T) {
// Run the test a bunch of times to try to trigger a conflict and ensure that it handles conflicts properly.
for i := 0; i < 10; i++ {
for i := range 10 {
namespaceName := fmt.Sprintf("default-%d", i)
namespaceObj := NewResource("v1", "Namespace", namespaceName, "default")

Expand Down
4 changes: 2 additions & 2 deletions internal/kubernetes/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func countLines(k string, v interface{}) (int, error) {
return strings.Count(buf.String(), "\n"), nil
}

// PrettyDiff creates a unified diff highlighting the differences between two Kubernetes resources
// PrettyDiff creates a unified diff highlighting the differences between two Kubernetes resources.
func PrettyDiff(expected *unstructured.Unstructured, actual *unstructured.Unstructured) (string, error) {
actualPruned := pruneLargeAdditions(expected, actual)

Expand Down Expand Up @@ -199,7 +199,7 @@ func LoadYAMLFromFile(path string) ([]client.Object, error) {
return LoadYAML(path, opened)
}

// LoadYAML loads all objects from a reader
// LoadYAML loads all objects from a reader.
func LoadYAML(path string, r io.Reader) ([]client.Object, error) {
yamlReader := yaml.NewYAMLReader(bufio.NewReader(r))

Expand Down
2 changes: 1 addition & 1 deletion internal/kubernetes/unstructured.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewResource(apiVersion, kind, name, namespace string) *unstructured.Unstruc
}
}

// NewClusterRoleBinding Create a clusterrolebinding for the serviceAccount passed
// NewClusterRoleBinding Create a clusterrolebinding for the serviceAccount passed.
func NewClusterRoleBinding(apiVersion, kind, name, namespace string, serviceAccount string, roleName string) runtime.Object {
sa := &rbacv1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion internal/kuttlctl/cmd/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
kubectl kuttl assert <path/to/assertfile.yaml>`
)

// newAssertCmd returns a new initialized instance of the assert sub command
// newAssertCmd returns a new initialized instance of the assert sub command.
func newAssertCmd() *cobra.Command {
timeout := 5
namespace := "default"
Expand Down
2 changes: 1 addition & 1 deletion internal/kuttlctl/cmd/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
kubectl kuttl errors <path/to/errorsfile.yaml> <path/to/errorsfile.yaml>...`
)

// newErrorsCmd returns a new initialized instance of the errors sub command
// newErrorsCmd returns a new initialized instance of the errors sub command.
func newErrorsCmd() *cobra.Command {
timeout := 5
namespace := "default"
Expand Down
Loading
Loading