Skip to content

Commit

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

Signed-off-by: Fred Rolland <[email protected]>
  • Loading branch information
rollandf committed May 17, 2022
1 parent 9a71b6e commit b585bee
Show file tree
Hide file tree
Showing 32 changed files with 228 additions and 237 deletions.
76 changes: 38 additions & 38 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const (
LASTNETWORKNAMESPACE = "operator.sriovnetwork.openshift.io/last-network-namespace"
NETATTDEFFINALIZERNAME = "netattdef.finalizers.sriovnetwork.openshift.io"
POOLCONFIGFINALIZERNAME = "poolconfig.finalizers.sriovnetwork.openshift.io"
ESWITCHMODE_LEGACY = "legacy"
ESWITCHMODE_SWITCHDEV = "switchdev"
ESwithModeLegacy = "legacy"
ESwithModeSwitchDev = "switchdev"
)

const invalidVfIndex = -1

var MANIFESTS_PATH = "./bindata/manifests/cni-config"
var ManifestsPath = "./bindata/manifests/cni-config"
var log = logf.Log.WithName("sriovnetwork")

// NicIdMap contains supported mapping of IDs with each in the format of:
// NicIDMap contains supported mapping of IDs with each in the format of:
// Vendor ID, Physical Function Device ID, Virtual Function Device ID
var NicIdMap = []string{}
var NicIDMap = []string{}

// NetFilterType Represents the NetFilter tags to be used
type NetFilterType int
Expand All @@ -47,7 +47,7 @@ const (
// OpenstackNetworkID network UUID
OpenstackNetworkID NetFilterType = iota

SUPPORTED_NIC_ID_CONFIGMAP = "supported-nic-ids"
SupportedNicIDConfigmap = "supported-nic-ids"
)

func (e NetFilterType) String() string {
Expand All @@ -59,81 +59,81 @@ func (e NetFilterType) String() string {
}
}

