Skip to content

Commit

Permalink
Fix ineffassign issues
Browse files Browse the repository at this point in the history
Fix issues found by:
`golangci-lint run --disable-all -E ineffassign`

Signed-off-by: Fred Rolland <[email protected]>
  • Loading branch information
rollandf committed May 17, 2022
1 parent 9a71b6e commit ee6e56b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 22 deletions.
8 changes: 2 additions & 6 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,6 @@ func (s *SriovNetworkNodeState) GetDriverByPciAddress(addr string) string {
func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
logger := log.WithName("renderNetAttDef")
logger.Info("Start to render IB SRIOV CNI NetworkAttachementDefinition")
var err error
objs := []*uns.Unstructured{}

// render RawCNIConfig manifests
data := render.MakeRenderData()
Expand Down Expand Up @@ -511,7 +509,7 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig
}

objs, err = render.RenderDir(MANIFESTS_PATH, &data)
objs, err := render.RenderDir(MANIFESTS_PATH, &data)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -548,8 +546,6 @@ func (cr *SriovIBNetwork) DeleteNetAttDef(c client.Client) error {
func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
logger := log.WithName("renderNetAttDef")
logger.Info("Start to render SRIOV CNI NetworkAttachementDefinition")
var err error
objs := []*uns.Unstructured{}

// render RawCNIConfig manifests
data := render.MakeRenderData()
Expand Down Expand Up @@ -637,7 +633,7 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig
}

