diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 9cf51c17..a098b7ee 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -15,6 +15,6 @@ jobs: with: go-version-file: 'go.mod' - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: - version: v1.64 + version: v2.0 \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index bcb1adb8..af684e57 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,4 +16,4 @@ jobs: - uses: actions/setup-go@v5 with: go-version-file: 'go.mod' - - run: make test + - run: make test-only diff --git a/.golangci.yaml b/.golangci.yaml index 403e9c09..fcd11a7b 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -1,26 +1,40 @@ -run: - timeout: 10m - +version: "2" linters: enable: - - revive - - ineffassign - - misspell - - goimports - importas - + - misspell + - revive + settings: + misspell: + ignore-rules: + - strat + revive: + severity: error + rules: + - name: exported + arguments: + - disableStutteringCheck + - name: if-return + disabled: true + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ severity: - default-severity: error - -linters-settings: - misspell: - ignore-words: - - strat - revive: - severity: error - rules: - - name: exported - arguments: - - disableStutteringCheck - - name: if-return - disabled: true + default: error +formatters: + enable: + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index c6ba0081..7128c3fc 100644 --- a/Makefile +++ b/Makefile @@ -350,7 +350,7 @@ CONTROLLER_TOOLS_VERSION ?= v0.16.0 GEN_CRD_API_REFERENCE_DOCS_VERSION ?= v0.3.0 ADDLICENSE_VERSION ?= v1.1.1 GOIMPORTS_VERSION ?= v0.25.0 -GOLANGCI_LINT_VERSION ?= v1.64 +GOLANGCI_LINT_VERSION ?= v2.0 OPENAPI_EXTRACTOR_VERSION ?= v0.1.9 KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" @@ -418,4 +418,4 @@ $(GOIMPORTS): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) + test -s $(LOCALBIN)/golangci-lint || GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) \ No newline at end of file diff --git a/apimachinery/api/net/net.go b/apimachinery/api/net/net.go index 96e0691c..fbeac1f6 100644 --- a/apimachinery/api/net/net.go +++ b/apimachinery/api/net/net.go @@ -62,7 +62,7 @@ func (i IP) ToUnstructured() interface{} { if i.IsZero() { return nil } - return i.Addr.String() + return i.String() } func (i *IP) IsValid() bool { @@ -84,9 +84,9 @@ func (i IP) Family() v1.IPFamily { } } -func (_ IP) OpenAPISchemaType() []string { return []string{"string"} } +func (i IP) OpenAPISchemaType() []string { return []string{"string"} } -func (_ IP) OpenAPISchemaFormat() string { return "ip" } +func (i IP) OpenAPISchemaFormat() string { return "ip" } func NewIP(ip netip.Addr) IP { return IP{ip} @@ -138,7 +138,7 @@ func (i IPPrefix) GomegaString() string { } func (i IPPrefix) IP() IP { - return IP{i.Prefix.Addr()} + return IP{i.Addr()} } func (i *IPPrefix) UnmarshalJSON(b []byte) error { @@ -193,9 +193,9 @@ func (in *IPPrefix) IsZero() bool { return in == nil || !in.Prefix.IsValid() } -func (_ IPPrefix) OpenAPISchemaType() []string { return []string{"string"} } +func (in IPPrefix) OpenAPISchemaType() []string { return []string{"string"} } -func (_ IPPrefix) OpenAPISchemaFormat() string { return "ip-prefix" } +func (in IPPrefix) OpenAPISchemaFormat() string { return "ip-prefix" } func NewIPPrefix(prefix netip.Prefix) *IPPrefix { return &IPPrefix{Prefix: prefix} diff --git a/apinetlet/controllers/networkpolicy_controller.go b/apinetlet/controllers/networkpolicy_controller.go index 3b15c85e..80edd44b 100644 --- a/apinetlet/controllers/networkpolicy_controller.go +++ b/apinetlet/controllers/networkpolicy_controller.go @@ -329,11 +329,11 @@ func (r *NetworkPolicyReconciler) fetchIPsFromNetworkInterfaces(ctx context.Cont for _, ip := range nic.Spec.IPs { ipFamily := corev1.IPv4Protocol - if ip.Addr.Is6() { + if ip.Is6() { ipFamily = corev1.IPv6Protocol } ips = append(ips, apinetv1alpha1.ObjectIP{ - Prefix: net.IPPrefix{Prefix: netip.PrefixFrom(ip.Addr, ip.Addr.BitLen())}, + Prefix: net.IPPrefix{Prefix: netip.PrefixFrom(ip.Addr, ip.BitLen())}, IPFamily: ipFamily, }) } @@ -364,7 +364,7 @@ func (r *NetworkPolicyReconciler) fetchIPsFromLoadBalancers(ctx context.Context, for _, ip := range lb.Spec.IPs { // TODO: handle LoadBalancerIP when only IPFamily is specified to allocate a random IP. ips = append(ips, apinetv1alpha1.ObjectIP{ - Prefix: net.IPPrefix{Prefix: netip.PrefixFrom(ip.IP.Addr, ip.IP.Addr.BitLen())}, + Prefix: net.IPPrefix{Prefix: netip.PrefixFrom(ip.IP.Addr, ip.IP.BitLen())}, IPFamily: ip.IPFamily, }) } diff --git a/internal/app/apiserver/apiserver.go b/internal/app/apiserver/apiserver.go index 4d7b25db..99628a64 100644 --- a/internal/app/apiserver/apiserver.go +++ b/internal/app/apiserver/apiserver.go @@ -158,8 +158,8 @@ func (o *IronCoreNetServerOptions) Run(ctx context.Context) error { } server.GenericAPIServer.AddPostStartHookOrDie("start-ironcore-net-server-informers", func(hookContext genericapiserver.PostStartHookContext) error { - config.GenericConfig.SharedInformerFactory.Start(hookContext.Context.Done()) - o.SharedInformerFactory.Start(hookContext.Context.Done()) + config.GenericConfig.SharedInformerFactory.Start(hookContext.Done()) + o.SharedInformerFactory.Start(hookContext.Done()) return nil }) diff --git a/internal/controllers/certificateapproval_controller.go b/internal/controllers/certificateapproval_controller.go index b5e1890b..207dff36 100644 --- a/internal/controllers/certificateapproval_controller.go +++ b/internal/controllers/certificateapproval_controller.go @@ -96,7 +96,7 @@ func (r *CertificateApprovalReconciler) authorize(ctx context.Context, csr *cert ResourceAttributes: &attrs, }, } - if err := r.Client.Create(ctx, sar); err != nil { + if err := r.Create(ctx, sar); err != nil { return false, fmt.Errorf("error creating subject access review: %w", err) } return sar.Status.Allowed, nil diff --git a/internal/controllers/scheduler_controller.go b/internal/controllers/scheduler_controller.go index 4ae09da2..cc14d9a5 100644 --- a/internal/controllers/scheduler_controller.go +++ b/internal/controllers/scheduler_controller.go @@ -468,7 +468,7 @@ func (r *SchedulerReconciler) reconcileExists( return ctrl.Result{}, fmt.Errorf("error getting nodes for instance: %w", err) } if len(nodes) == 0 { - r.EventRecorder.Event(inst, corev1.EventTypeNormal, outOfCapacity, "No nodes available to schedule instance on") + r.Event(inst, corev1.EventTypeNormal, outOfCapacity, "No nodes available to schedule instance on") return ctrl.Result{}, nil } diff --git a/internal/controllers/util.go b/internal/controllers/util.go index edd8df31..dab54840 100644 --- a/internal/controllers/util.go +++ b/internal/controllers/util.go @@ -101,7 +101,7 @@ func ReplaceDaemonSetInstanceNodeNameNodeAffinity(affinity *v1alpha1.Affinity, n // avoid bad words. func ComputeHash(template *v1alpha1.InstanceTemplate, collisionCount *int32) string { podTemplateSpecHasher := fnv.New32a() - _, _ = podTemplateSpecHasher.Write([]byte(fmt.Sprintf("%#+v", *template))) + _, _ = fmt.Fprintf(podTemplateSpecHasher, "%#+v", *template) // Add collisionCount in the hash if it exists. if collisionCount != nil {