Skip to content

Commit

Permalink
add revive linter and fix the lint error
Browse files Browse the repository at this point in the history
Signed-off-by: duanmengkk <[email protected]>
  • Loading branch information
duanmengkk committed Sep 12, 2024
1 parent f69918a commit bfc59f2
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 29 deletions.
5 changes: 1 addition & 4 deletions cmd/clusterlink/agent/app/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ func NewAgentCommand(ctx context.Context) *cobra.Command {
if errs := opts.Validate(); len(errs) != 0 {
return errs.ToAggregate()
}
if err := run(ctx, opts); err != nil {
return err
}
return nil
return run(ctx, opts)
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
Expand Down
5 changes: 1 addition & 4 deletions cmd/clusterlink/floater/app/floater.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ func NewFloaterCommand(ctx context.Context) *cobra.Command {
if errs := opts.Validate(); len(errs) != 0 {
return errs.ToAggregate()
}
if err := Run(ctx, opts); err != nil {
return err
}
return nil
return Run(ctx, opts)
},
Args: func(cmd *cobra.Command, args []string) error {
for _, arg := range args {
Expand Down
1 change: 1 addition & 0 deletions pkg/clusterlink/agent-manager/auto_detect_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (r *AutoDetectReconciler) newClusterMapFunc() handler.MapFunc {
}
}

// nolint:revive
func (r *AutoDetectReconciler) detectInterfaceName(ctx context.Context) (string, error) {
var Cluster kosmosv1alpha1.Cluster

Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterlink/network/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (n *DefaultNetWork) UpdateArps([]clusterlinkv1alpha1.Arp) error {
return ErrNotImplemented
}

func (n *DefaultNetWork) UpdateFdbs(fdbs []clusterlinkv1alpha1.Fdb) error {
func (n *DefaultNetWork) UpdateFdbs(_ []clusterlinkv1alpha1.Fdb) error {
return ErrNotImplemented
}

Expand Down
14 changes: 5 additions & 9 deletions pkg/clusterlink/network/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func createNewVxlanIface(name string, addrIPWithMask *netlink.Addr, vxlanId int,
}

// load device info from environment
// nolint:revive
func loadDevices() ([]clusterlinkv1alpha1.Device, error) {
ret := []clusterlinkv1alpha1.Device{}

Expand All @@ -113,9 +114,8 @@ func loadDevices() ([]clusterlinkv1alpha1.Device, error) {
if err != nil {
if errors.As(err, &netlink.LinkNotFoundError{}) {
continue
} else {
return nil, err
}
return nil, err
}

if vxlanIface.Type() != (&netlink.Vxlan{}).Type() {
Expand Down Expand Up @@ -230,11 +230,7 @@ func addDevice(d clusterlinkv1alpha1.Device) error {
return err
}

if err := updateDeviceConfig(d.Name, family); err != nil {
return err
}

return nil
return updateDeviceConfig(d.Name, family)
}

func deleteDevice(d clusterlinkv1alpha1.Device) error {
Expand All @@ -258,7 +254,7 @@ func deleteDevice(d clusterlinkv1alpha1.Device) error {

func updateDeviceConfig(name string, ipFamily int) error {
if ipFamily == netlink.FAMILY_V6 {
if err := UpdateDefaultIp6tablesBehavior(name); err != nil {
if err := UpdateDefaultIP6tablesBehavior(name); err != nil {
return err
}
if err := EnableDisableIPV6ByIFaceNmae(name); err != nil {
Expand All @@ -281,7 +277,7 @@ func UpdateDefaultIptablesAndKernalConfig(name string, ipFamily int) error {

// ipv6
if ipFamily == netlink.FAMILY_V6 {
if err := UpdateDefaultIp6tablesBehavior(name); err != nil {
if err := UpdateDefaultIP6tablesBehavior(name); err != nil {
return err
}
if err := EnableDisableIPV6ByIFaceNmae(name); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/clusterlink/network/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (w *WatchDog) AddTask(path string, contents []byte) {
w.WatchTasks = append(w.WatchTasks, WatchTask{Path: path, Contents: contents})
}

func (w *WatchDog) Watch(ctx context.Context) {
func (w *WatchDog) Watch(_ context.Context) {
w.lock.Lock()
defer w.lock.Unlock()

Expand All @@ -60,7 +60,7 @@ func init() {
go wait.UntilWithContext(context.Background(), watchDog.Watch, 30*time.Second)
}

func UpdateDefaultIp6tablesBehavior(ifaceName string) error {
func UpdateDefaultIP6tablesBehavior(ifaceName string) error {
iptableHandler, err := iptables.New(ipt.ProtocolIPv6)
if err != nil {
return err //nolint:wrapcheck // Let the caller wrap it
Expand Down
10 changes: 4 additions & 6 deletions pkg/clusterlink/network/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,11 @@ func translateChainName(key string, f bool) string {
}
if f {
return chainMap[key]
} else {
if chainMap["PREROUTING"] == key {
return "PREROUTING"
} else {
return "POSTROUTING"
}
}
if chainMap["PREROUTING"] == key {
return "PREROUTING"
}
return "POSTROUTING"
}

func groupByTableChain(records []IptablesRecord) map[string][]IptablesRecord {
Expand Down
5 changes: 4 additions & 1 deletion pkg/clusterlink/network/neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ import (
type NeighType int

const (
// nolint:revive
NEIGH_FDB NeighType = iota
// nolint:revive
NEIGH_ARP
)

var NEIGH_TYPE_MAP map[NeighType]string = map[NeighType]string{
// nolint:revive
var NEIGH_TYPE_MAP = map[NeighType]string{
NEIGH_ARP: "arp",
NEIGH_FDB: "fbd",
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/clusterlink/network/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ func loadRoutes() ([]clusterlinkv1alpha1.Route, error) {
if err != nil {
if errors.As(err, &netlink.LinkNotFoundError{}) {
continue
} else {
return nil, err
}
return nil, err
}
for _, r := range routes {
ret = append(ret, clusterlinkv1alpha1.Route{
Expand Down

0 comments on commit bfc59f2

Please sign in to comment.