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

Automated backport of #347: Use golangci-lint for header checks #375: Replace io/ioutil with os or io package #379: Remove space between // and nolint #1050

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
10 changes: 0 additions & 10 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 23 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,7 +58,6 @@ linters:
- bodyclose
- contextcheck
# - cyclop # This is equivalent to gocyclo
- deadcode
- depguard
- dogsled
- dupl
Expand All @@ -68,7 +84,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
Expand Down Expand Up @@ -104,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
Expand All @@ -115,7 +130,6 @@ linters:
- unconvert
- unparam
- unused
- varcheck
# - varnamelen # It doesn't seem necessary to enforce a minimum variable name length
- wastedassign
- whitespace
Expand Down Expand Up @@ -171,3 +185,8 @@ issues:
- gochecknoinits
- goerr113
- wrapcheck

# Ignore header linting for internal files copied from Kubernetes
- path: internal/(cli|env|log)/.*\.go
linters:
- goheader
34 changes: 0 additions & 34 deletions .licenserc.json

This file was deleted.

4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions cmd/subctl/diagnose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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))
}
}
2 changes: 1 addition & 1 deletion cmd/subctl/gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/env/term_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package env_test

import (
"bytes"
"io/ioutil"
"os"
"testing"

"github.com/submariner-io/subctl/internal/env"
Expand All @@ -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)
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/serviceaccount/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading