diff --git a/pkg/kubeletclient/kubeletclient_test.go b/pkg/kubeletclient/kubeletclient_test.go index da1cda0a8..db4e703b5 100644 --- a/pkg/kubeletclient/kubeletclient_test.go +++ b/pkg/kubeletclient/kubeletclient_test.go @@ -47,12 +47,12 @@ type fakeResourceServer struct { server *grpc.Server } -//TODO: This is stub code for test, but we may need to change for the testing we use this API in the future... -func (m *fakeResourceServer) GetAllocatableResources(ctx context.Context, req *podresourcesapi.AllocatableResourcesRequest) (*podresourcesapi.AllocatableResourcesResponse, error) { +// TODO: This is stub code for test, but we may need to change for the testing we use this API in the future... +func (m *fakeResourceServer) GetAllocatableResources(_ context.Context, _ *podresourcesapi.AllocatableResourcesRequest) (*podresourcesapi.AllocatableResourcesResponse, error) { return &podresourcesapi.AllocatableResourcesResponse{}, nil } -func (m *fakeResourceServer) List(ctx context.Context, req *podresourcesapi.ListPodResourcesRequest) (*podresourcesapi.ListPodResourcesResponse, error) { +func (m *fakeResourceServer) List(_ context.Context, _ *podresourcesapi.ListPodResourcesRequest) (*podresourcesapi.ListPodResourcesResponse, error) { podName := "pod-name" podNamespace := "pod-namespace" containerName := "container-name" diff --git a/pkg/multus/multus.go b/pkg/multus/multus.go index 584144d51..5d257783c 100644 --- a/pkg/multus/multus.go +++ b/pkg/multus/multus.go @@ -107,7 +107,7 @@ func getIfname(delegate *types.DelegateNetConf, argif string, idx int) string { return fmt.Sprintf("net%d", idx) } -func getDelegateDeviceInfo(delegate *types.DelegateNetConf, runtimeConf *libcni.RuntimeConf) (*nettypes.DeviceInfo, error) { +func getDelegateDeviceInfo(_ *types.DelegateNetConf, runtimeConf *libcni.RuntimeConf) (*nettypes.DeviceInfo, error) { // If the DPDeviceInfoFile was created, it was copied to the CNIDeviceInfoFile. // If the DPDeviceInfoFile was not created, CNI might have created it. So // either way, load CNIDeviceInfoFile. diff --git a/pkg/multus/multus_suite_test.go b/pkg/multus/multus_suite_test.go index a46b474ce..d3756d867 100644 --- a/pkg/multus/multus_suite_test.go +++ b/pkg/multus/multus_suite_test.go @@ -146,7 +146,7 @@ func ParseEnvironment(environ []string) map[string]string { return m } -func (f *fakeExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData []byte, environ []string) ([]byte, error) { +func (f *fakeExec) ExecPlugin(_ context.Context, pluginPath string, stdinData []byte, environ []string) ([]byte, error) { envMap := ParseEnvironment(environ) cmd := envMap["CNI_COMMAND"] var index int diff --git a/pkg/netutils/netutils.go b/pkg/netutils/netutils.go index 47edf51cb..8d87787b1 100644 --- a/pkg/netutils/netutils.go +++ b/pkg/netutils/netutils.go @@ -92,7 +92,7 @@ func SetDefaultGW(netnsPath string, ifName string, gateways []net.IP) error { } // DeleteDefaultGWCache updates libcni cache to remove default gateway routes in result -func DeleteDefaultGWCache(cacheDir string, rt *libcni.RuntimeConf, netName string, ifName string, ipv4, ipv6 bool) error { +func DeleteDefaultGWCache(cacheDir string, rt *libcni.RuntimeConf, netName string, _ string, ipv4, ipv6 bool) error { cacheFile := filepath.Join(cacheDir, "results", fmt.Sprintf("%s-%s-%s", netName, rt.ContainerID, rt.IfName)) cache, err := os.ReadFile(cacheFile) @@ -264,7 +264,7 @@ func deleteDefaultGWResult020(result map[string]interface{}, ipv4, ipv6 bool) (m } // AddDefaultGWCache updates libcni cache to add default gateway result -func AddDefaultGWCache(cacheDir string, rt *libcni.RuntimeConf, netName string, ifName string, gw []net.IP) error { +func AddDefaultGWCache(cacheDir string, rt *libcni.RuntimeConf, netName string, _ string, gw []net.IP) error { cacheFile := filepath.Join(cacheDir, "results", fmt.Sprintf("%s-%s-%s", netName, rt.ContainerID, rt.IfName)) cache, err := os.ReadFile(cacheFile) diff --git a/pkg/server/config/generator.go b/pkg/server/config/generator.go index ffbf50f10..1a2a0d18b 100644 --- a/pkg/server/config/generator.go +++ b/pkg/server/config/generator.go @@ -89,6 +89,7 @@ func NewMultusConfig(pluginName string, cniVersion string, configurationOptions return multusConfig, err } +// ParseMultusConfig parses multus config from configPath and create MultusConf. func ParseMultusConfig(configPath string) (*MultusConf, error) { config, err := os.ReadFile(configPath) if err != nil { diff --git a/pkg/server/server.go b/pkg/server/server.go index f318b1ce2..f1b57d7b8 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -499,7 +499,7 @@ func cmdDelegateAdd(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.E return serializeResult(result) } -func cmdDelegateCheck(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo, multusConfig *types.NetConf) error { +func cmdDelegateCheck(cmdArgs *skel.CmdArgs, k8sArgs *types.K8sArgs, exec invoke.Exec, _ *k8s.ClientInfo, multusConfig *types.NetConf) error { delegateCNIConf := &types.DelegateNetConf{} if err := json.Unmarshal(cmdArgs.StdinData, delegateCNIConf); err != nil { return err diff --git a/pkg/server/thick_cni_test.go b/pkg/server/thick_cni_test.go index 6d8ea5f98..b9d3eefaa 100644 --- a/pkg/server/thick_cni_test.go +++ b/pkg/server/thick_cni_test.go @@ -46,17 +46,17 @@ const suiteName = "Thick CNI architecture" type fakeExec struct{} // ExecPlugin executes the plugin -func (fe *fakeExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData []byte, environ []string) ([]byte, error) { +func (fe *fakeExec) ExecPlugin(_ context.Context, _ string, _ []byte, _ []string) ([]byte, error) { return []byte("{}"), nil } // FindInPath finds in path -func (fe *fakeExec) FindInPath(plugin string, paths []string) (string, error) { +func (fe *fakeExec) FindInPath(_ string, _ []string) (string, error) { return "", nil } // Decode decodes -func (fe *fakeExec) Decode(jsonBytes []byte) (version.PluginInfo, error) { +func (fe *fakeExec) Decode(_ []byte) (version.PluginInfo, error) { return nil, nil } @@ -221,10 +221,7 @@ func prepareCNIEnv(netnsPath string, namespaceName string, podName string, podUI if err := os.Setenv("CNI_NETNS", netnsPath); err != nil { return err } - if err := os.Setenv("CNI_ARGS", cniArgs); err != nil { - return err - } - return nil + return os.Setenv("CNI_ARGS", cniArgs) } func teardownCNIEnv() error { @@ -237,10 +234,7 @@ func teardownCNIEnv() error { if err := os.Unsetenv("CNI_NETNS"); err != nil { return err } - if err := os.Unsetenv("CNI_ARGS"); err != nil { - return err - } - return nil + return os.Unsetenv("CNI_ARGS") } func createFakePod(k8sClient *k8s.ClientInfo, podName string) error { diff --git a/pkg/server/types.go b/pkg/server/types.go index a5f8f1fb4..b2b08c845 100644 --- a/pkg/server/types.go +++ b/pkg/server/types.go @@ -22,7 +22,6 @@ import ( "github.com/prometheus/client_golang/prometheus" "gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/k8sclient" - "gopkg.in/k8snetworkplumbingwg/multus-cni.v3/pkg/types" ) // Metrics represents server's metrics. @@ -40,13 +39,3 @@ type Server struct { serverConfig []byte metrics *Metrics } - -// ShimNetConf for the shim cni config file written in json -type ShimNetConf struct { - types.NetConf - - MultusSocketDir string `json:"socketDir"` - LogFile string `json:"logFile,omitempty"` - LogLevel string `json:"logLevel,omitempty"` - LogToStderr bool `json:"logToStderr,omitempty"` -} diff --git a/pkg/types/conf.go b/pkg/types/conf.go index ecbf0115f..8c271ce5b 100644 --- a/pkg/types/conf.go +++ b/pkg/types/conf.go @@ -420,8 +420,10 @@ func LoadNetConf(bytes []byte) (*NetConf, error) { const ( // const block for multus-daemon configs + // DefaultMultusDaemonConfigFile is the Default path of the config file DefaultMultusDaemonConfigFile = "/etc/cni/net.d/multus.d/daemon-config.json" + // DefaultMultusRunDir specifies default RunDir for multus DefaultMultusRunDir = "/run/multus/" )