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

ci: update golangci-lint to 1.47.0 #4830

Merged
merged 13 commits into from
Aug 20, 2022
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
7 changes: 3 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ linters-settings:
- default
- prefix(github.com/kumahq/kuma-net)
- prefix(github.com/kumahq/kuma)
# This doesn't take effect until 1.48.0
custom-order: true
importas:
alias:
- pkg: github.com/kumahq/kuma/pkg/core/resources/apis/mesh
Expand Down Expand Up @@ -69,10 +71,7 @@ issues:
exclude-rules:
- linters:
- staticcheck
text: "SA1019: package github.com/golang/protobuf/proto is deprecated" # TODO ignore deprecation of proto library. We don't want to migrate yet because go-control-plane is not ready
- linters:
- staticcheck
text: "SA1019: package github.com/golang/protobuf/jsonpb" # TODO ignore deprecation of proto library. We don't want to migrate yet because go-control-plane is not ready
slonka marked this conversation as resolved.
Show resolved Hide resolved
text: 'SA1019: "github.com/golang/protobuf' # TODO ignore deprecation of proto library. We don't want to migrate yet because go-control-plane is not ready
- linters:
- staticcheck
text: "SA1019: proto.MessageName is deprecated" # TODO ignore deprecation of proto library. We don't want to migrate yet because go-control-plane is not ready
Expand Down
4 changes: 2 additions & 2 deletions app/cni/pkg/cni/injector_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/go-logr/logr"
"github.com/pkg/errors"

"github.com/kumahq/kuma/pkg/transparentproxy"

kumanet_tproxy "github.com/kumahq/kuma-net/transparent-proxy"
kumanet_config "github.com/kumahq/kuma-net/transparent-proxy/config"

"github.com/kumahq/kuma/pkg/transparentproxy"
)

