Skip to content

Commit

Permalink
fix: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
chideat committed Jan 8, 2024
1 parent 3e9b715 commit 8ba3eee
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 110 deletions.
33 changes: 26 additions & 7 deletions .github/workflows/dev.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
name: dev

on: [pull_request]
on:
push:
branch: [ "main" ]
pull_request:

jobs:
test:
name: Test with Coverage
check:
name: Golang Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
args: --timeout=15m --tests=false --exclude-use-default
unit-test:
name: Unit Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Check out code
uses: actions/checkout@v2
go-version-file: go.mod
cache: false
- name: Install dependencies
run: |
go mod download
Expand Down
5 changes: 2 additions & 3 deletions cmd/redis-tools/pkg/commands/backup/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package backup
import (
"context"
"fmt"
"io/ioutil"
"log"
"net/url"
"os"
Expand Down Expand Up @@ -60,7 +59,7 @@ func PushFile2S3(ctx context.Context, c *cli.Context, client *kubernetes.Clients
logger.Error(err, "S3 client init failed")
return err
}
files, err := ioutil.ReadDir(dataDir)
files, err := os.ReadDir(dataDir)
if err != nil {
logger.Error(err, "Read data dir failed")
return err
Expand Down Expand Up @@ -91,7 +90,7 @@ func PushFile2S3(ctx context.Context, c *cli.Context, client *kubernetes.Clients

func ReadFileToString(filename string) string {
filename = path.Join("/s3_secret", filename)
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
log.Println(err)
return ""
Expand Down
3 changes: 1 addition & 2 deletions cmd/redis-tools/pkg/commands/backup/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
"path"
Expand All @@ -49,7 +48,7 @@ func RenameCluster(ctx context.Context, c *cli.Context, client *kubernetes.Clien
dataDir := c.String("data-dir")
filePath := path.Join(dataDir, "nodes.json")

buff, err := ioutil.ReadFile(filePath)
buff, err := os.ReadFile(filePath)
if err != nil {
logger.Error(err, "read nodes.json err")
return err
Expand Down
3 changes: 1 addition & 2 deletions cmd/redis-tools/pkg/commands/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"strings"
Expand Down Expand Up @@ -163,7 +162,7 @@ func ExtractMyselfSlots(data string) string {
}

func FileToString(filename string) (string, error) {
content, err := ioutil.ReadFile(filename)
content, err := os.ReadFile(filename)
if err != nil {
return "", err
}
Expand Down
19 changes: 0 additions & 19 deletions cmd/redis-tools/pkg/commands/cluster/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,25 +169,6 @@ func NewCommand(ctx context.Context) *cli.Command {
},
},
Action: func(c *cli.Context) error {
var (
namespace = c.String("namespace")
podName = c.String("pod-name")
workspace = c.String("workspace")
nodeConfigName = c.String("node-config-name")
)
if namespace == "" {
return cli.Exit("require namespace", 1)
}
if podName == "" {
return cli.Exit("require podname", 1)
}
if workspace == "" {
workspace = "/data"
}
if nodeConfigName == "" {
nodeConfigName = "nodes.conf"
}

logger := logger.NewLogger(c).WithName("Heal")

client, err := client.NewClient()
Expand Down
6 changes: 4 additions & 2 deletions cmd/redis-tools/pkg/commands/cluster/heal.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ type FailoverAction string

const (
NoFailoverAction FailoverAction = ""
ForceFailoverAction = "FORCE"
TakeoverFailoverAction = "TAKEOVER"
ForceFailoverAction FailoverAction = "FORCE"
TakeoverFailoverAction FailoverAction = "TAKEOVER"
)

func doRedisFailover(ctx context.Context, cli redis.Client, action FailoverAction, logger logr.Logger) (err error) {
Expand Down Expand Up @@ -376,6 +376,7 @@ func getClusterNodes(c *cli.Context, ctx context.Context, client *kubernetes.Cli
return nodes, nil
}

/*
func getBindableAddresses(logger logr.Logger) []string {
var bindAddrs []string
// generate ip list for startup
Expand Down Expand Up @@ -420,3 +421,4 @@ func getBindableAddresses(logger logr.Logger) []string {
}
return bindAddrs
}
*/
24 changes: 0 additions & 24 deletions cmd/redis-tools/pkg/commands/cluster/shutdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"math/rand"
"net"
"net/netip"
"strconv"
"strings"
"time"

"github.com/alauda/redis-operator/cmd/redis-tools/pkg/redis"
Expand All @@ -35,10 +33,6 @@ import (
"k8s.io/client-go/kubernetes"
)

func init() {
rand.Seed(time.Now().UnixNano())
}

// Shutdown 在退出时做 failover
//
// NOTE: 在4.0, 5.0中,在更新密码时,会重启实例。但是由于密码在重启前已经热更新,导致其他脚本无法连接到实例,包括shutdown脚本
Expand Down Expand Up @@ -177,24 +171,6 @@ func Shutdown(ctx context.Context, c *cli.Context, client *kubernetes.Clientset,
return nil
}

// parseStatefulsetIndex parse index of statefulset from pod name
// eg:
//
// drc-test-0-0 -> 0
// drc-abc-dddd-ee11-2-1 -> 2
func parseStatefulsetIndex(name string) int {
if idx := strings.LastIndex(name, "-"); idx > 0 {
if idx2 := strings.LastIndex(name[:idx], "-"); idx2 > 0 {
if val, err := strconv.Atoi(name[idx2+1 : idx]); err != nil {
return -1
} else {
return val
}
}
}
return -1
}

func getContainerByName(containers []v1.Container, name string) *v1.Container {
for _, container := range containers {
if container.Name == name {
Expand Down
42 changes: 0 additions & 42 deletions cmd/redis-tools/pkg/commands/cluster/shutdown_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/redis-tools/pkg/commands/helper/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func NewCommand(ctx context.Context) *cli.Command {
logger.Error(err, "load acl failed")
return cli.Exit(err, 1)
}
fmt.Fprintf(os.Stdout, pwd)
fmt.Fprint(os.Stdout, pwd)
return nil
},
},
Expand Down
10 changes: 7 additions & 3 deletions cmd/redis-tools/pkg/commands/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func getRedisNodeInfo(redisClient redis.Client, logger logr.Logger) (*redis.Node
return nodes.Self(), nodes, nil
}

/*
func redisFailover(redisClient redis.Client, logger logr.Logger) error {
self, _, err := getRedisNodeInfo(redisClient, logger)
if err != nil {
Expand Down Expand Up @@ -72,13 +73,14 @@ func redisFailover(redisClient redis.Client, logger logr.Logger) error {
}
}
}
*/

type FailoverAction string

const (
NoFailoverAction FailoverAction = ""
ForceFailoverAction = "FORCE"
TakeoverFailoverAction = "TAKEOVER"
ForceFailoverAction FailoverAction = "FORCE"
TakeoverFailoverAction FailoverAction = "TAKEOVER"
)

func doRedisFailover(ctx context.Context, cli redis.Client, action FailoverAction, logger logr.Logger) (err error) {
Expand Down Expand Up @@ -134,7 +136,9 @@ func SyncToLocal(ctx context.Context, client *kubernetes.Clientset, namespace, n
}
nodesConfData = cm.Data[target]
} else {
os.WriteFile(fmt.Sprintf("%s.bak.1", targetFile), data, 0644)
if err := os.WriteFile(fmt.Sprintf("%s.bak.1", targetFile), data, 0644); err != nil {
logger.Error(err, "backup file failed", "file", targetFile)
}
nodesConfData = string(data)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/redis-tools/pkg/redis/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Node struct {
LinkState string
slots []string
rawInfo string
slaves []*Node
// slaves []*Node
}

func (n *Node) IsSelf() bool {
Expand Down
5 changes: 1 addition & 4 deletions cmd/redis-tools/pkg/types/slot/slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ func (s *Slots) Set(v interface{}, status SlotAssignStatus) error {
// Equals check if this two slots equals (no care about the status)
func (s *Slots) Equals(old *Slots) bool {
if s == nil {
if old == nil {
return true
}
return false
return old == nil
}
if old == nil {
return false
Expand Down

0 comments on commit 8ba3eee

Please sign in to comment.