Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ineffassign issues #291

Merged
merged 1 commit into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion test/conformance/tests/sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,7 @@ var _ = Describe("[sriov] operator", func() {

By("Create first Pod which consumes all available VFs")
sriovDevice, err := sriovInfos.FindOneSriovDevice(node)
Expect(err).ToNot(HaveOccurred())
ipam := `{"type": "host-local","ranges": [[{"subnet": "3ffe:ffff:0:01ff::/64"}]],"dataDir": "/run/my-orchestrator/container-ipam-state"}`
err = network.CreateSriovNetwork(clients, sriovDevice, sriovNetworkName, namespaces.Test, operatorNamespace, resourceName, ipam)
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -1209,7 +1210,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 +1935,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
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
}
7 changes: 0 additions & 7 deletions test/validation/tests/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ const (
sriovOperatorConfigs = "sriovoperatorconfigs.sriovnetwork.openshift.io"
)

func init() {
roleWorkerCNF := os.Getenv("ROLE_WORKER_CNF")
if roleWorkerCNF == "" {
roleWorkerCNF = "worker-cnf"
}
}

var _ = Describe("validation", func() {

Context("sriov", func() {
Expand Down