Skip to content

Commit

Permalink
Fix gosimple issues
Browse files Browse the repository at this point in the history
This commit fixes issues found with:
`golangci-lint run --disable-all -E gosimple`

Signed-off-by: Fred Rolland <frolland@nvidia.com>
  • Loading branch information
rollandf committed Apr 27, 2022
1 parent 0030dda commit 4f9436d
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 39 deletions.
2 changes: 1 addition & 1 deletion api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ func (selector *SriovNetworkNicSelector) Selected(iface *InterfaceExt) bool {
return false
}
}
if selector.NetFilter != "" && NetFilterMatch(selector.NetFilter, iface.NetFilter) == false {
if selector.NetFilter != "" && !NetFilterMatch(selector.NetFilter, iface.NetFilter) {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestRendering(t *testing.T) {
if err != nil {
t.Fatalf("failed reading .golden: %s", err)
}
t.Log(string(b.Bytes()))
t.Log(b.String())
if !bytes.Equal(b.Bytes(), g) {
t.Errorf("bytes do not match .golden file")
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestIBRendering(t *testing.T) {
if err != nil {
t.Fatalf("failed reading .golden: %s", err)
}
t.Log(string(b.Bytes()))
t.Log(b.String())
if !bytes.Equal(b.Bytes(), g) {
t.Errorf("bytes do not match .golden file")
}
Expand Down
2 changes: 1 addition & 1 deletion controllers/sriovnetworkpoolconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (r *SriovNetworkPoolConfigReconciler) syncOvsHardwareOffloadMachineConfigs(
return fmt.Errorf("Couldn't delete MachineConfig: %v", err)
}
} else {
if bytes.Compare(foundMC.Spec.Config.Raw, mc.Spec.Config.Raw) == 0 {
if bytes.Equal(foundMC.Spec.Config.Raw, mc.Spec.Config.Raw) {
logger.Info("MachineConfig already exists, updating")
err = r.Update(context.TODO(), foundMC)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (r *SriovOperatorConfigReconciler) syncWebhookObjs(dc *sriovnetworkv1.Sriov
}

// Delete injector webhook
if *dc.Spec.EnableInjector != true && path == constants.INJECTOR_WEBHOOK_PATH {
if !*dc.Spec.EnableInjector && path == constants.INJECTOR_WEBHOOK_PATH {
for _, obj := range objs {
err = r.deleteWebhookObject(obj)
if err != nil {
Expand All @@ -253,7 +253,7 @@ func (r *SriovOperatorConfigReconciler) syncWebhookObjs(dc *sriovnetworkv1.Sriov
continue
}
// Delete operator webhook
if *dc.Spec.EnableOperatorWebhook != true && path == constants.OPERATOR_WEBHOOK_PATH {
if !*dc.Spec.EnableOperatorWebhook && path == constants.OPERATOR_WEBHOOK_PATH {
for _, obj := range objs {
err = r.deleteWebhookObject(obj)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,8 @@ func (dn *Daemon) processNextWorkItem() bool {
utilruntime.HandleError(fmt.Errorf("expected workItem in workqueue but got %#v", obj))
return nil
}
var err error

err = dn.nodeStateSyncHandler(key)
err := dn.nodeStateSyncHandler(key)
if err != nil {
// Ereport error message, and put the item back to work queue for retry.
dn.refreshCh <- Message{
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (p *MellanoxPlugin) OnNodeStateChange(old, new *sriovnetworkv1.SriovNetwork
processedNics := map[string]bool{}

// Read mellanox NIC status once
if mellanoxNicsStatus == nil || len(mellanoxNicsStatus) == 0 {
if len(mellanoxNicsStatus) == 0 {
for _, iface := range new.Status.Interfaces {
if iface.Vendor != MellanoxVendorId {
continue
Expand Down
3 changes: 1 addition & 2 deletions pkg/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,7 @@ func TestValidatePolicyForNodeStateWithInvalidDevice(t *testing.T) {
},
}
g := NewGomegaWithT(t)
var testEnv *envtest.Environment
testEnv = &envtest.Environment{}
var testEnv = &envtest.Environment{}

cfg, err := testEnv.Start()
g.Expect(err).ToNot(HaveOccurred())
Expand Down
39 changes: 15 additions & 24 deletions test/conformance/tests/sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(numVfs)))
Expand Down Expand Up @@ -392,10 +392,7 @@ var _ = Describe("[sriov] operator", func() {
}, (10+snoTimeoutMultiplier*110)*time.Second, 1*time.Second).ShouldNot(HaveOccurred())

checkFunc := func(line string) bool {
if strings.Contains(line, validationString) {
return true
}
return false
return strings.Contains(line, validationString)
}

validationFunction([]string{sriovNetwork.Name}, checkFunc)
Expand All @@ -405,7 +402,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 3*time.Minute, time.Second).Should(Equal(int64(numVfs)))
Expand Down Expand Up @@ -956,7 +953,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), vfioNode, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(5)))
Expand Down Expand Up @@ -1002,7 +999,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), vfioNode, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable["openshift.io/testresource"]
resNum := testedNode.Status.Allocatable["openshift.io/testresource"]
capacity, _ := resNum.AsInt64()
return capacity
}, 3*time.Minute, time.Second).Should(Equal(int64(3)))
Expand Down Expand Up @@ -1050,11 +1047,11 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() map[string]int64 {
testedNode, err := clients.Nodes().Get(context.Background(), vfioNode, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable["openshift.io/testresource"]
resNum := testedNode.Status.Allocatable["openshift.io/testresource"]
capacity, _ := resNum.AsInt64()
res := make(map[string]int64)
res["openshift.io/testresource"] = capacity
resNum, _ = testedNode.Status.Allocatable["openshift.io/testresource1"]
resNum = testedNode.Status.Allocatable["openshift.io/testresource1"]
capacity, _ = resNum.AsInt64()
res["openshift.io/testresource1"] = capacity
return res
Expand Down Expand Up @@ -1290,7 +1287,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(5)))
Expand Down Expand Up @@ -1441,7 +1438,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(numVfs)))
Expand Down Expand Up @@ -1505,10 +1502,7 @@ var _ = Describe("[sriov] operator", func() {
podsList, err := clients.Pods(operatorNamespace).List(context.Background(), metav1.ListOptions{
LabelSelector: fmt.Sprintf("app=%s", resourceName)})
Expect(err).ToNot(HaveOccurred())
if len(podsList.Items) > 0 {
return false
}
return true
return len(podsList.Items) <= 0

}, 2*time.Minute, 10*time.Second).Should(BeTrue())

Expand Down Expand Up @@ -1643,7 +1637,7 @@ var _ = Describe("[sriov] operator", func() {
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), node, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
allocatable, _ := resNum.AsInt64()
return allocatable
}, 10*time.Minute, time.Second).Should(Equal(int64(5)))
Expand Down Expand Up @@ -1972,7 +1966,7 @@ func createSriovPolicy(sriovDevice string, testNode string, numVfs int, resource
Eventually(func() int64 {
testedNode, err := clients.Nodes().Get(context.Background(), testNode, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
resNum, _ := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
resNum := testedNode.Status.Allocatable[corev1.ResourceName("openshift.io/"+resourceName)]
capacity, _ := resNum.AsInt64()
return capacity
}, 10*time.Minute, time.Second).Should(Equal(int64(numVfs)))
Expand Down Expand Up @@ -2001,7 +1995,7 @@ func createUnschedulableTestPod(node string, networks []string, resourceName str

func isPodConditionUnschedulable(pod *k8sv1.Pod, resourceName string) bool {
for _, condition := range pod.Status.Conditions {
if condition.Reason == "Unschedulable" && strings.Index(condition.Message, "Insufficient openshift.io/"+resourceName) != -1 {
if condition.Reason == "Unschedulable" && strings.Contains(condition.Message, "Insufficient openshift.io/"+resourceName) {
return true
}
}
Expand All @@ -2023,7 +2017,7 @@ func createCustomTestPod(node string, networks []string, hostNetwork bool, podCa
)
}

if podCapabilities != nil && len(podCapabilities) != 0 {
if len(podCapabilities) != 0 {
if podDefinition.Spec.Containers[0].SecurityContext == nil {
podDefinition.Spec.Containers[0].SecurityContext = &corev1.SecurityContext{}
}
Expand Down Expand Up @@ -2141,10 +2135,7 @@ func createVanillaNetworkPolicy(node string, sriovInfos *cluster.EnabledNodes, n
}

func defaultFilterPolicy(policy sriovv1.SriovNetworkNodePolicy) bool {
if policy.Spec.DeviceType != "netdevice" {
return false
}
return true
return policy.Spec.DeviceType == "netdevice"
}

func setSriovOperatorSpecFlag(flagName string, flagValue bool) {
Expand Down
5 changes: 1 addition & 4 deletions test/util/k8sreporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ func (r *KubernetesReporter) Dump() {
r.logPods("openshift-sriov-network-operator")
r.logPods(namespaces.Test)
r.logLogs(func(p *corev1.Pod) bool {
if !strings.HasPrefix(p.Name, "sriov-") {
return true
}
return false
return !strings.HasPrefix(p.Name, "sriov-")
})
r.logSriovNodeState()
r.logNetworkPolicies()
Expand Down

0 comments on commit 4f9436d

Please sign in to comment.