Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: l1b0k <[email protected]>
  • Loading branch information
l1b0k committed Oct 15, 2024
1 parent c1db828 commit 5af2cab
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.14.0
ENVTEST_VERSION ?= latest
GOLANGCI_LINT_VERSION ?= v1.55.2
GOLANGCI_LINT_VERSION ?= v1.61.0

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
Expand Down
7 changes: 4 additions & 3 deletions pkg/controller/webhook/mutating.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package webhook

import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
Expand All @@ -35,7 +36,7 @@ import (

"gomodules.xyz/jsonpatch/v2"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8sErr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
k8stypes "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
Expand Down Expand Up @@ -101,7 +102,7 @@ func podWebhook(ctx context.Context, req *webhook.AdmissionRequest, client clien
if err != nil {
msg := fmt.Sprintf("error get previous podENI conf, %s", err)
l.Error(err, msg)
return webhook.Errored(1, fmt.Errorf(msg))
return webhook.Errored(1, errors.New(msg))

Check warning on line 105 in pkg/controller/webhook/mutating.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/webhook/mutating.go#L105

Added line #L105 was not covered by tests
}

// 1. check pod annotation config first
Expand Down Expand Up @@ -348,7 +349,7 @@ func getPreviousZone(ctx context.Context, client client.Client, pod *corev1.Pod)
Name: pod.Name,
}, podENI)
if err != nil {
if errors.IsNotFound(err) {
if k8sErr.IsNotFound(err) {
return "", nil
}
return "", err
Expand Down
32 changes: 16 additions & 16 deletions plugin/driver/utils/netlink_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NetlinkFamily(ip net.IP) int {

func LinkSetName(link netlink.Link, name string) error {
cmd := fmt.Sprintf("ip link set %s name %s", link.Attrs().Name, name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 36 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L36

Added line #L36 was not covered by tests
err := netlink.LinkSetName(link, name)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -43,7 +43,7 @@ func LinkSetName(link netlink.Link, name string) error {

func LinkAdd(link netlink.Link) error {
cmd := fmt.Sprintf("ip link add %s type %s", link.Attrs().Name, link.Type())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 46 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L46

Added line #L46 was not covered by tests
err := netlink.LinkAdd(link)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -53,7 +53,7 @@ func LinkAdd(link netlink.Link) error {

func LinkSetUp(link netlink.Link) error {
cmd := fmt.Sprintf("ip link set %s up", link.Attrs().Name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 56 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L56

Added line #L56 was not covered by tests
err := netlink.LinkSetUp(link)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -63,7 +63,7 @@ func LinkSetUp(link netlink.Link) error {

func LinkSetDown(link netlink.Link) error {
cmd := fmt.Sprintf("ip link set %s down", link.Attrs().Name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 66 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L66

Added line #L66 was not covered by tests
err := netlink.LinkSetDown(link)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -73,7 +73,7 @@ func LinkSetDown(link netlink.Link) error {

func LinkDel(link netlink.Link) error {
cmd := fmt.Sprintf("ip link del %s", link.Attrs().Name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 76 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L76

Added line #L76 was not covered by tests
err := netlink.LinkDel(link)
if err != nil {
if _, ok := err.(netlink.LinkNotFoundError); ok {
Expand All @@ -86,7 +86,7 @@ func LinkDel(link netlink.Link) error {

func LinkSetMTU(link netlink.Link, mtu int) error {
cmd := fmt.Sprintf("ip link set %s mtu %d", link.Attrs().Name, mtu)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 89 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L89

Added line #L89 was not covered by tests
err := netlink.LinkSetMTU(link, mtu)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -96,7 +96,7 @@ func LinkSetMTU(link netlink.Link, mtu int) error {

func AddrDel(link netlink.Link, addr *netlink.Addr) error {
cmd := fmt.Sprintf("ip addr del %s dev %s", addr.IPNet.String(), link.Attrs().Name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 99 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L99

Added line #L99 was not covered by tests
err := netlink.AddrDel(link, addr)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -106,7 +106,7 @@ func AddrDel(link netlink.Link, addr *netlink.Addr) error {

func AddrReplace(link netlink.Link, addr *netlink.Addr) error {
cmd := fmt.Sprintf("ip addr replace %s dev %s", addr.IPNet.String(), link.Attrs().Name)
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 109 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L109

Added line #L109 was not covered by tests
err := netlink.AddrReplace(link, addr)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -116,7 +116,7 @@ func AddrReplace(link netlink.Link, addr *netlink.Addr) error {

func RouteReplace(route *netlink.Route) error {
cmd := fmt.Sprintf("ip route replace %s", route.String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 119 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L119

Added line #L119 was not covered by tests
err := netlink.RouteReplace(route)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -126,7 +126,7 @@ func RouteReplace(route *netlink.Route) error {

func RouteDel(route *netlink.Route) error {
cmd := fmt.Sprintf("ip route del %s", route.String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 129 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L129

Added line #L129 was not covered by tests
err := netlink.RouteDel(route)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -136,7 +136,7 @@ func RouteDel(route *netlink.Route) error {

func NeighSet(neigh *netlink.Neigh) error {
cmd := fmt.Sprintf("ip neigh replace %s", neigh.String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 139 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L139

Added line #L139 was not covered by tests
err := netlink.NeighSet(neigh)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -146,7 +146,7 @@ func NeighSet(neigh *netlink.Neigh) error {

func RuleAdd(rule *netlink.Rule) error {
cmd := fmt.Sprintf("ip rule add %s", rule.String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 149 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L149

Added line #L149 was not covered by tests
err := netlink.RuleAdd(rule)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -156,7 +156,7 @@ func RuleAdd(rule *netlink.Rule) error {

func RuleDel(rule *netlink.Rule) error {
cmd := fmt.Sprintf("ip rule del %s", rule.String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 159 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L159

Added line #L159 was not covered by tests
err := netlink.RuleDel(rule)
if err != nil {
rule.IifName = ""
Expand All @@ -172,7 +172,7 @@ func RuleDel(rule *netlink.Rule) error {

func LinkSetNsFd(link netlink.Link, netNS ns.NetNS) error {
cmd := fmt.Sprintf("ip link set %s netns %s", link.Attrs().Name, netNS.Path())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 175 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L175

Added line #L175 was not covered by tests
err := netlink.LinkSetNsFd(link, int(netNS.Fd()))
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -182,7 +182,7 @@ func LinkSetNsFd(link netlink.Link, netNS ns.NetNS) error {

func QdiscReplace(qdisc netlink.Qdisc) error {
cmd := fmt.Sprintf("tc qdisc replace %s", qdisc.Attrs().String())
Log.Infof(cmd)
Log.Info(cmd)
err := netlink.QdiscReplace(qdisc)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand All @@ -191,7 +191,7 @@ func QdiscReplace(qdisc netlink.Qdisc) error {
}
func QdiscDel(qdisc netlink.Qdisc) error {
cmd := fmt.Sprintf("tc qdisc del %s", qdisc.Attrs().String())
Log.Infof(cmd)
Log.Info(cmd)

Check warning on line 194 in plugin/driver/utils/netlink_linux.go

View check run for this annotation

Codecov / codecov/patch

plugin/driver/utils/netlink_linux.go#L194

Added line #L194 was not covered by tests
err := netlink.QdiscDel(qdisc)
if err != nil {
return fmt.Errorf("error %s, %w", cmd, err)
Expand Down

0 comments on commit 5af2cab

Please sign in to comment.