mirror of
https://github.com/k3s-io/k3s.git
synced 2026-02-03 20:39:49 -05:00
lint: unnecessary-format,use-errors-new
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
003fd4471c
commit
fc506e56dd
23 changed files with 46 additions and 45 deletions
|
|
@ -242,7 +242,7 @@ func createFlannelConf(nodeConfig *config.Node) error {
|
|||
routes = append(routes, "$IPV6SUBNET")
|
||||
}
|
||||
if len(routes) == 0 {
|
||||
return fmt.Errorf("incorrect netMode for flannel tailscale backend")
|
||||
return errors.New("incorrect netMode for flannel tailscale backend")
|
||||
}
|
||||
advertisedRoutes, err := vpn.GetAdvertisedRoutes()
|
||||
if err == nil && advertisedRoutes != nil {
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ func Test_createFlannelConf(t *testing.T) {
|
|||
}
|
||||
data, err := os.ReadFile("test_file")
|
||||
if err != nil {
|
||||
t.Errorf("Something went wrong when reading the flannel config file")
|
||||
t.Error("Something went wrong when reading the flannel config file")
|
||||
}
|
||||
for _, config := range tt.wantConfig {
|
||||
isExist, _ := regexp.Match(config, data)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ func (s *testServer) echo(conn net.Conn) {
|
|||
}
|
||||
|
||||
func ping(conn net.Conn) (string, error) {
|
||||
fmt.Fprintf(conn, "ping\n")
|
||||
fmt.Fprint(conn, "ping\n")
|
||||
result, err := bufio.NewReader(conn).ReadString('\n')
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func run(ctx context.Context, cfg cmds.Agent, proxy proxy.Proxy) error {
|
|||
|
||||
// dualStack or IPv6 are not supported on Windows node
|
||||
if (goruntime.GOOS == "windows") && enableIPv6 {
|
||||
return fmt.Errorf("dual-stack or IPv6 are not supported on Windows node")
|
||||
return errors.New("dual-stack or IPv6 are not supported on Windows node")
|
||||
}
|
||||
|
||||
conntrackConfig, err := getConntrackConfig(nodeConfig)
|
||||
|
|
|
|||
|
|
@ -134,13 +134,13 @@ password2,user2,uid2
|
|||
password3,user3
|
||||
password4
|
||||
`); err == nil {
|
||||
t.Fatalf("unexpected non error")
|
||||
t.Fatal("unexpected non error")
|
||||
}
|
||||
}
|
||||
|
||||
func Test_UnitInsufficientColumnsPasswordFile(t *testing.T) {
|
||||
if _, err := newWithContents(t, "password4\n"); err == nil {
|
||||
t.Fatalf("unexpected non error")
|
||||
t.Fatal("unexpected non error")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package agent
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
|
|
@ -82,11 +82,11 @@ func Run(clx *cli.Context) (rerr error) {
|
|||
_, err := tls.LoadX509KeyPair(clientKubeletCert, clientKubeletKey)
|
||||
|
||||
if err != nil && cmds.AgentConfig.Token == "" {
|
||||
return fmt.Errorf("--token is required")
|
||||
return errors.New("--token is required")
|
||||
}
|
||||
|
||||
if cmds.AgentConfig.ServerURL == "" {
|
||||
return fmt.Errorf("--server is required")
|
||||
return errors.New("--server is required")
|
||||
}
|
||||
|
||||
if cmds.AgentConfig.FlannelIface != "" && len(cmds.AgentConfig.NodeIP.Value()) == 0 {
|
||||
|
|
|
|||
|
|
@ -133,8 +133,8 @@ func (f *TableFormatter) Format(certInfo *CertificateInfo) error {
|
|||
now := certInfo.ReferenceTime
|
||||
defer w.Flush()
|
||||
|
||||
fmt.Fprintf(w, "\nFILENAME\tSUBJECT\tUSAGES\tEXPIRES\tRESIDUAL TIME\tSTATUS\n")
|
||||
fmt.Fprintf(w, "--------\t-------\t------\t-------\t-------------\t------\n")
|
||||
fmt.Fprint(w, "\nFILENAME\tSUBJECT\tUSAGES\tEXPIRES\tRESIDUAL TIME\tSTATUS\n")
|
||||
fmt.Fprint(w, "--------\t-------\t------\t-------\t-------------\t------\n")
|
||||
|
||||
for _, cert := range certInfo.Certificates {
|
||||
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\t%s\n",
|
||||
|
|
|
|||
|
|
@ -132,9 +132,9 @@ func Status(app *cli.Context) error {
|
|||
|
||||
var tabBuffer bytes.Buffer
|
||||
w := tabwriter.NewWriter(&tabBuffer, 0, 0, 2, ' ', 0)
|
||||
fmt.Fprintf(w, "\n")
|
||||
fmt.Fprintf(w, "Active\tKey Type\tName\n")
|
||||
fmt.Fprintf(w, "------\t--------\t----\n")
|
||||
fmt.Fprint(w, "\n")
|
||||
fmt.Fprint(w, "Active\tKey Type\tName\n")
|
||||
fmt.Fprint(w, "------\t--------\t----\n")
|
||||
if status.ActiveKey != "" {
|
||||
ak := strings.Split(status.ActiveKey, " ")
|
||||
fmt.Fprintf(w, " *\t%s\t%s\n", ak[0], ak[1])
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package cloudprovider
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
|
||||
"github.com/k3s-io/k3s/pkg/util"
|
||||
|
|
@ -74,7 +74,7 @@ func init() {
|
|||
}
|
||||
|
||||
if !k.LBEnabled && !k.NodeEnabled {
|
||||
return nil, fmt.Errorf("all cloud-provider functionality disabled by config")
|
||||
return nil, errors.New("all cloud-provider functionality disabled by config")
|
||||
}
|
||||
|
||||
return &k, err
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package cloudprovider
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
|
@ -734,11 +735,11 @@ func validateToleration(toleration *core.Toleration) error {
|
|||
}
|
||||
|
||||
if toleration.Key == "" && toleration.Operator != core.TolerationOpExists {
|
||||
return fmt.Errorf("toleration with empty key must have operator 'Exists'")
|
||||
return errors.New("toleration with empty key must have operator 'Exists'")
|
||||
}
|
||||
|
||||
if toleration.Operator == core.TolerationOpExists && toleration.Value != "" {
|
||||
return fmt.Errorf("toleration with operator 'Exists' must have an empty value")
|
||||
return errors.New("toleration with operator 'Exists' must have an empty value")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"crypto/rand"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ func encrypt(passphrase string, plaintext []byte) ([]byte, error) {
|
|||
func decrypt(passphrase string, ciphertext []byte) ([]byte, error) {
|
||||
parts := strings.SplitN(string(ciphertext), ":", 2)
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("invalid cipher text, not : delimited")
|
||||
return nil, errors.New("invalid cipher text, not : delimited")
|
||||
}
|
||||
|
||||
clearKey := pbkdf2.Key([]byte(passphrase), []byte(parts[0]), 4096, 32, sha1.New)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
|
|
@ -105,7 +104,7 @@ func (c *Cluster) initClusterAndHTTPS(ctx context.Context) error {
|
|||
if c.config.Runtime.Handler != nil {
|
||||
c.config.Runtime.Handler.ServeHTTP(rw, req)
|
||||
} else {
|
||||
util.SendError(fmt.Errorf("starting"), rw, req, http.StatusServiceUnavailable)
|
||||
util.SendError(errors.New("starting"), rw, req, http.StatusServiceUnavailable)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -758,7 +758,7 @@ func (e *ETCD) handler(next http.Handler) http.Handler {
|
|||
func (e *ETCD) infoHandler() http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodGet {
|
||||
util.SendError(fmt.Errorf("method not allowed"), rw, req, http.StatusMethodNotAllowed)
|
||||
util.SendError(errors.New("method not allowed"), rw, req, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ func (c *Controller) GetClient(ctx context.Context, etcdS3 *config.EtcdS3) (*Cli
|
|||
return nil, pkgerrors.WithMessage(err, "failed to parse etcd-s3-proxy value as URL")
|
||||
}
|
||||
if u.Scheme == "" || u.Host == "" {
|
||||
return nil, fmt.Errorf("proxy URL must include scheme and host")
|
||||
return nil, errors.New("proxy URL must include scheme and host")
|
||||
}
|
||||
}
|
||||
tr.Proxy = http.ProxyURL(u)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package etcd
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ func (e *ETCD) handleDelete(rw http.ResponseWriter, req *http.Request, snapshots
|
|||
}
|
||||
|
||||
func (e *ETCD) handleInvalid(rw http.ResponseWriter, req *http.Request) error {
|
||||
util.SendErrorWithID(fmt.Errorf("invalid snapshot operation"), "etcd-snapshot", rw, req, http.StatusBadRequest)
|
||||
util.SendErrorWithID(errors.New("invalid snapshot operation"), "etcd-snapshot", rw, req, http.StatusBadRequest)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ func Test_UnitAsserts(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_PasswordError(t *testing.T) {
|
||||
err := &passwordError{node: "test", err: fmt.Errorf("inner error")}
|
||||
err := &passwordError{node: "test", err: errors.New("inner error")}
|
||||
assertEqual(t, errors.Is(err, ErrVerifyFailed), true)
|
||||
assertEqual(t, errors.Is(err, fmt.Errorf("different error")), false)
|
||||
assertEqual(t, errors.Is(err, errors.New("different error")), false)
|
||||
assertNotEqual(t, errors.Unwrap(err), nil)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
|
@ -92,7 +93,7 @@ func GetEncryptionKeys(runtime *config.ControlRuntime) (*EncryptionKeys, error)
|
|||
currentKeys.SBKeys = append(currentKeys.SBKeys, p.Secretbox.Keys...)
|
||||
}
|
||||
if p.AESGCM != nil || p.KMS != nil {
|
||||
return nil, fmt.Errorf("unsupported encryption keys found")
|
||||
return nil, errors.New("unsupported encryption keys found")
|
||||
}
|
||||
}
|
||||
return currentKeys, nil
|
||||
|
|
@ -333,7 +334,7 @@ func GetEncryptionConfigMetrics(runtime *config.ControlRuntime, initialMetrics b
|
|||
|
||||
unixUpdateTime = int64(tsMetric.GetMetric()[0].GetGauge().GetValue())
|
||||
if time.Now().Unix() < unixUpdateTime {
|
||||
return true, fmt.Errorf("encryption reload time is incorrectly ahead of current time")
|
||||
return true, errors.New("encryption reload time is incorrectly ahead of current time")
|
||||
}
|
||||
|
||||
for _, totalMetric := range totalMetrics.GetMetric() {
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ import (
|
|||
func CACertReplace(control *config.Control) http.HandlerFunc {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPut {
|
||||
util.SendError(fmt.Errorf("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
util.SendError(errors.New("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
force, _ := strconv.ParseBool(req.FormValue("force"))
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ func encryptionEnable(ctx context.Context, control *config.Control, enable bool)
|
|||
logrus.Infoln("Secrets encryption already enabled")
|
||||
return nil
|
||||
} else {
|
||||
return fmt.Errorf("unable to enable/disable secrets encryption, unknown configuration")
|
||||
return errors.New("unable to enable/disable secrets encryption, unknown configuration")
|
||||
}
|
||||
if err := cluster.Save(ctx, control, true); err != nil {
|
||||
return err
|
||||
|
|
@ -188,7 +188,7 @@ func encryptionEnable(ctx context.Context, control *config.Control, enable bool)
|
|||
func EncryptionConfig(ctx context.Context, control *config.Control) http.Handler {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPut {
|
||||
util.SendError(fmt.Errorf("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
util.SendError(errors.New("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +237,7 @@ func encryptionPrepare(ctx context.Context, control *config.Control, force bool)
|
|||
return err
|
||||
}
|
||||
if control.EncryptProvider == secretsencrypt.SecretBoxProvider {
|
||||
return fmt.Errorf("prepare does not support secretbox key type, use rotate-keys instead")
|
||||
return errors.New("prepare does not support secretbox key type, use rotate-keys instead")
|
||||
}
|
||||
|
||||
curKeys, err := secretsencrypt.GetEncryptionKeys(control.Runtime)
|
||||
|
|
@ -265,7 +265,7 @@ func encryptionRotate(ctx context.Context, control *config.Control, force bool)
|
|||
return err
|
||||
}
|
||||
if control.EncryptProvider == secretsencrypt.SecretBoxProvider {
|
||||
return fmt.Errorf("rotate does not support secretbox key type, use rotate-keys instead")
|
||||
return errors.New("rotate does not support secretbox key type, use rotate-keys instead")
|
||||
}
|
||||
|
||||
curKeys, err := secretsencrypt.GetEncryptionKeys(control.Runtime)
|
||||
|
|
@ -301,7 +301,7 @@ func encryptionReencrypt(ctx context.Context, control *config.Control, force boo
|
|||
return err
|
||||
}
|
||||
if control.EncryptProvider == secretsencrypt.SecretBoxProvider {
|
||||
return fmt.Errorf("reencrypt does not support secretbox key type, use rotate-keys instead")
|
||||
return errors.New("reencrypt does not support secretbox key type, use rotate-keys instead")
|
||||
}
|
||||
|
||||
// Set the reencrypt-active annotation so other nodes know we are in the process of reencrypting.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package handlers
|
|||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -35,7 +35,7 @@ func getServerTokenRequest(req *http.Request) (TokenRotateRequest, error) {
|
|||
func TokenRequest(ctx context.Context, control *config.Control) http.Handler {
|
||||
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != http.MethodPut {
|
||||
util.SendError(fmt.Errorf("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
util.SendError(errors.New("method not allowed"), resp, req, http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
var err error
|
||||
|
|
@ -73,7 +73,7 @@ func tokenRotate(ctx context.Context, control *config.Control, newToken string)
|
|||
|
||||
oldToken, found := passwd.Pass("server")
|
||||
if !found {
|
||||
return fmt.Errorf("server token not found")
|
||||
return errors.New("server token not found")
|
||||
}
|
||||
if newToken == "" {
|
||||
newToken, err = util.Random(16)
|
||||
|
|
|
|||
|
|
@ -396,9 +396,9 @@ func (ml *multiListener) Accept() (net.Conn, error) {
|
|||
if ok {
|
||||
return res.conn, res.err
|
||||
}
|
||||
return nil, fmt.Errorf("connection channel closed")
|
||||
return nil, errors.New("connection channel closed")
|
||||
case <-ml.closing:
|
||||
return nil, fmt.Errorf("listener closed")
|
||||
return nil, errors.New("listener closed")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
package permissions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ import (
|
|||
// Ref: https://github.com/kubernetes/kubernetes/pull/96616
|
||||
func IsPrivileged() error {
|
||||
if os.Getuid() != 0 {
|
||||
return fmt.Errorf("not running as root")
|
||||
return errors.New("not running as root")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
package permissions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
|
||||
pkgerrors "github.com/pkg/errors"
|
||||
"golang.org/x/sys/windows"
|
||||
|
|
@ -39,7 +39,7 @@ func IsPrivileged() error {
|
|||
}
|
||||
|
||||
if !member {
|
||||
return fmt.Errorf("not running as member of BUILTIN\\Administrators group")
|
||||
return errors.New("not running as member of BUILTIN\\Administrators group")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue