diff --git a/controllers/daemon_connector.go b/controllers/daemon_connector.go index 2f67f536..518f7ffe 100644 --- a/controllers/daemon_connector.go +++ b/controllers/daemon_connector.go @@ -8,7 +8,7 @@ package controllers import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "bytes" @@ -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 } @@ -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 } @@ -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 } diff --git a/plugin/mellanox.go b/plugin/mellanox.go index 30a606f6..084eee42 100644 --- a/plugin/mellanox.go +++ b/plugin/mellanox.go @@ -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() diff --git a/plugin/net_attach_def.go b/plugin/net_attach_def.go index a698f5bb..6314f1d6 100644 --- a/plugin/net_attach_def.go +++ b/plugin/net_attach_def.go @@ -8,6 +8,7 @@ package plugin import ( "context" "encoding/json" + "errors" "fmt" "strings" @@ -15,7 +16,7 @@ import ( 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" @@ -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 } @@ -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 diff --git a/plugin/sriov_resource.go b/plugin/sriov_resource.go index f461e00f..2fcb371b 100644 --- a/plugin/sriov_resource.go +++ b/plugin/sriov_resource.go @@ -8,7 +8,6 @@ package plugin import ( "bytes" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -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) }