From 50db40757e6fee28fed94fd71be8ca6645638c8a Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Mon, 31 Oct 2022 18:13:37 +0100 Subject: [PATCH 1/5] Use golangci-lint for header checks goheader's whitespace handling seems to be less fragile than license_checker's. This also means one less job in CI. Signed-off-by: Stephen Kitt --- .github/workflows/linting.yml | 10 ---------- .golangci.yml | 24 +++++++++++++++++++++++- .licenserc.json | 34 ---------------------------------- cmd/main.go | 4 ++++ 4 files changed, 27 insertions(+), 45 deletions(-) delete mode 100644 .licenserc.json diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 2dbf3310e..7b39248a9 100644 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -53,16 +53,6 @@ jobs: - name: Run golangci-lint run: make golangci-lint - headers: - name: License Headers - runs-on: ubuntu-latest - steps: - - name: Check out the repository - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - - - name: Check License Headers - uses: kt3k/license_checker@d12a6d90c58e30fefed09f2c4d03ba57f4c673a8 - licenses: name: Dependency Licenses runs-on: ubuntu-latest diff --git a/.golangci.yml b/.golangci.yml index 9747c437a..6b2f4ef22 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -14,6 +14,23 @@ linters-settings: godot: exclude: - ^\s*\+ + goheader: + template: |- + SPDX-License-Identifier: Apache-2.0 + + Copyright Contributors to the Submariner project. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. govet: enable: - fieldalignment @@ -68,7 +85,7 @@ linters: # - godox # Let's not forbid inline TODOs, FIXMEs et al - gofmt - gofumpt - # - goheader # We do license header linting another way + - goheader - goimports # - golint # Deprecated since v1.41.0 # - gomnd # It doesn't seem useful in general to enforce constants for all numeric values @@ -171,3 +188,8 @@ issues: - gochecknoinits - goerr113 - wrapcheck + + # Ignore header linting for internal files copied from Kubernetes + - path: internal/(cli|env|log)/.*\.go + linters: + - goheader diff --git a/.licenserc.json b/.licenserc.json deleted file mode 100644 index 52d905b0c..000000000 --- a/.licenserc.json +++ /dev/null @@ -1,34 +0,0 @@ -[ - { - "**/*.{go,proto}": [ - "Licensed under the Apache License, Version 2.0 (the \"License\");", - "you may not use this file except in compliance with the License.", - "You may obtain a copy of the License at", - " http://www.apache.org/licenses/LICENSE-2.0", - "Unless required by applicable law or agreed to in writing, software", - "distributed under the License is distributed on an \"AS IS\" BASIS,", - "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.", - "See the License for the specific language governing permissions and", - "limitations under the License." - ], - "ignore": [ - "vendor/" - ] - }, - { - "**/*.{go,proto}": [ - "SPDX-License-Identifier: Apache-2.0", - "Copyright Contributors to the Submariner project." - ], - "ignore": [ - "pkg/client/clientset/", - "internal/cli", - "internal/env", - "internal/log", - "vendor/" - ] - }, - { - "LICENSE": "Apache License" - } -] diff --git a/cmd/main.go b/cmd/main.go index bc348600f..d8805bf74 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -1,10 +1,14 @@ /* SPDX-License-Identifier: Apache-2.0 + Copyright Contributors to the Submariner project. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. From aceef48873bfe90c524841453ccbf54627142842 Mon Sep 17 00:00:00 2001 From: yanggang Date: Sat, 12 Nov 2022 14:02:01 +0800 Subject: [PATCH 2/5] Replace io/ioutil with os or io package Signed-off-by: yanggang --- internal/env/term_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/env/term_test.go b/internal/env/term_test.go index c2dc1bb67..e64abfdb5 100644 --- a/internal/env/term_test.go +++ b/internal/env/term_test.go @@ -18,7 +18,7 @@ package env_test import ( "bytes" - "io/ioutil" + "os" "testing" "github.com/submariner-io/subctl/internal/env" @@ -41,7 +41,7 @@ func TestIsTerminal(t *testing.T) { } // test a file - f, err := ioutil.TempFile("", "kind-isterminal") + f, err := os.CreateTemp("", "kind-isterminal") if err != nil { t.Fatalf("Failed to create tempfile %v", err) } From b4f26832f057aca4a47e072d892e6d1d9d60cdba Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Mon, 14 Nov 2022 15:36:20 +0100 Subject: [PATCH 3/5] Remove space between // and nolint This is enforced by newer releases of golangci-lint. Signed-off-by: Stephen Kitt --- cmd/subctl/diagnose.go | 8 ++++---- cmd/subctl/gather.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/subctl/diagnose.go b/cmd/subctl/diagnose.go index df1d7cc4b..fcb7005c9 100644 --- a/cmd/subctl/diagnose.go +++ b/cmd/subctl/diagnose.go @@ -214,7 +214,7 @@ func addDiagnoseFWConfigFlags(command *cobra.Command) { } func firewallIntraVxLANConfig(clusterInfo *cluster.Info, namespace string, status reporter.Interface) error { - return diagnose.FirewallIntraVxLANConfig( // nolint:wrapcheck // No need to wrap errors here. + return diagnose.FirewallIntraVxLANConfig( //nolint:wrapcheck // No need to wrap errors here. clusterInfo, namespace, diagnoseFirewallOptions, status) } @@ -254,7 +254,7 @@ func diagnoseAll(status reporter.Interface) error { fmt.Printf("Skipping inter-cluster firewall check as it requires two kubeconfigs." + " Please run \"subctl diagnose firewall inter-cluster\" command manually.\n") - return err // nolint:wrapcheck // No need to wrap errors here. + return err //nolint:wrapcheck // No need to wrap errors here. } func runLocalRemoteCommand(command *cobra.Command, localRemoteRestConfigProducer *restconfig.Producer, args []string, @@ -274,7 +274,7 @@ func runLocalRemoteCommand(command *cobra.Command, localRemoteRestConfigProducer exit.OnError(localProducer.RunOnSelectedContext( func(localClusterInfo *cluster.Info, localNamespace string, status reporter.Interface) error { - return remoteProducer.RunOnSelectedContext( // nolint:wrapcheck // No need to wrap errors here. + return remoteProducer.RunOnSelectedContext( //nolint:wrapcheck // No need to wrap errors here. func(remoteClusterInfo *cluster.Info, remoteNamespace string, status reporter.Interface) error { return function(localClusterInfo, remoteClusterInfo, localNamespace, diagnoseFirewallOptions, status) }, status) @@ -287,7 +287,7 @@ func runLocalRemoteCommand(command *cobra.Command, localRemoteRestConfigProducer func(remoteClusterInfo *cluster.Info, remoteNamespace string, status reporter.Interface) error { return function(localClusterInfo, remoteClusterInfo, localNamespace, diagnoseFirewallOptions, status) }, status) - return err // nolint:wrapcheck // No need to wrap errors here. + return err //nolint:wrapcheck // No need to wrap errors here. }, status)) } } diff --git a/cmd/subctl/gather.go b/cmd/subctl/gather.go index e4d821aeb..a037b416a 100644 --- a/cmd/subctl/gather.go +++ b/cmd/subctl/gather.go @@ -54,7 +54,7 @@ var gatherCmd = &cobra.Command{ exit.OnError(gatherRestConfigProducer.RunOnAllContexts( func(clusterInfo *cluster.Info, namespace string, status reporter.Interface) error { - return gather.Data(clusterInfo, status, options) // nolint:wrapcheck // No need to wrap errors here. + return gather.Data(clusterInfo, status, options) //nolint:wrapcheck // No need to wrap errors here. }, status)) }, } From 1ea4703fd16e3585a1bb8bfc84a69ba80156a5e9 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Mon, 14 Nov 2022 15:46:01 +0100 Subject: [PATCH 4/5] Disable deprecated linters varcheck, deadcode, and structcheck are deprecated since 1.49.0. Signed-off-by: Stephen Kitt --- .golangci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 6b2f4ef22..5ebbb9dd8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -58,7 +58,6 @@ linters: - bodyclose - contextcheck # - cyclop # This is equivalent to gocyclo - - deadcode - depguard - dogsled - dupl @@ -121,7 +120,6 @@ linters: # - scopelint # Deprecated since v1.39.0 # - sqlclosecheck # We don't use SQL - staticcheck - - structcheck - stylecheck # - tagliatelle # Inconsistent with stylecheck and not as good # - tenv # Not relevant for our Ginkgo UTs @@ -132,7 +130,6 @@ linters: - unconvert - unparam - unused - - varcheck # - varnamelen # It doesn't seem necessary to enforce a minimum variable name length - wastedassign - whitespace From 6ecd931a0d14e277440a86dfd2ba69debfb4f305 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Mon, 14 Nov 2022 15:50:29 +0100 Subject: [PATCH 5/5] Avoid conflicts between doc and nolint comments This causes gci etc. to fail. Signed-off-by: Stephen Kitt --- pkg/serviceaccount/ensure.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/serviceaccount/ensure.go b/pkg/serviceaccount/ensure.go index 062378f53..b0d44d251 100644 --- a/pkg/serviceaccount/ensure.go +++ b/pkg/serviceaccount/ensure.go @@ -44,13 +44,12 @@ const ( ) // ensureFromYAML creates the given service account. -//nolint:wrapcheck // No need to wrap errors here. func ensureFromYAML(kubeClient kubernetes.Interface, namespace, yaml string) (*corev1.ServiceAccount, error) { sa := &corev1.ServiceAccount{} err := embeddedyamls.GetObject(yaml, sa) if err != nil { - return nil, err + return nil, err //nolint:wrapcheck // No need to wrap errors here. } err = ensure(kubeClient, namespace, sa, true)