Skip to content

Commit

Permalink
fix: golint ioutils, error format
Browse files Browse the repository at this point in the history
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
  • Loading branch information
sunya-ch committed Aug 29, 2024
1 parent fda977c commit f0c3ee4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions controllers/daemon_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package controllers
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net/http"

"bytes"
Expand Down Expand Up @@ -79,7 +79,7 @@ func (dc DaemonConnector) GetInterfaces(podAddress string) ([]multinicv1.Interfa
return []multinicv1.InterfaceInfoType{}, err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return []multinicv1.InterfaceInfoType{}, err
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (dc DaemonConnector) Join(podAddress string, hifs []multinicv1.InterfaceInf
return errors.New(res.Status)
}

_, err = ioutil.ReadAll(res.Body)
_, err = io.ReadAll(res.Body)
if err != nil {
return err
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func (dc DaemonConnector) putRouteRequest(podAddress string, path string, cidrNa
return response, errors.New(res.Status)
}

body, err := ioutil.ReadAll(res.Body)
body, err := io.ReadAll(res.Body)
if err != nil {
return response, err
}
Expand Down
6 changes: 3 additions & 3 deletions plugin/mellanox.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func (p *MellanoxPlugin) GetConfig(net multinicv1.MultiNicNetwork, hifList map[s
// get resource from nicclusterpolicy
resourceName := p.GetResourceName()
if resourceName == "" {
msg := "failed to get resource name from sriov plugin config"
vars.NetworkLog.V(2).Info(msg)
return "", annotation, fmt.Errorf(msg)
err := fmt.Errorf("failed to get resource name from sriov plugin config")
vars.NetworkLog.V(2).Info(err.Error())
return "", annotation, err
}

name := net.GetName()
Expand Down
7 changes: 4 additions & 3 deletions plugin/net_attach_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ package plugin
import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"

"github.com/containernetworking/cni/pkg/types"
multinicv1 "github.com/foundation-model-stack/multi-nic-cni/api/v1"
"github.com/foundation-model-stack/multi-nic-cni/controllers/vars"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -143,7 +144,7 @@ func (h *NetAttachDefHandler) CreateOrUpdateOnNamespace(ns string, net *multinic
errMsg := h.createOrUpdate(def, "")
if errMsg != "" {
vars.NetworkLog.V(2).Info(errMsg)
return fmt.Errorf(errMsg)
return errors.New(errMsg)
}
return nil
}
Expand Down Expand Up @@ -268,7 +269,7 @@ func (h *NetAttachDefHandler) Get(name string, namespace string) (*NetworkAttach
func (h *NetAttachDefHandler) IsExist(name string, namespace string) bool {
_, err := h.Get(name, namespace)
if err != nil {
if !errors.IsNotFound(err) {
if !k8serrors.IsNotFound(err) {
vars.NetworkLog.V(2).Info(fmt.Sprintf("Not exist: %v", err))
}
return false
Expand Down
3 changes: 1 addition & 2 deletions plugin/sriov_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package plugin
import (
"bytes"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -312,7 +311,7 @@ func RenderTemplate(path string, d *RenderData) ([]*unstructured.Unstructured, e
tmpl.Funcs(template.FuncMap{"getOr": getOr, "isSet": isSet})
tmpl.Funcs(sprig.TxtFuncMap())

source, err := ioutil.ReadFile(path)
source, err := os.ReadFile(path)
if err != nil {
return nil, errors.Wrapf(err, "failed to read manifest %s", path)
}
Expand Down

0 comments on commit f0c3ee4

Please sign in to comment.