chore: bump golangci-lint from 1.45.2 to 1.47.2

Minor linter upgrade.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
This commit is contained in:
Dmitriy Matrenichev 2022-07-18 17:20:40 +03:00
parent 2cce9112d1
commit 30f7851d2a
No known key found for this signature in database
GPG Key ID: D3363CF894E68892
16 changed files with 60 additions and 49 deletions

View File

@ -140,6 +140,7 @@ linters:
enable-all: true
disable:
- errorlint
- exhaustruct
- exhaustivestruct
- forbidigo
- forcetypeassert
@ -156,7 +157,9 @@ linters:
- maintidx
- nestif
- nilnil # we return "nil, nil"
- nonamedreturns
- nolintlint
- nosnakecase
- paralleltest
- promlinter # https://github.com/golangci/golangci-lint/issues/2222
- tagliatelle # we have many different conventions

View File

@ -19,7 +19,7 @@ EXTRAS ?= v1.2.0-alpha.0-1-g17a319f
GO_VERSION ?= 1.18
GOIMPORTS_VERSION ?= v0.1.11
GOFUMPT_VERSION ?= v0.3.0
GOLANGCILINT_VERSION ?= v1.45.2
GOLANGCILINT_VERSION ?= v1.47.2
STRINGER_VERSION ?= v0.1.10
ENUMER_VERSION ?= v1.1.2
DEEPCOPY_GEN_VERSION ?= v0.21.3

View File