func InitNicIdMap(client *kubernetes.Clientset, namespace string) error {
func InitNicIDMap(client *kubernetes.Clientset, namespace string) error {
cm, err := client.CoreV1().ConfigMaps(namespace).Get(
context.Background(),
SUPPORTED_NIC_ID_CONFIGMAP,
SupportedNicIDConfigmap,
metav1.GetOptions{},
)
// if the configmap does not exist, return false
if err != nil {
return err
}
for _, v := range cm.Data {
NicIdMap = append(NicIdMap, v)
NicIDMap = append(NicIDMap, v)
}
return nil
}

func IsSupportedVendor(vendorId string) bool {
for _, n := range NicIdMap {
func IsSupportedVendor(vendorID string) bool {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
if vendorId == ids[0] {
if vendorID == ids[0] {
return true
}
}
return false
}

func IsSupportedDevice(deviceId string) bool {
for _, n := range NicIdMap {
func IsSupportedDevice(deviceID string) bool {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
if deviceId == ids[1] {
if deviceID == ids[1] {
return true
}
}
return false
}

func IsSupportedModel(vendorId, deviceId string) bool {
for _, n := range NicIdMap {
func IsSupportedModel(vendorID, deviceID string) bool {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
if vendorId == ids[0] && deviceId == ids[1] {
if vendorID == ids[0] && deviceID == ids[1] {
return true
}
}
log.Info("IsSupportedModel():", "Unsupported model:", "vendorId:", vendorId, "deviceId:", deviceId)
log.Info("IsSupportedModel():", "Unsupported model:", "vendorId:", vendorID, "deviceId:", deviceID)
return false
}

func IsVfSupportedModel(vendorId, deviceId string) bool {
for _, n := range NicIdMap {
func IsVfSupportedModel(vendorID, deviceID string) bool {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
if vendorId == ids[0] && deviceId == ids[2] {
if vendorID == ids[0] && deviceID == ids[2] {
return true
}
}
log.Info("IsVfSupportedModel():", "Unsupported VF model:", "vendorId:", vendorId, "deviceId:", deviceId)
log.Info("IsVfSupportedModel():", "Unsupported VF model:", "vendorId:", vendorID, "deviceId:", deviceID)
return false
}

func IsEnabledUnsupportedVendor(vendorId string, unsupportedNicIdMap map[string]string) bool {
for _, n := range unsupportedNicIdMap {
func IsEnabledUnsupportedVendor(vendorID string, unsupportedNicIDMap map[string]string) bool {
for _, n := range unsupportedNicIDMap {
if IsValidPciString(n) {
ids := strings.Split(n, " ")
if vendorId == ids[0] {
if vendorID == ids[0] {
return true
}
}
}
return false
}

func IsValidPciString(nicIdString string) bool {
ids := strings.Split(nicIdString, " ")
func IsValidPciString(nicIDString string) bool {
ids := strings.Split(nicIDString, " ")

if len(ids) != 3 {
log.Info("IsValidPciString(): ", nicIdString)
log.Info("IsValidPciString(): ", nicIDString)
return false
}

Expand Down Expand Up @@ -166,11 +166,11 @@ func IsValidPciString(nicIdString string) bool {

func GetSupportedVfIds() []string {
var vfIds []string
for _, n := range NicIdMap {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
vfId := "0x" + ids[2]
if !StringInArray(vfId, vfIds) {
vfIds = append(vfIds, vfId)
vfID := "0x" + ids[2]
if !StringInArray(vfID, vfIds) {
vfIds = append(vfIds, vfID)
}
}
// return a sorted slice so that udev rule is stable
Expand All @@ -182,10 +182,10 @@ func GetSupportedVfIds() []string {
return vfIds
}

func GetVfDeviceId(deviceId string) string {
for _, n := range NicIdMap {
func GetVfDeviceID(deviceID string) string {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
if deviceId == ids[1] {
if deviceID == ids[1] {
return ids[2]
}
}
Expand Down Expand Up @@ -511,7 +511,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(ManifestsPath, &data)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -637,7 +637,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(ManifestsPath, &data)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion api/v1/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var update = flag.Bool("updategolden", false, "update .golden files")

func init() {
// when running go tests path is local to the file, overriding it.
v1.MANIFESTS_PATH = "../../bindata/manifests/cni-config"
v1.ManifestsPath = "../../bindata/manifests/cni-config"
}

func newNodeState() *v1.SriovNetworkNodeState {
Expand Down
2 changes: 1 addition & 1 deletion cmd/sriov-network-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
glog.V(0).Infof("Running on platform: %s", platformType.String())

var namespace = os.Getenv("NAMESPACE")
if err := sriovnetworkv1.InitNicIdMap(kubeclient, namespace); err != nil {
if err := sriovnetworkv1.InitNicIDMap(kubeclient, namespace); err != nil {
glog.Errorf("failed to run init NicIdMap: %v", err)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/webhook/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func runStartCmd(cmd *cobra.Command, args []string) {
panic(err)
}

keyPair, err := webhook.NewTlsKeypairReloader(certFile, keyFile)
keyPair, err := webhook.NewTLSKeypairReloader(certFile, keyFile)
if err != nil {
glog.Fatalf("error load certificate: %s", err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions controllers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
)

var webhooks = map[string](string){
constants.INJECTOR_WEBHOOK_NAME: constants.INJECTOR_WEBHOOK_PATH,
constants.OPERATOR_WEBHOOK_NAME: constants.OPERATOR_WEBHOOK_PATH,
constants.InjectorWebHookName: constants.InjectorWebHookPath,
constants.OperatorWebHookName: constants.OperatorWebHookPath,
}

var namespace = os.Getenv("NAMESPACE")
34 changes: 17 additions & 17 deletions controllers/sriovnetworknodepolicy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct
reqLogger.Info("Reconciling")

defaultPolicy := &sriovnetworkv1.SriovNetworkNodePolicy{}
err := r.Get(context.TODO(), types.NamespacedName{Name: constants.DEFAULT_POLICY_NAME, Namespace: namespace}, defaultPolicy)
err := r.Get(context.TODO(), types.NamespacedName{Name: constants.DefaultPolicyName, Namespace: namespace}, defaultPolicy)
if err != nil {
if errors.IsNotFound(err) {
// Default policy object not found, create it.
defaultPolicy.SetNamespace(namespace)
defaultPolicy.SetName(constants.DEFAULT_POLICY_NAME)
defaultPolicy.SetName(constants.DefaultPolicyName)
defaultPolicy.Spec = sriovnetworkv1.SriovNetworkNodePolicySpec{
NumVfs: 0,
NodeSelector: make(map[string]string),
NicSelector: sriovnetworkv1.SriovNetworkNicSelector{},
}
err = r.Create(context.TODO(), defaultPolicy)
if err != nil {
reqLogger.Error(err, "Failed to create default Policy", "Namespace", namespace, "Name", constants.DEFAULT_POLICY_NAME)
reqLogger.Error(err, "Failed to create default Policy", "Namespace", namespace, "Name", constants.DefaultPolicyName)
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
Expand All @@ -112,7 +112,7 @@ func (r *SriovNetworkNodePolicyReconciler) Reconcile(ctx context.Context, req ct
nodeList := &corev1.NodeList{}
lo := &client.MatchingLabels{}
defaultOpConf := &sriovnetworkv1.SriovOperatorConfig{}
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: constants.DEFAULT_CONFIG_NAME}, defaultOpConf); err != nil {
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: constants.DefaultConfigName}, defaultOpConf); err != nil {
return reconcile.Result{}, err
}
if len(defaultOpConf.Spec.ConfigDaemonNodeSelector) > 0 {
Expand Down Expand Up @@ -181,7 +181,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(pl *sriovne
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: constants.CONFIGMAP_NAME,
Name: constants.ConfigMapName,
Namespace: namespace,
},
Data: configData,
Expand All @@ -192,17 +192,17 @@ func (r *SriovNetworkNodePolicyReconciler) syncDevicePluginConfigMap(pl *sriovne
if errors.IsNotFound(err) {
err = r.Create(context.TODO(), cm)
if err != nil {
return fmt.Errorf("Couldn't create ConfigMap: %v", err)
return fmt.Errorf("couldn't create ConfigMap: %v", err)
}
logger.Info("Created ConfigMap for", cm.Namespace, cm.Name)
} else {
return fmt.Errorf("Failed to get ConfigMap: %v", err)
return fmt.Errorf("failed to get ConfigMap: %v", err)
}
} else {
logger.Info("ConfigMap already exists, updating")
err = r.Update(context.TODO(), cm)
if err != nil {
return fmt.Errorf("Couldn't update ConfigMap: %v", err)
return fmt.Errorf("couldn't update ConfigMap: %v", err)
}
}
return nil
Expand All @@ -212,8 +212,8 @@ func (r *SriovNetworkNodePolicyReconciler) syncAllSriovNetworkNodeStates(np *sri
logger := log.Log.WithName("syncAllSriovNetworkNodeStates")
logger.Info("Start to sync all SriovNetworkNodeState custom resource")
found := &corev1.ConfigMap{}
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: constants.CONFIGMAP_NAME}, found); err != nil {
logger.Info("Fail to get", "ConfigMap", constants.CONFIGMAP_NAME)
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: namespace, Name: constants.ConfigMapName}, found); err != nil {
logger.Info("Fail to get", "ConfigMap", constants.ConfigMapName)
}
for _, node := range nl.Items {
logger.Info("Sync SriovNetworkNodeState CR", "name", node.Name)
Expand Down Expand Up @@ -272,11 +272,11 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(np *sriovne
ns.Spec.DpConfigVersion = cksum
err = r.Create(context.TODO(), ns)
if err != nil {
return fmt.Errorf("Couldn't create SriovNetworkNodeState: %v", err)
return fmt.Errorf("couldn't create SriovNetworkNodeState: %v", err)
}
logger.Info("Created SriovNetworkNodeState for", ns.Namespace, ns.Name)
} else {
return fmt.Errorf("Failed to get SriovNetworkNodeState: %v", err)
return fmt.Errorf("failed to get SriovNetworkNodeState: %v", err)
}
} else {
logger.Info("SriovNetworkNodeState already exists, updating")
Expand Down Expand Up @@ -313,7 +313,7 @@ func (r *SriovNetworkNodePolicyReconciler) syncSriovNetworkNodeState(np *sriovne
}
err = r.Update(context.TODO(), newVersion)
if err != nil {
return fmt.Errorf("Couldn't update SriovNetworkNodeState: %v", err)
return fmt.Errorf("couldn't update SriovNetworkNodeState: %v", err)
}
}
return nil
Expand All @@ -330,15 +330,15 @@ func (r *SriovNetworkNodePolicyReconciler) syncPluginDaemonObjs(dp *sriovnetwork
data.Data["ReleaseVersion"] = os.Getenv("RELEASEVERSION")
data.Data["ResourcePrefix"] = os.Getenv("RESOURCE_PREFIX")

objs, err := renderDsForCR(constants.PLUGIN_PATH, &data)
objs, err := renderDsForCR(constants.PluginPath, &data)
if err != nil {
logger.Error(err, "Fail to render SR-IoV manifests")
return err
}

defaultConfig := &sriovnetworkv1.SriovOperatorConfig{}
err = r.Get(context.TODO(), types.NamespacedName{
Name: constants.DEFAULT_CONFIG_NAME, Namespace: namespace}, defaultConfig)
Name: constants.DefaultConfigName, Namespace: namespace}, defaultConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -600,7 +600,7 @@ func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(pl *srio
if p.Spec.NumVfs == 0 {
deviceID = p.Spec.NicSelector.DeviceID
} else {
deviceID = sriovnetworkv1.GetVfDeviceId(p.Spec.NicSelector.DeviceID)
deviceID = sriovnetworkv1.GetVfDeviceID(p.Spec.NicSelector.DeviceID)
}

if !sriovnetworkv1.StringInArray(deviceID, netDeviceSelectors.Devices) && deviceID != "" {
Expand Down Expand Up @@ -666,7 +666,7 @@ func (r *SriovNetworkNodePolicyReconciler) renderDevicePluginConfigData(pl *srio
if p.Spec.NumVfs == 0 {
deviceID = p.Spec.NicSelector.DeviceID
} else {
deviceID = sriovnetworkv1.GetVfDeviceId(p.Spec.NicSelector.DeviceID)
deviceID = sriovnetworkv1.GetVfDeviceID(p.Spec.NicSelector.DeviceID)
}

if !sriovnetworkv1.StringInArray(deviceID, netDeviceSelectors.Devices) && deviceID != "" {
Expand Down
Loading

0 comments on commit b585bee

Please sign in to comment.