func convertToUint16(field string, value string) (uint16, error) {
Expand Down
8 changes: 4 additions & 4 deletions app/cni/pkg/install/installer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package install

import (
"encoding/base64"
"io/ioutil"
"net"
"net/url"
"os"
"path/filepath"
"strings"

Expand Down Expand Up @@ -74,7 +74,7 @@ func findCniConfFile(mountedCNINetDir string) (string, error) {
func prepareKubeconfig(ic *InstallerConfig, serviceAccountPath string) error {
kubeconfigPath := ic.MountedCniNetDir + "/" + ic.KubeconfigName
serviceAccountTokenPath := serviceAccountPath + "/token"
serviceAccountToken, err := ioutil.ReadFile(serviceAccountTokenPath)
serviceAccountToken, err := os.ReadFile(serviceAccountTokenPath)
if err != nil {
return err
}
Expand All @@ -91,7 +91,7 @@ func prepareKubeconfig(ic *InstallerConfig, serviceAccountPath string) error {
ic.KubernetesCaFile = serviceAccountPath + "/ca.crt"
}

kubeCa, err := ioutil.ReadFile(ic.KubernetesCaFile)
kubeCa, err := os.ReadFile(ic.KubernetesCaFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func prepareKumaCniConfig(ic *InstallerConfig, serviceAccountPath string) error
cniConfig := strings.Replace(rawConfig, "__KUBECONFIG_FILEPATH__", kubeconfigFilePath, 1)
log.V(1).Info("cni config after replace", "cni config", cniConfig)

serviceAccountToken, err := ioutil.ReadFile(serviceAccountPath + "/token")
serviceAccountToken, err := os.ReadFile(serviceAccountPath + "/token")
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions app/cni/pkg/install/installer_config_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package install

import (
"io/ioutil"
"os"
"path"

. "github.com/onsi/ginkgo/v2"
Expand Down Expand Up @@ -63,7 +63,7 @@ var _ = Describe("prepareKubeconfig", func() {
// then
Expect(err).To(Not(HaveOccurred()))
// and
kubeconfig, _ := ioutil.ReadFile(path.Join("testdata", "prepare-kubeconfig", "ZZZ-kuma-cni-kubeconfig"))
kubeconfig, _ := os.ReadFile(path.Join("testdata", "prepare-kubeconfig", "ZZZ-kuma-cni-kubeconfig"))
Expect(kubeconfig).To(matchers.MatchGoldenYAML(path.Join("testdata", "prepare-kubeconfig", "ZZZ-kuma-cni-kubeconfig.golden")))
})
})
Expand All @@ -86,7 +86,7 @@ var _ = Describe("prepareKumaCniConfig", func() {
// then
Expect(err).To(Not(HaveOccurred()))
// and
kubeconfig, _ := ioutil.ReadFile(path.Join("testdata", "prepare-chained-kuma-config", "10-calico.conflist"))
kubeconfig, _ := os.ReadFile(path.Join("testdata", "prepare-chained-kuma-config", "10-calico.conflist"))
Expect(kubeconfig).To(matchers.MatchGoldenJSON(path.Join("testdata", "prepare-chained-kuma-config", "10-calico.conflist.golden")))
})

Expand All @@ -107,7 +107,7 @@ var _ = Describe("prepareKumaCniConfig", func() {
// then
Expect(err).To(Not(HaveOccurred()))
// and
kubeconfig, _ := ioutil.ReadFile(path.Join("testdata", "prepare-standalone-kuma-config", "kuma-cni.conf"))
kubeconfig, _ := os.ReadFile(path.Join("testdata", "prepare-standalone-kuma-config", "kuma-cni.conf"))
Expect(kubeconfig).To(matchers.MatchGoldenJSON(path.Join("testdata", "prepare-standalone-kuma-config", "kuma-cni.conf.golden")))
})
})
5 changes: 2 additions & 3 deletions app/cni/pkg/install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package install

import (
"bytes"
"io/ioutil"
"os"
"os/signal"
"path"
Expand Down Expand Up @@ -81,7 +80,7 @@ func revertConfig(mountedCniNetDir, cniConfName string, chainedCniPlugin bool) e
}

if chainedCniPlugin {
contents, err := ioutil.ReadFile(configPath)
contents, err := os.ReadFile(configPath)
if err != nil {
return errors.Wrap(err, "couldn't read cni conf file")
}
Expand Down Expand Up @@ -131,7 +130,7 @@ func setupChainedPlugin(mountedCniNetDir, cniConfName, kumaCniConfig string) err
return errors.Errorf("CNI config %v not found. Kuma CNI won't be chained", cniConfPath)
}

hostCniConfig, err := ioutil.ReadFile(cniConfPath)
hostCniConfig, err := os.ReadFile(cniConfPath)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions app/cni/pkg/install/transform_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package install

import (
"io/ioutil"
"os"
"path"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -13,7 +13,7 @@ import (
var _ = Describe("testTransformJsonConfig", func() {
It("should properly manipulate CNI conflist file", func() {
// given
calicoConfig, _ := ioutil.ReadFile(path.Join("testdata", "10-calico.conflist"))
calicoConfig, _ := os.ReadFile(path.Join("testdata", "10-calico.conflist"))
expectedConfig := path.Join("testdata", "10-calico-cni-injected.conflist")

// when
Expand All @@ -26,7 +26,7 @@ var _ = Describe("testTransformJsonConfig", func() {

It("should properly manipulate CNI conf file", func() {
// given
calicoConfig, _ := ioutil.ReadFile(path.Join("testdata", "10-flannel.conf"))
calicoConfig, _ := os.ReadFile(path.Join("testdata", "10-flannel.conf"))
expectedConfig := path.Join("testdata", "10-flannel-cni-injected.conf")

// when
Expand All @@ -40,7 +40,7 @@ var _ = Describe("testTransformJsonConfig", func() {
var _ = Describe("revertConfig", func() {
It("should properly revert CNI conflist", func() {
// given
changedConfig, _ := ioutil.ReadFile(path.Join("testdata", "10-calico-cni-injected.conflist"))
changedConfig, _ := os.ReadFile(path.Join("testdata", "10-calico-cni-injected.conflist"))
originalConfig := path.Join("testdata", "10-calico.conflist")

// when
Expand All @@ -53,7 +53,7 @@ var _ = Describe("revertConfig", func() {

It("should properly revert CNI conf", func() {
// given
changedConfig, _ := ioutil.ReadFile(path.Join("testdata", "10-flannel-cni-injected.conf"))
changedConfig, _ := os.ReadFile(path.Join("testdata", "10-flannel-cni-injected.conf"))
originalConfig := path.Join("testdata", "10-flannel-clean.conf")

// when
Expand Down
3 changes: 1 addition & 2 deletions app/cni/pkg/install/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package install

import (
"encoding/json"
"io/ioutil"
"os"

"github.com/go-logr/logr"
Expand All @@ -12,7 +11,7 @@ import (
)

func parseFileToHashMap(file string) (map[string]interface{}, error) {
contents, err := ioutil.ReadFile(file)
contents, err := os.ReadFile(file)
if err != nil {
return nil, err
}
Expand Down
9 changes: 3 additions & 6 deletions app/kuma-dp/pkg/dataplane/envoy/remote_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (b *remoteBootstrap) Generate(ctx context.Context, url string, cfg kuma_dp.
return envoyBootstrap, &bootstrap.KumaSidecarConfiguration, nil
}

func (b *remoteBootstrap) resourceMetadata(cfg kuma_dp.DataplaneResources) (types.ProxyResources, error) {
func (b *remoteBootstrap) resourceMetadata(cfg kuma_dp.DataplaneResources) types.ProxyResources {
var maxMemory uint64

if cfg.MaxMemoryBytes == 0 {
Expand All @@ -124,7 +124,7 @@ func (b *remoteBootstrap) resourceMetadata(cfg kuma_dp.DataplaneResources) (type
res.MaxHeapSizeBytes = maxMemory
}

return res, nil
return res
}

func (b *remoteBootstrap) requestForBootstrap(ctx context.Context, url *net_url.URL, cfg kuma_dp.Config, params BootstrapParams) ([]byte, error) {
Expand All @@ -149,10 +149,7 @@ func (b *remoteBootstrap) requestForBootstrap(ctx context.Context, url *net_url.
token = cfg.DataplaneRuntime.Token
}

resources, err := b.resourceMetadata(cfg.DataplaneRuntime.Resources)
if err != nil {
return nil, err
}
resources := b.resourceMetadata(cfg.DataplaneRuntime.Resources)

request := types.BootstrapRequest{
Mesh: cfg.Dataplane.Mesh,
Expand Down
7 changes: 6 additions & 1 deletion app/kuma-dp/pkg/dataplane/metrics/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,19 @@ func (s *Hijacker) getStats(ctx context.Context, initReq *http.Request, app Appl
var resp *http.Response
if app.IsIPv6 {
resp, err = s.upstreamOverrideHttpClientIPv6.Do(req)
if err == nil {
defer resp.Body.Close()
}
} else {
resp, err = s.upstreamOverrideHttpClientIPv4.Do(req)
if err == nil {
defer resp.Body.Close()
}
}
if err != nil {
logger.Error(err, "failed call", "name", app.Name, "path", app.Path, "port", app.Port)
return nil
}
defer resp.Body.Close()

var bodyBytes []byte
if app.Mutator != nil {
Expand Down
7 changes: 4 additions & 3 deletions app/kumactl/cmd/install/install_control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ package install

import (
"fmt"
"io/ioutil"
"io"
"os"
"strings"

"github.com/ghodss/yaml"
Expand Down Expand Up @@ -81,9 +82,9 @@ This command requires that the KUBECONFIG environment is set`,

var bytes []byte
if strings.TrimSpace(filePath) == "-" {
bytes, err = ioutil.ReadAll(cmd.InOrStdin())
bytes, err = io.ReadAll(cmd.InOrStdin())
} else {
bytes, err = ioutil.ReadFile(filePath)
bytes, err = os.ReadFile(filePath)
}
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions app/kumactl/cmd/install/install_control_plane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package install_test

import (
"bytes"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
Expand Down Expand Up @@ -79,7 +79,7 @@ var _ = Describe("kumactl install control-plane", func() {
}, func() []TableEntry {
var res []TableEntry
testDir := filepath.Join("testdata", "install-cp-helm")
files, err := ioutil.ReadDir(testDir)
files, err := os.ReadDir(testDir)
Expect(err).ToNot(HaveOccurred())
for _, f := range files {
if !f.IsDir() && strings.HasSuffix(f.Name(), ".values.yaml") {
Expand Down
4 changes: 2 additions & 2 deletions app/kumactl/cmd/install/install_transparent_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/kumahq/kuma-net/firewalld"

"github.com/kumahq/kuma/pkg/transparentproxy"
"github.com/kumahq/kuma/pkg/transparentproxy/config"

"github.com/kumahq/kuma-net/firewalld"
)

type transparentProxyArgs struct {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ require (
golang.org/x/net v0.0.0-20220520000938-2e3eb7b945c2
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
golang.org/x/text v0.3.7
golang.org/x/time v0.0.0-20220224211638-0e9765cccd65
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd
google.golang.org/grpc v1.48.0
Expand Down Expand Up @@ -186,7 +187,6 @@ require (
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.10 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion mk/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ ifeq (,$(wildcard $(BUILD_ARTIFACTS_DIR)/coredns/coredns))
$(GO_BUILD_COREDNS) -ldflags="-s -w -X github.com/coredns/coredns/coremain.GitCommit=$(shell git describe --dirty --always)" -o $(BUILD_ARTIFACTS_DIR)/coredns/coredns
rm -rf "$(COREDNS_TMP_DIRECTORY)"
else
echo "CoreDNS is already built. If you want to rebuild it, remove the binary: rm $(BUILD_ARTIFACTS_DIR)/coredns/coredns"
@echo "CoreDNS is already built. If you want to rebuild it, remove the binary: rm $(BUILD_ARTIFACTS_DIR)/coredns/coredns"
endif

.PHONY: build/kuma-prometheus-sd
Expand Down
2 changes: 1 addition & 1 deletion mk/dev.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
KUMA_DIR ?= .
ENVOY_VERSION = $(shell ${KUMA_DIR}/tools/envoy/version.sh)
GINKGO_VERSION := v2.1.3
GOLANGCI_LINT_VERSION := v1.45.2
GOLANGCI_LINT_VERSION := v1.47.0
GOLANG_PROTOBUF_VERSION := v1.5.2
HELM_DOCS_VERSION := 1.7.0
KUSTOMIZE_VERSION := v4.4.1
Expand Down
13 changes: 6 additions & 7 deletions pkg/api-server/api_server_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ func (r *resourceApiClient) list() *http.Response {
return response
}

func (r *resourceApiClient) listOrError() (*http.Response, error) {
return http.Get(r.fullAddress())
}

func (r *resourceApiClient) delete(name string) *http.Response {
request, err := http.NewRequest(
"DELETE",
Expand Down Expand Up @@ -109,7 +105,6 @@ func putSampleResourceIntoStore(resourceStore store.ResourceStore, name string,
}

type testApiServerConfigurer struct {
stop func()
store store.ResourceStore
enableGui bool
config *config_api_server.ApiServerConfig
Expand Down Expand Up @@ -264,10 +259,14 @@ func tryStartApiServer(t *testApiServerConfigurer) (*api_server.ApiServer, kuma_
select {
case err = <-errChan:
return nil, cfg, stop, err
case _ = <-tick.C:
case <-tick.C:
leftTicks--
r, err := http.Get("http://" + apiServer.Address() + "/config")
if err == nil && r.StatusCode == http.StatusOK {
if err != nil {
return nil, cfg, stop, err
}
r.Body.Close()
if r.StatusCode == http.StatusOK {
return apiServer, cfg, stop, nil
}
}
Expand Down
Loading