Skip to content

Commit

Permalink
Remove unused code
Browse files Browse the repository at this point in the history
This PR fix issues found with:
golangci-lint run --disable-all -E unused

Signed-off-by: Fred Rolland <[email protected]>
  • Loading branch information
rollandf committed Apr 26, 2022
1 parent 0030dda commit 9e3652b
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 128 deletions.
7 changes: 1 addition & 6 deletions cmd/webhook/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/golang/glog"
"github.com/spf13/cobra"
"k8s.io/api/admission/v1"
v1 "k8s.io/api/admission/v1"
"k8s.io/apimachinery/pkg/runtime"

"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/webhook"
Expand All @@ -29,11 +29,6 @@ var (
Long: "Starts Webhook Daemon",
Run: runStartCmd,
}

startOpts struct {
kubeconfig string
nodeName string
}
)

// admitv1Func handles a v1 admission
Expand Down
3 changes: 0 additions & 3 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ type SriovOperatorConfigReconciler struct {
Scheme *runtime.Scheme
}

var injectorServiceCaCmVersion = ""
var webhookServiceCaCmVersion = ""

//+kubebuilder:rbac:groups=sriovnetwork.openshift.io,resources=sriovoperatorconfigs,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=sriovnetwork.openshift.io,resources=sriovoperatorconfigs/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=sriovnetwork.openshift.io,resources=sriovoperatorconfigs/finalizers,verbs=update
Expand Down
2 changes: 0 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"
Expand All @@ -48,7 +47,6 @@ import (
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.

var cfg *rest.Config
var k8sClient client.Client
var testEnv *envtest.Environment

Expand Down
30 changes: 1 addition & 29 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
mcfginformers "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions"
"golang.org/x/time/rate"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
Expand Down Expand Up @@ -63,8 +62,7 @@ type Message struct {

type Daemon struct {
// name is the node name.
name string
namespace string
name string

platform utils.PlatformType

Expand All @@ -88,8 +86,6 @@ type Daemon struct {

refreshCh chan<- Message

dpReboot bool

mu *sync.Mutex

drainer *drain.Helper
Expand All @@ -107,10 +103,6 @@ type Daemon struct {
mcpName string
}

type workItem struct {
old, new *sriovnetworkv1.SriovNetworkNodeState
}

const (
rdmaScriptsPath = "/bindata/scripts/enable-rdma.sh"
udevScriptsPath = "/bindata/scripts/load-udev.sh"
Expand Down Expand Up @@ -179,26 +171,6 @@ func New(
}
}

func (dn *Daemon) annotateUnsupportedNicIdConfigMap(cm *v1.ConfigMap, nodeName string) (*v1.ConfigMap, error) {
jsonData, err := json.Marshal(cm.Data)
if err != nil {
return nil, err
}
cmData := string(jsonData)

annotationKey := "openshift.io/" + nodeName
annotationData, ok := cm.ObjectMeta.Annotations[annotationKey]
if ok && cmData == annotationData {
return cm, nil
}

if cm.ObjectMeta.Annotations == nil {
cm.ObjectMeta.Annotations = make(map[string]string)
}
cm.ObjectMeta.Annotations[annotationKey] = cmData
return dn.kubeClient.CoreV1().ConfigMaps(namespace).Update(context.Background(), cm, metav1.UpdateOptions{})
}

func (dn *Daemon) tryCreateUdevRuleWrapper() error {
ns, nodeStateErr := dn.client.SriovnetworkV1().SriovNetworkNodeStates(namespace).Get(
context.Background(),
Expand Down
11 changes: 0 additions & 11 deletions pkg/plugins/virtual/virtual_plugin.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main

import (
"os/exec"
"reflect"
"syscall"

"github.com/golang/glog"
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
Expand Down Expand Up @@ -132,12 +130,3 @@ func needVfioDriver(state *sriovnetworkv1.SriovNetworkNodeState) bool {
}
return false
}

func isCommandNotFound(err error) bool {
if exitErr, ok := err.(*exec.ExitError); ok {
if status, ok := exitErr.Sys().(syscall.WaitStatus); ok && status.ExitStatus() == 127 {
return true
}
}
return false
}
10 changes: 0 additions & 10 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ func validatePolicyForNodePolicy(
return true, nil
}

func keys(m map[string]([]string)) []string {
keys := make([]string, len(m))
i := 0
for k := range m {
keys[i] = k
i++
}
return keys
}

func validateNicModel(selector *sriovnetworkv1.SriovNetworkNicSelector, iface *sriovnetworkv1.InterfaceExt, node *corev1.Node) bool {
if selector.Vendor != "" && selector.Vendor != iface.Vendor {
return false
Expand Down
30 changes: 0 additions & 30 deletions test/conformance/tests/sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1978,36 +1978,6 @@ 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{})
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
2 changes: 0 additions & 2 deletions test/e2e/e2e_tests_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
// +kubebuilder:scaffold:imports

"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/netns"
)

Expand Down Expand Up @@ -56,7 +55,6 @@ func TestSriovTests(t *testing.T) {
[]Reporter{printer.NewlineReporter{}})
}

var sriovInfos *cluster.EnabledNodes
var sriovIface *sriovnetworkv1.InterfaceExt

var _ = BeforeSuite(func(done Done) {
Expand Down
9 changes: 0 additions & 9 deletions test/util/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,3 @@ func getSriovNodes(clients *client.ClientSet, sriovNodeNames []string) ([]corev1
}
return nodes, nil
}

func containsNode(name string, sriovNodes []string) bool {
for _, node := range sriovNodes {
if node == name {
return true
}
}
return false
}
20 changes: 0 additions & 20 deletions test/util/k8sreporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,6 @@ func (r *KubernetesReporter) logNetworkPolicies() {
}
fmt.Fprintln(r.dumpOutput, string(j))
}
func (r *KubernetesReporter) logNetworks() {
fmt.Fprintf(r.dumpOutput, "Logging networks")

networks := sriovv1.SriovNetworkList{}
err := r.clients.List(context.Background(),
&networks,
runtimeclient.InNamespace("openshift-sriov-network-operator"))

if err != nil {
fmt.Fprintf(os.Stderr, "failed to fetch network policies: %v\n", err)
return
}

j, err := json.MarshalIndent(networks, "", " ")
if err != nil {
fmt.Println("Failed to marshal networks")
return
}
fmt.Fprintln(r.dumpOutput, string(j))
}

func (r *KubernetesReporter) logSriovNodeState() {
fmt.Fprintf(r.dumpOutput, "Logging node states")
Expand Down
6 changes: 0 additions & 6 deletions test/validation/tests/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/cluster"
)

var (
machineConfigPoolNodeSelector string
)

var (
clients *testclient.ClientSet
operatorNamespace string
Expand Down Expand Up @@ -54,8 +50,6 @@ func init() {
if roleWorkerCNF == "" {
roleWorkerCNF = "worker-cnf"
}

machineConfigPoolNodeSelector = fmt.Sprintf("node-role.kubernetes.io/%s", roleWorkerCNF)
}

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

0 comments on commit 9e3652b

Please sign in to comment.