@ -40,6 +40,7 @@ import (
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/generate"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/provision"
"github.com/talos-systems/talos/pkg/provision/access"
"github.com/talos-systems/talos/pkg/provision/providers"
@ -495,7 +496,7 @@ func create(ctx context.Context, flags *pflag.FlagSet) (err error) {
bundle.WithInputOptions(
&bundle.InputOptions{
ClusterName: clusterName,
Endpoint: fmt.Sprintf("https://%s:%d", defaultInternalLB, controlPlanePort),
Endpoint: fmt.Sprintf("https://%s", nethelpers.JoinHostPort(defaultInternalLB, controlPlanePort)),
KubeVersion: strings.TrimPrefix(kubernetesVersion, "v"),
GenOptions: genOptions,
}),
@ -737,7 +738,7 @@ func mergeKubeconfig(ctx context.Context, clusterAccess *access.Adapter) error {
if clusterAccess.ForceEndpoint != "" {
for name := range config.Clusters {
config.Clusters[name].Server = fmt.Sprintf("https://%s:%d", clusterAccess.ForceEndpoint, controlPlanePort)
config.Clusters[name].Server = fmt.Sprintf("https://%s", nethelpers.JoinHostPort(clusterAccess.ForceEndpoint, controlPlanePort))
}
}

View File

@ -112,7 +112,7 @@ e.g. by excluding packets with the port 50000.
defer wg.Wait()
if pcapCmdFlags.output == "" {
return dumpPackets(ctx, r)
return dumpPackets(r)
}
var out io.Writer
@ -137,7 +137,7 @@ e.g. by excluding packets with the port 50000.
},
}
func dumpPackets(ctx context.Context, r io.Reader) error {
func dumpPackets(r io.Reader) error {
src, err := pcapgo.NewReader(r)
if err != nil {
return fmt.Errorf("error opening pcap reader: %w", err)

View File

@ -48,16 +48,6 @@ func (suite *HardwareSuite) SetupTest() {
suite.Require().NoError(err)
}
func (suite *HardwareSuite) startRuntime() {
suite.wg.Add(1)
go func() {
defer suite.wg.Done()
suite.Assert().NoError(suite.runtime.Run(suite.ctx))
}()
}
func (suite *HardwareSuite) assertResource(md resource.Metadata, check func(res resource.Resource) error) func() error {
return func() error {
r, err := suite.state.Get(suite.ctx, md)

View File

@ -26,6 +26,7 @@ type DeviceConfigController struct {
devices map[string]networkDevice
}
//nolint:unused
type networkDevice struct {
hardwareAddress string
busPrefix string
@ -103,7 +104,7 @@ func (ctrl *DeviceConfigController) Run(ctx context.Context, r controller.Runtim
if device.Selector() != nil {
device = device.(*v1alpha1.Device).DeepCopy()
err = ctrl.getDeviceBySelector(ctx, device, links.Items)
err = ctrl.getDeviceBySelector(device, links.Items)
if err != nil {
logger.Warn("failed to select an interface for a device", zap.Error(err))
@ -153,7 +154,7 @@ func (ctrl *DeviceConfigController) Run(ctx context.Context, r controller.Runtim
}
}
func (ctrl *DeviceConfigController) getDeviceBySelector(ctx context.Context, device talosconfig.Device, links []resource.Resource) error {
func (ctrl *DeviceConfigController) getDeviceBySelector(device talosconfig.Device, links []resource.Resource) error {
selector := device.Selector()
for _, link := range links {

View File

@ -165,7 +165,7 @@ func (suite *DeviceConfigSpecSuite) TestSelectors() {
return retry.ExpectedError(err)
}
deviceConfig = config.(*network.DeviceConfigSpec) //nolint:errcheck,forcedtypeassert
deviceConfig = config.(*network.DeviceConfigSpec) //nolint:errcheck,forcetypeassert
return nil
},

View File

@ -134,13 +134,7 @@ func (ctrl *HostnameConfigController) Run(ctx context.Context, r controller.Runt
nodeID := identity.(*cluster.Identity).TypedSpec().NodeID
var stableHostname *network.HostnameSpecSpec
stableHostname, err = ctrl.getStableDefault(nodeID)
if err != nil {
return err
}
stableHostname := ctrl.getStableDefault(nodeID)
specs = append(specs, *stableHostname)
} else {
specs = append(specs, ctrl.getDefault(defaultAddr))
@ -205,7 +199,7 @@ func (ctrl *HostnameConfigController) apply(ctx context.Context, r controller.Ru
return ids, nil
}
func (ctrl *HostnameConfigController) getStableDefault(nodeID string) (*network.HostnameSpecSpec, error) {
func (ctrl *HostnameConfigController) getStableDefault(nodeID string) *network.HostnameSpecSpec {
h := sha256.New()
h.Write([]byte(nodeID))
@ -218,7 +212,7 @@ func (ctrl *HostnameConfigController) getStableDefault(nodeID string) (*network.
return &network.HostnameSpecSpec{
Hostname: hostname,
ConfigLayer: network.ConfigDefault,
}, nil
}
}
func (ctrl *HostnameConfigController) getDefault(defaultAddr *network.NodeAddress) (spec network.HostnameSpecSpec) {

View File

@ -45,6 +45,7 @@ import (
machineapi "github.com/talos-systems/talos/pkg/machinery/api/machine"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
etcdresource "github.com/talos-systems/talos/pkg/machinery/resources/etcd"
"github.com/talos-systems/talos/pkg/machinery/resources/k8s"
"github.com/talos-systems/talos/pkg/machinery/resources/network"
@ -444,11 +445,15 @@ func (e *Etcd) argsForInit(ctx context.Context, r runtime.Runtime) error {
}
if !extraArgs.Contains("initial-advertise-peer-urls") {
denyListArgs.Set("initial-advertise-peer-urls", fmt.Sprintf("https://%s:2380", net.FormatAddress(primaryAddr)))
denyListArgs.Set("initial-advertise-peer-urls",
fmt.Sprintf("https://%s", nethelpers.JoinHostPort(net.FormatAddress(primaryAddr), 2380)),
)
}
if !extraArgs.Contains("advertise-client-urls") {
denyListArgs.Set("advertise-client-urls", fmt.Sprintf("https://%s:2379", net.FormatAddress(primaryAddr)))
denyListArgs.Set("advertise-client-urls",
fmt.Sprintf("https://%s", nethelpers.JoinHostPort(net.FormatAddress(primaryAddr), 2379)),
)
}
if err := denyListArgs.Merge(extraArgs, denyList); err != nil {
@ -537,12 +542,16 @@ func (e *Etcd) argsForControlPlane(ctx context.Context, r runtime.Runtime) error
}
if !extraArgs.Contains("initial-advertise-peer-urls") {
denyListArgs.Set("initial-advertise-peer-urls", fmt.Sprintf("https://%s:2380", net.FormatAddress(primaryAddr)))
denyListArgs.Set("initial-advertise-peer-urls",
fmt.Sprintf("https://%s", nethelpers.JoinHostPort(net.FormatAddress(primaryAddr), 2380)),
)
}
}
if !extraArgs.Contains("advertise-client-urls") {
denyListArgs.Set("advertise-client-urls", fmt.Sprintf("https://%s:2379", net.FormatAddress(primaryAddr)))
denyListArgs.Set("advertise-client-urls",
fmt.Sprintf("https://%s", nethelpers.JoinHostPort(net.FormatAddress(primaryAddr), 2379)),
)
}
if err = denyListArgs.Merge(extraArgs, denyList); err != nil {

View File

@ -77,7 +77,7 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() {
newHostname := "test-update-hostname"
err = suite.updateHostname(nodeCtx, nodeInternalIP, newHostname)
err = suite.updateHostname(nodeCtx, newHostname)
suite.Require().NoError(err)
nodeReady := func(status corev1.ConditionStatus) bool {
@ -90,7 +90,7 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() {
defer func() {
// revert the hostname back to the original one
err = suite.updateHostname(nodeCtx, nodeInternalIP, oldHostname)
err = suite.updateHostname(nodeCtx, oldHostname)
suite.Require().NoError(err)
// expect node status to be Ready again
@ -119,7 +119,7 @@ func (suite *UpdateHostnameSuite) TestUpdateHostname() {
suite.Require().NoError(err)
}
func (suite *UpdateHostnameSuite) updateHostname(nodeCtx context.Context, nodeIP string, newHostname string) error {
func (suite *UpdateHostnameSuite) updateHostname(nodeCtx context.Context, newHostname string) error {
nodeConfig, err := suite.ReadConfigFromNode(nodeCtx)
if err != nil {
return err

View File

@ -41,15 +41,7 @@ func (cliSuite *CLISuite) DiscoverNodes(ctx context.Context) cluster.Info {
return discoveredNodes
}
discoveredNodes = cliSuite.discoverKubectl()
if discoveredNodes != nil {
return discoveredNodes
}
// still no nodes, skip the test
cliSuite.T().Skip("no nodes were discovered")
return nil
return cliSuite.discoverKubectl()
}
// DiscoverNodeInternalIPs provides list of Talos node internal IPs in the cluster.

View File

@ -42,6 +42,7 @@ import (
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/generic/slices"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
"github.com/talos-systems/talos/pkg/provision"
"github.com/talos-systems/talos/pkg/provision/access"
"github.com/talos-systems/talos/pkg/provision/providers/qemu"
@ -340,7 +341,7 @@ func (suite *UpgradeSuite) setupCluster() {
}
defaultInternalLB, _ := suite.provisioner.GetLoadBalancers(request.Network)
suite.controlPlaneEndpoint = fmt.Sprintf("https://%s:%d", defaultInternalLB, constants.DefaultControlPlanePort)
suite.controlPlaneEndpoint = fmt.Sprintf("https://%s", nethelpers.JoinHostPort(defaultInternalLB, constants.DefaultControlPlanePort))
genOptions := suite.provisioner.GenOptions(request.Network)

View File

@ -60,9 +60,7 @@ func (b *MenuButton) SetActiveColors(colors ...tcell.Color) {
// 1st value is bg color.
// 2nd value is label color.
func (b *MenuButton) SetInactiveColors(colors ...tcell.Color) {
for i, color := range colors {
b.colors[i] = color
}
copy(b.colors[:], colors)
b.updateColors()
}

View File

@ -20,6 +20,7 @@ import (
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1"
"github.com/talos-systems/talos/pkg/machinery/config/types/v1alpha1/machine"
"github.com/talos-systems/talos/pkg/machinery/constants"
"github.com/talos-systems/talos/pkg/machinery/nethelpers"
)
const canalCustomCNI = "canal"
@ -54,9 +55,9 @@ func NewState(ctx context.Context, installer *Installer, conn *Connection) (*Sta
}
if conn.ExpandingCluster() {
opts.ClusterConfig.ControlPlane.Endpoint = fmt.Sprintf("https://%s:%d", conn.bootstrapEndpoint, constants.DefaultControlPlanePort)
opts.ClusterConfig.ControlPlane.Endpoint = fmt.Sprintf("https://%s", nethelpers.JoinHostPort(conn.bootstrapEndpoint, constants.DefaultControlPlanePort))
} else {
opts.ClusterConfig.ControlPlane.Endpoint = fmt.Sprintf("https://%s:%d", conn.nodeEndpoint, constants.DefaultControlPlanePort)
opts.ClusterConfig.ControlPlane.Endpoint = fmt.Sprintf("https://%s", nethelpers.JoinHostPort(conn.nodeEndpoint, constants.DefaultControlPlanePort))
}
installDiskOptions := []interface{}{

View File

@ -28,6 +28,8 @@ func IsRetryableError(err error) bool {
var netErr net.Error
if errors.As(err, &netErr) {
// https://groups.google.com/g/golang-nuts/c/-JcZzOkyqYI/m/xwaZzjCgAwAJ
//nolint:staticcheck
if netErr.Temporary() || netErr.Timeout() {
return true
}

View File

@ -0,0 +1,19 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package nethelpers
import (
"fmt"
"net"
)
type ints interface {
~int16 | ~int32 | ~int64 | ~uint16 | ~uint32 | ~uint64 | int | uint
}
// JoinHostPort is a wrapper around net.JoinHostPort which accepts port any integer type.
func JoinHostPort[T ints](host string, port T) string {
return net.JoinHostPort(host, fmt.Sprintf("%d", port))
}