From 376ff8bff17e7bfbfdf902dec72dbffea36355ad Mon Sep 17 00:00:00 2001 From: Sebastian Sch Date: Thu, 1 Dec 2022 18:40:25 +0200 Subject: [PATCH] fix golint-issues Signed-off-by: Sebastian Sch --- api/v1/helper.go | 4 +--- cmd/sriov-network-config-daemon/service.go | 8 ++++---- controllers/helper.go | 4 ++++ controllers/sriovoperatorconfig_controller.go | 7 ++++--- pkg/daemon/daemon.go | 3 +-- pkg/daemon/plugin.go | 1 + pkg/host/host.go | 5 +++-- pkg/plugins/generic/generic_plugin.go | 2 +- pkg/plugins/virtual/virtual_plugin.go | 2 +- pkg/systemd/systemd.go | 5 +++-- pkg/utils/utils_virtual.go | 2 +- 11 files changed, 24 insertions(+), 19 deletions(-) diff --git a/api/v1/helper.go b/api/v1/helper.go index f0869a5220..2665c99685 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -91,9 +91,7 @@ func InitNicIDMapFromConfigMap(client kubernetes.Interface, namespace string) er } func InitNicIDMapFromList(idList []string) { - for _, v := range idList { - NicIDMap = append(NicIDMap, v) - } + NicIDMap = append(NicIDMap, idList...) } func IsSupportedVendor(vendorID string) bool { diff --git a/cmd/sriov-network-config-daemon/service.go b/cmd/sriov-network-config-daemon/service.go index db1a53f67b..4b6e14fafb 100644 --- a/cmd/sriov-network-config-daemon/service.go +++ b/cmd/sriov-network-config-daemon/service.go @@ -4,15 +4,16 @@ import ( "errors" "flag" "fmt" + "os" + "github.com/golang/glog" + "github.com/spf13/cobra" + sriovv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins/generic" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/systemd" - "github.com/spf13/cobra" - "os" - "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/version" ) @@ -111,7 +112,6 @@ func runServiceCmd(cmd *cobra.Command, args []string) { glog.Errorf("sriov-config-service failed to create generic plugin %v", err) return } - } else if nodeStateSpec.PlatformType == utils.VirtualOpenStack { // Openstack support metaData, networkData, err := utils.GetOpenstackData(false) diff --git a/controllers/helper.go b/controllers/helper.go index eb8ff44932..747db5a057 100644 --- a/controllers/helper.go +++ b/controllers/helper.go @@ -28,6 +28,10 @@ var webhooks = map[string](string){ constants.OperatorWebHookName: constants.OperatorWebHookPath, } +const ( + machineConfigCRDName = "MachineConfig" +) + var namespace = os.Getenv("NAMESPACE") func GetImagePullSecrets() []string { diff --git a/controllers/sriovoperatorconfig_controller.go b/controllers/sriovoperatorconfig_controller.go index eb11f1e02c..0bf7870714 100644 --- a/controllers/sriovoperatorconfig_controller.go +++ b/controllers/sriovoperatorconfig_controller.go @@ -19,7 +19,6 @@ package controllers import ( "context" "fmt" - machinev1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" "os" appsv1 "k8s.io/api/apps/v1" @@ -35,6 +34,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/reconcile" + machinev1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" apply "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/apply" constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" @@ -311,7 +312,7 @@ func (r *SriovOperatorConfigReconciler) deleteK8sResource(in *uns.Unstructured) func (r *SriovOperatorConfigReconciler) syncK8sResource(cr *sriovnetworkv1.SriovOperatorConfig, in *uns.Unstructured) error { switch in.GetKind() { - case "ClusterRole", "ClusterRoleBinding", "MutatingWebhookConfiguration", "ValidatingWebhookConfiguration", "MachineConfig": + case "ClusterRole", "ClusterRoleBinding", "MutatingWebhookConfiguration", "ValidatingWebhookConfiguration", machineConfigCRDName: default: // set owner-reference only for namespaced objects if err := controllerutil.SetControllerReference(cr, in, r.Scheme); err != nil { @@ -361,7 +362,7 @@ func (r *SriovOperatorConfigReconciler) syncSystemdService(cr *sriovnetworkv1.Sr // Sync machine config for _, obj := range objs { - if obj.GetKind() == "MachineConfig" && len(cr.Spec.ConfigDaemonNodeSelector) > 0 { + if obj.GetKind() == machineConfigCRDName && len(cr.Spec.ConfigDaemonNodeSelector) > 0 { scheme := kscheme.Scheme mc := &machinev1.ControllerConfig{} err = scheme.Convert(obj, mc, nil) diff --git a/pkg/daemon/daemon.go b/pkg/daemon/daemon.go index aa8890dff6..8bfa9cde15 100644 --- a/pkg/daemon/daemon.go +++ b/pkg/daemon/daemon.go @@ -109,7 +109,6 @@ type Daemon struct { } const ( - rdmaScriptsPath = "/bindata/scripts/enable-rdma.sh" udevScriptsPath = "/bindata/scripts/load-udev.sh" annoKey = "sriovnetwork.openshift.io/state" annoIdle = "Idle" @@ -219,7 +218,7 @@ func (dn *Daemon) Run(stopCh <-chan struct{}, exitCh <-chan error) error { } else { glog.V(0).Infof("Run(): start daemon.") } - if dn.useSystemdService == true { + if dn.useSystemdService { glog.V(0).Info("Run(): daemon running in systemd mode") } // Only watch own SriovNetworkNodeState CR diff --git a/pkg/daemon/plugin.go b/pkg/daemon/plugin.go index 0b9db565cc..022c9cdac1 100644 --- a/pkg/daemon/plugin.go +++ b/pkg/daemon/plugin.go @@ -2,6 +2,7 @@ package daemon import ( "fmt" + "github.com/golang/glog" sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" diff --git a/pkg/host/host.go b/pkg/host/host.go index 01fb85fdb8..adea794a00 100644 --- a/pkg/host/host.go +++ b/pkg/host/host.go @@ -2,11 +2,12 @@ package host import ( "fmt" - "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" "os" "strings" "github.com/golang/glog" + + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" ) const ( @@ -138,7 +139,7 @@ func (h *HostManager) TryEnableRdma() (bool, error) { } if isUbuntuSystem { - + return h.enableRDMAOnUbuntuMachine() } osName, err := h.getOSPrettyName() diff --git a/pkg/plugins/generic/generic_plugin.go b/pkg/plugins/generic/generic_plugin.go index b6891640a5..3e129151d7 100644 --- a/pkg/plugins/generic/generic_plugin.go +++ b/pkg/plugins/generic/generic_plugin.go @@ -2,7 +2,6 @@ package generic import ( "bytes" - "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" "os/exec" "reflect" "strconv" @@ -13,6 +12,7 @@ import ( sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" ) diff --git a/pkg/plugins/virtual/virtual_plugin.go b/pkg/plugins/virtual/virtual_plugin.go index 5c0923a1ec..3d9f2048bc 100644 --- a/pkg/plugins/virtual/virtual_plugin.go +++ b/pkg/plugins/virtual/virtual_plugin.go @@ -1,12 +1,12 @@ package virtual import ( - "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" "reflect" "github.com/golang/glog" sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" constants "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts" + "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/host" plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" ) diff --git a/pkg/systemd/systemd.go b/pkg/systemd/systemd.go index c97542a16e..3aa23c5880 100644 --- a/pkg/systemd/systemd.go +++ b/pkg/systemd/systemd.go @@ -3,12 +3,13 @@ package systemd import ( "bytes" "fmt" - "github.com/golang/glog" - "gopkg.in/yaml.v3" "io/ioutil" "os" "strings" + "github.com/golang/glog" + "gopkg.in/yaml.v3" + sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1" "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/utils" ) diff --git a/pkg/utils/utils_virtual.go b/pkg/utils/utils_virtual.go index cf3a1c75c0..3e390edd1d 100644 --- a/pkg/utils/utils_virtual.go +++ b/pkg/utils/utils_virtual.go @@ -128,7 +128,7 @@ func getOpenstackDataFromConfigDrive(useHostPath bool) (metaData *OSPMetaData, n networkData = &OSPNetworkData{} glog.Infof("reading OpenStack meta_data from config-drive") var metadataf *os.File - ospMetaDataFilePath := ospNetworkDataFile + ospMetaDataFilePath := ospMetaDataFile if useHostPath { ospMetaDataFilePath = ospHostMetaDataFile }