Skip to content

Commit

Permalink
Merge pull request #290 from rollandf/gosimple
Browse files Browse the repository at this point in the history
Fix gosimple issues
  • Loading branch information
SchSeba authored May 17, 2022
2 parents 5180973 + 5b128da commit 9a71b6e
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 43 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 @@ -237,7 +237,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 @@ -250,7 +250,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
7 changes: 3 additions & 4 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,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 Expand Up @@ -680,7 +679,7 @@ func rebootNode() {
// if kubelet failed to shutdown - that way the machine will still eventually reboot
// as systemd will time out the stop invocation.
cmd := exec.Command("systemd-run", "--unit", "sriov-network-config-daemon-reboot",
"--description", fmt.Sprintf("sriov-network-config-daemon reboot node"), "/bin/sh", "-c", "systemctl stop kubelet.service; reboot")
"--description", "sriov-network-config-daemon reboot node", "/bin/sh", "-c", "systemctl stop kubelet.service; reboot")

if err := cmd.Run(); err != nil {
glog.Errorf("failed to reboot node: %v", err)
Expand Down Expand Up @@ -1043,7 +1042,7 @@ func tryCreateNMUdevRule() error {
new_content := fmt.Sprintf("ACTION==\"add|change|move\", ATTRS{device}==\"%s\", ENV{NM_UNMANAGED}=\"1\"\n", strings.Join(sriovnetworkv1.GetSupportedVfIds(), "|"))

// add NM udev rules for renaming VF rep
new_content = new_content + fmt.Sprintf("SUBSYSTEM==\"net\", ACTION==\"add|move\", ATTRS{phys_switch_id}!=\"\", ATTR{phys_port_name}==\"pf*vf*\", ENV{NM_UNMANAGED}=\"1\"\n")
new_content = new_content + "SUBSYSTEM==\"net\", ACTION==\"add|move\", ATTRS{phys_switch_id}!=\"\", ATTR{phys_port_name}==\"pf*vf*\", ENV{NM_UNMANAGED}=\"1\"\n"

old_content, err := ioutil.ReadFile(filePath)
// if old_content = new_content, don't do anything
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
37 changes: 14 additions & 23 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 @@ -1970,7 +1964,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 All @@ -1991,7 +1985,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 @@ -2109,10 +2103,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 @@ -58,10 +58,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
5 changes: 2 additions & 3 deletions test/util/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package network
import (
"context"
"encoding/json"
"fmt"
"strings"

netattdefv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
Expand Down Expand Up @@ -125,7 +124,7 @@ func CreateMacvlanNetworkAttachmentDefinition(name string, namespace string) net
Namespace: namespace,
},
Spec: netattdefv1.NetworkAttachmentDefinitionSpec{
Config: fmt.Sprintf(`{
Config: `{
"cniVersion": "0.3.0",
"type": "macvlan",
"mode": "bridge",
Expand All @@ -139,7 +138,7 @@ func CreateMacvlanNetworkAttachmentDefinition(name string, namespace string) net
],
"gateway": "10.1.1.1"
}
}`),
}`,
},
}
}

0 comments on commit 9a71b6e

Please sign in to comment.