objs, err = render.RenderDir(MANIFESTS_PATH, &data)
objs, err := render.RenderDir(MANIFESTS_PATH, &data)
if err != nil {
return nil, err
}
Expand Down
17 changes: 6 additions & 11 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,17 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct
}
// Fetch the Nodes
nodeList := &corev1.NodeList{}
lo := &client.MatchingLabels{}
lo := &client.MatchingLabels{
"node-role.kubernetes.io/worker": "",
"beta.kubernetes.io/os": "linux",
}
defaultOpConf := &sriovnetworkv1.SriovOperatorConfig{}
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: constants.DEFAULT_CONFIG_NAME}, defaultOpConf); err != nil {
return reconcile.Result{}, err
}
if len(defaultOpConf.Spec.ConfigDaemonNodeSelector) > 0 {
labels := client.MatchingLabels(defaultOpConf.Spec.ConfigDaemonNodeSelector)
lo = &labels
} else {
lo = &client.MatchingLabels{
"node-role.kubernetes.io/worker": "",
"beta.kubernetes.io/os": "linux",
}
}
err = r.List(context.TODO(), nodeList, lo)
if err != nil {
Expand Down Expand Up @@ -530,7 +528,6 @@ func setDsNodeAffinity(pl *sriovnetworkv1.SriovNetworkNodePolicyList, ds *appsv1
func nodeSelectorTermsForPolicyList(policies []sriovnetworkv1.SriovNetworkNodePolicy) []corev1.NodeSelectorTerm {
terms := []corev1.NodeSelectorTerm{}
for _, p := range policies {
nodeSelector := corev1.NodeSelectorTerm{}
if len(p.Spec.NodeSelector) == 0 {
continue
}
Expand All @@ -548,7 +545,7 @@ func nodeSelectorTermsForPolicyList(policies []sriovnetworkv1.SriovNetworkNodePo
sort.Slice(expressions, func(i, j int) bool {
return expressions[i].Key < expressions[j].Key
})
nodeSelector = corev1.NodeSelectorTerm{
nodeSelector := corev1.NodeSelectorTerm{
MatchExpressions: expressions,
}
terms = append(terms, nodeSelector)
Expand All @@ -561,10 +558,8 @@ func nodeSelectorTermsForPolicyList(policies []sriovnetworkv1.SriovNetworkNodePo
func renderDsForCR(path string, data *render.RenderData) ([]*uns.Unstructured, error) {
logger := log.Log.WithName("renderDsForCR")
logger.Info("Start to render objects")
var err error
objs := []*uns.Unstructured{}

objs, err = render.RenderDir(path, data)
objs, err := render.RenderDir(path, data)
if err != nil {
return nil, errs.Wrap(err, "failed to render OpenShiftSRIOV Network manifests")
}
Expand Down
2 changes: 0 additions & 2 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ func (r *SriovOperatorConfigReconciler) syncPluginDaemonSet(dc *sriovnetworkv1.S
func (r *SriovOperatorConfigReconciler) syncConfigDaemonSet(dc *sriovnetworkv1.SriovOperatorConfig) error {
logger := log.Log.WithName("syncConfigDaemonset")
logger.Info("Start to sync config daemonset")
// var err error
objs := []*uns.Unstructured{}

data := render.MakeRenderData()
data.Data["Image"] = os.Getenv("SRIOV_NETWORK_CONFIG_DAEMON_IMAGE")
Expand Down
1 change: 1 addition & 0 deletions pkg/apply/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ metadata:
g.Expect(err).NotTo(HaveOccurred())

s, ok, err := uns.NestedSlice(upd.Object, "secrets")
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ok).To(BeTrue())
g.Expect(s).To(ConsistOf("foo"))
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ func dynamicValidateSriovNetworkNodePolicy(cr *sriovnetworkv1.SriovNetworkNodePo
nodeList, err := kubeclient.CoreV1().Nodes().List(context.Background(), metav1.ListOptions{
LabelSelector: labels.Set(cr.Spec.NodeSelector).String(),
})
if err != nil {
return false, err
}
nsList, err := snclient.SriovnetworkV1().SriovNetworkNodeStates(namespace).List(context.Background(), metav1.ListOptions{})
if err != nil {
return false, err
Expand Down
2 changes: 0 additions & 2 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ func ValidateCustomResource(ar v1.AdmissionReview) *v1.AdmissionResponse {

if ar.Request.Operation == "DELETE" {
raw = ar.Request.OldObject.Raw
} else {
raw = ar.Request.Object.Raw
}

switch ar.Request.Kind.Kind {
Expand Down
34 changes: 33 additions & 1 deletion test/conformance/tests/sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ var _ = Describe("[sriov] operator", func() {
BeforeEach(func() {
var node string
resourceName := "mturesource"
numVfs := 5
var numVfs int
var intf *sriovv1.InterfaceExt
var err error

Expand Down Expand Up @@ -1934,6 +1934,7 @@ func daemonsScheduledOnNodes(selector string) bool {
nn, err := clients.Nodes().List(context.Background(), metav1.ListOptions{
LabelSelector: selector,
})
Expect(err).ToNot(HaveOccurred())
nodes := nn.Items

daemons, err := clients.Pods(operatorNamespace).List(context.Background(), metav1.ListOptions{LabelSelector: "app=sriov-network-config-daemon"})
Expand Down Expand Up @@ -1970,6 +1971,37 @@ func createSriovPolicy(sriovDevice string, testNode string, numVfs int, resource
}, 10*time.Minute, time.Second).Should(Equal(int64(numVfs)))
}

func createUnschedulableTestPod(node string, networks []string, resourceName string) {
podDefinition := pod.RedefineWithNodeSelector(
pod.DefineWithNetworks(networks),
node,
)
createdPod, err := clients.Pods(namespaces.Test).Create(context.Background(), podDefinition, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
Consistently(func() k8sv1.PodPhase {
runningPod, err := clients.Pods(namespaces.Test).Get(context.Background(), createdPod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
return runningPod.Status.Phase
}, 3*time.Minute, 1*time.Second).Should(Equal(k8sv1.PodPending))
pod, err := clients.Pods(namespaces.Test).Get(context.Background(), createdPod.Name, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
for _, condition := range pod.Status.Conditions {
if condition.Reason == "Unschedulable" && strings.Contains(condition.Message, "Insufficient openshift.io/"+resourceName) {
return
}
}
Fail("Pod should be Unschedulable due to: Insufficient openshift.io/" + resourceName)
}

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 {
return true
}
}
return false
}

func createTestPod(node string, networks []string) *k8sv1.Pod {
return createCustomTestPod(node, networks, false, nil)
}
Expand Down
3 changes: 3 additions & 0 deletions test/util/client/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,8 @@ func New(kubeconfig string) *ClientSet {
clientSet.Client, err = runtimeclient.New(config, client.Options{
Scheme: crScheme,
})
if err != nil {
return nil
}
return clientSet
}

0 comments on commit ee6e56b

Please sign in to comment.