diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/lint.yml similarity index 93% rename from .github/workflows/golangci-lint.yml rename to .github/workflows/lint.yml index d3754b7..a31f7ea 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/lint.yml @@ -17,4 +17,4 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.59 + version: v1.61 diff --git a/.golangci.yaml b/.golangci.yaml deleted file mode 100644 index d8c320c..0000000 --- a/.golangci.yaml +++ /dev/null @@ -1,26 +0,0 @@ -run: - concurrency: 4 - timeout: 10m - -linters: - enable: - - revive - - ineffassign - - misspell - - goimports - - importas - - unused - - ginkgolinter - -severity: - default-severity: error - -linters-settings: - revive: - severity: error - rules: - - name: exported - arguments: - - disableStutteringCheck - - name: if-return - disabled: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..4d143cb --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,61 @@ +run: + timeout: 10m + allow-parallel-runners: true + +issues: + # don't skip warning about doc comments + # don't exclude the default set of lint + exclude-use-default: false + # restore some of the defaults + # (fill in the rest as needed) + exclude-rules: + - path: "clientutils/*" + linters: + - lll + - path: "envtestutils/*" + linters: + - lll + - path: "unstructuredutils/*" + linters: + - lll + - path: "metautils/*" + linters: + - lll + - path: "kustomizeutils/*" + linters: + - lll + - path: "configutils/*" + linters: + - lll + - path: "conditionutils/*" + linters: + - lll + - path: "testutils/*" + linters: + - lll + - path: "cmdutils/*" + linters: + - dupl +linters: + disable-all: true + enable: + - copyloopvar + - dupl + - errcheck + - goconst + - gocyclo + - gofmt + - goimports + - gosimple + - govet + - ineffassign + - ginkgolinter + - lll + - misspell + - nakedret + - prealloc + - staticcheck + - typecheck + - unconvert + - unparam + - unused \ No newline at end of file diff --git a/.reuse/dep5 b/.reuse/dep5 index 01cc9ea..d47f051 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -9,7 +9,7 @@ Source: https://github.com/ironcore-dev/controller-utils Files: .github/* .gitignore - .golangci.yaml + .golangci.yml CODEOWNERS CODE_OF_CONDUCT.md CONTRIBUTING.md diff --git a/Makefile b/Makefile index 74ac97d..2196c14 100644 --- a/Makefile +++ b/Makefile @@ -73,9 +73,9 @@ GOLANGCILINT ?= $(LOCALBIN)/golangci-lint ## Tool Versions ADDLICENSE_VERSION ?= v1.1.1 -GOIMPORTS_VERSION ?= v0.22.0 +GOIMPORTS_VERSION ?= v0.25.0 MOCKGEN_VERSION ?= v0.4.0 -GOLANGCILINT_VERSION ?= v1.59.1 +GOLANGCILINT_VERSION ?= v1.61.0 .PHONY: addlicense addlicense: $(ADDLICENSE) ## Download addlicense locally if necessary. diff --git a/clientutils/clientutils.go b/clientutils/clientutils.go index 44c0cc2..2d1c357 100644 --- a/clientutils/clientutils.go +++ b/clientutils/clientutils.go @@ -488,10 +488,9 @@ func CreateOrUseAndPatch( var ( base = obj.DeepCopyObject().(client.Object) best client.Object - other []client.Object + other = make([]client.Object, 0, len(objects)) ) for _, object := range objects { - object := object if err := setObject(obj, object); err != nil { return controllerutil.OperationResultNone, nil, err } diff --git a/conditionutils/conditionutils.go b/conditionutils/conditionutils.go index f1000d0..eda95cd 100644 --- a/conditionutils/conditionutils.go +++ b/conditionutils/conditionutils.go @@ -116,7 +116,7 @@ func getAndConvertField(v reflect.Value, name string, into interface{}) error { // Otherwise, it returns a pointer to that value. func direct(v reflect.Value) reflect.Value { if v.IsZero() { - return reflect.New(reflect.PtrTo(v.Type())).Elem() + return reflect.New(reflect.PointerTo(v.Type())).Elem() } res := reflect.New(v.Type()) diff --git a/go.mod b/go.mod index f562138..e1ce6ef 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/ironcore-dev/controller-utils -go 1.22.3 +go 1.23.0 require ( github.com/onsi/ginkgo/v2 v2.20.2 @@ -8,13 +8,13 @@ require ( github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 go.uber.org/mock v0.4.0 - k8s.io/api v0.29.7 - k8s.io/apiextensions-apiserver v0.29.7 - k8s.io/apimachinery v0.29.7 - k8s.io/apiserver v0.29.7 - k8s.io/client-go v0.29.7 + k8s.io/api v0.29.9 + k8s.io/apiextensions-apiserver v0.29.9 + k8s.io/apimachinery v0.29.9 + k8s.io/apiserver v0.29.9 + k8s.io/client-go v0.29.9 k8s.io/utils v0.0.0-20231127182322-b307cd553661 - sigs.k8s.io/controller-runtime v0.17.5 + sigs.k8s.io/controller-runtime v0.17.6 sigs.k8s.io/kustomize/api v0.17.3 sigs.k8s.io/kustomize/kyaml v0.17.2 sigs.k8s.io/yaml v1.4.0 @@ -91,7 +91,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/component-base v0.29.7 // indirect + k8s.io/component-base v0.29.9 // indirect k8s.io/klog/v2 v2.110.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 // indirect diff --git a/go.sum b/go.sum index 0670f20..a186bab 100644 --- a/go.sum +++ b/go.sum @@ -233,18 +233,18 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.29.7 h1:Q2/thp7YYESgy0MGzxT9RvA/6doLJHBXSFH8GGLxSbc= -k8s.io/api v0.29.7/go.mod h1:mPimdbyuIjwoLtBEVIGVUYb4BKOE+44XHt/n4IqKsLA= -k8s.io/apiextensions-apiserver v0.29.7 h1:X62u7vUGfwW5rYJB5jkZDr0uV2XSyEHJRdxnfD5PaLs= -k8s.io/apiextensions-apiserver v0.29.7/go.mod h1:JzBXxlZKKdtEYGr4yiN+s0eXheCTYgKDay8JXPfSGoQ= -k8s.io/apimachinery v0.29.7 h1:ICXzya58Q7hyEEfnTrbmdfX1n1schSepX2KUfC2/ykc= -k8s.io/apimachinery v0.29.7/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= -k8s.io/apiserver v0.29.7 h1:yvdZAZJ6Bmih8Iu8CqUB74otyPP0OM3XKzYzAFiWsY4= -k8s.io/apiserver v0.29.7/go.mod h1:MjEld3ySZrQ4eOzf6OKANT/v8GvM3sb1e5vozXoIirs= -k8s.io/client-go v0.29.7 h1:vTtiFrGBKlcBhxaeZC4eDrqui1e108nsTyue/KU63IY= -k8s.io/client-go v0.29.7/go.mod h1:69BvVqdRozgR/9TP45u/oO0tfrdbP+I8RqrcCJQshzg= -k8s.io/component-base v0.29.7 h1:zXLJvZjvvDWdYmZCwZYk95E1Fd2oRXUz71mQukkRk5I= -k8s.io/component-base v0.29.7/go.mod h1:ddLTpIrjazaRI1EG83M41GNcYEAdskuQmx4JOOSXCOg= +k8s.io/api v0.29.9 h1:FwdflpNsfMUYUOblMZNWJ4K/q0OSL5A4jGa0iOgcJco= +k8s.io/api v0.29.9/go.mod h1:fNhmzRfKaSEHCmczA/jRx6CiDKhYOnFLJBERMJAXEk8= +k8s.io/apiextensions-apiserver v0.29.9 h1:EB6RK06kFJjbzBwU1YiVznxrcgBE0hhDWt6EQQIcOy4= +k8s.io/apiextensions-apiserver v0.29.9/go.mod h1:jcaHG6R/bB1iU6XzC1DMhB1x2ktTJLt2KKpg6B65Z2c= +k8s.io/apimachinery v0.29.9 h1:YZ8HUid1TzQVz94cnNlsQjLdH0VoAhWSqz7t0q6B12A= +k8s.io/apimachinery v0.29.9/go.mod h1:i3FJVwhvSp/6n8Fl4K97PJEP8C+MM+aoDq4+ZJBf70Y= +k8s.io/apiserver v0.29.9 h1:BiHTZbAYcNYHTE9RlWMBe5AX2XoZbRujy6oo5krU4V8= +k8s.io/apiserver v0.29.9/go.mod h1:3zmBeYworciVZHs8jSfzt/naTpDQb3AM++aYJ5Pkqqo= +k8s.io/client-go v0.29.9 h1:4f/Wz6li3rEyIPFj32XAQMtOGMM1tg7KQi1oeS6ibPg= +k8s.io/client-go v0.29.9/go.mod h1:2N1drQEZ5yiYrWVaE2Un8JiISUhl47D8pyZlYLszke4= +k8s.io/component-base v0.29.9 h1:lPENvp3CCwdeMEWGjiTfn5b287qQYuK7gX32OBOovmA= +k8s.io/component-base v0.29.9/go.mod h1:NGDa6Ih0EdcLA2G4K2ZYySoiB+2Tn+rmSqPyudCPgDY= k8s.io/klog/v2 v2.110.1 h1:U/Af64HJf7FcwMcXyKm2RPM22WZzyR7OSpYj5tg3cL0= k8s.io/klog/v2 v2.110.1/go.mod h1:YGtd1984u+GgbuZ7e08/yBuAfKLSO0+uR1Fhi6ExXjo= k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780= @@ -253,8 +253,8 @@ k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6R k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0 h1:TgtAeesdhpm2SGwkQasmbeqDo8th5wOBA5h/AjTKA4I= sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.28.0/go.mod h1:VHVDI/KrK4fjnV61bE2g3sA7tiETLn8sooImelsCx3Y= -sigs.k8s.io/controller-runtime v0.17.5 h1:1FI9Lm7NiOOmBsgTV36/s2XrEFXnO2C4sbg/Zme72Rw= -sigs.k8s.io/controller-runtime v0.17.5/go.mod h1:N0jpP5Lo7lMTF9aL56Z/B2oWBJjey6StQM0jRbKQXtY= +sigs.k8s.io/controller-runtime v0.17.6 h1:12IXsozEsIXWAMRpgRlYS1jjAHQXHtWEOMdULh3DbEw= +sigs.k8s.io/controller-runtime v0.17.6/go.mod h1:N0jpP5Lo7lMTF9aL56Z/B2oWBJjey6StQM0jRbKQXtY= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0= sigs.k8s.io/kustomize/api v0.17.3 h1:6GCuHSsxq7fN5yhF2XrC+AAr8gxQwhexgHflOAD/JJU= diff --git a/metautils/metautils.go b/metautils/metautils.go index 333ca50..a7bd56f 100644 --- a/metautils/metautils.go +++ b/metautils/metautils.go @@ -28,14 +28,13 @@ func ConvertAndSetList(scheme *runtime.Scheme, list runtime.Object, objs []runti return err } - var converted []runtime.Object - for _, obj := range objs { + converted := make([]runtime.Object, len(objs)) + for i, obj := range objs { into := reflect.New(elemType).Interface() if err := scheme.Convert(obj, into, nil); err != nil { return err } - - converted = append(converted, into.(runtime.Object)) + converted[i] = into.(runtime.Object) } return meta.SetList(list, converted) } diff --git a/modutils/modutils.go b/modutils/modutils.go index 5d0bbf8..a851b7b 100644 --- a/modutils/modutils.go +++ b/modutils/modutils.go @@ -99,7 +99,6 @@ func (e *Executor) GetE(name string) (*Module, error) { continue } - mod := mod return &mod, nil } return nil, fmt.Errorf("module %q not found", name) diff --git a/unstructuredutils/unstructuredutils.go b/unstructuredutils/unstructuredutils.go index 06f4e13..d9d3df0 100644 --- a/unstructuredutils/unstructuredutils.go +++ b/unstructuredutils/unstructuredutils.go @@ -63,7 +63,7 @@ func Read(r io.Reader) ([]unstructured.Unstructured, error) { for { ext := runtime.RawExtension{} if err := d.Decode(&ext); err != nil { - if !errors.Is(io.EOF, err) { + if !errors.Is(err, io.EOF) { return nil, fmt.Errorf("error parsing: %w", err) } return objs, nil @@ -107,7 +107,6 @@ func UnstructuredSliceToObjectSlice(unstructureds []unstructured.Unstructured) [ } res := make([]client.Object, 0, len(unstructureds)) for _, u := range unstructureds { - u := u res = append(res, &u) } return res