Skip to content

Commit

Permalink
Merge pull request #545 from pliurh/upstream
Browse files Browse the repository at this point in the history
Sync upstream: 2021-7-22
  • Loading branch information
openshift-merge-robot authored Jul 22, 2021
2 parents 9af5e07 + 8ecc651 commit 5c2581d
Show file tree
Hide file tree
Showing 26 changed files with 931 additions and 773 deletions.
52 changes: 21 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -129,37 +129,27 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif

kustomize:
ifeq (, $(shell which kustomize))
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
GOFLAGS="" go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
else
KUSTOMIZE=$(shell which kustomize)
endif
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

skopeo:
if ! which skopeo; then if [ -z ${SKIP_VAR_SET} ]; then if [ -f /etc/redhat-release ]; then dnf -y install skopeo; elif [ -f /etc/lsb-release ]; then sudo apt-get -y update; sudo apt-get -y install skopeo; fi; fi; fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ contents:
inline: |
#!/bin/bash
set -eux
input="/etc/switchdev.conf"
input="/etc/sriov_config.json"
UDEV_RULE_FILE='/etc/udev/rules.d/10-persistent-net.rules'
if [ ! -f $input ]; then
echo "File /etc/switchdev.conf not exist."
echo "File /etc/sriov_config.json not exist."
exit
fi
Expand All @@ -33,49 +33,46 @@ contents:
append_to_file "$udev_data_line" "$UDEV_RULE_FILE"
}
names=()
while read pci_addr num_vfs
do
jq -c '.interfaces[]' ${input} | while read iface;do
num_vfs=$(echo $iface | jq '.numVfs' -r)
pci_addr=$(echo $iface | jq '.pciAddress' -r)
echo "Set $num_vfs VFs on device $pci_addr"
name=$(ls /sys/bus/pci/devices/${pci_addr}/net/)
names+=($name)
# Create udev rule to save PF name
add_udev_rule_for_sriov_pf $name
# create VFs
echo $num_vfs > /sys/bus/pci/devices/${pci_addr}/sriov_numvfs
done <"$input"
done
# wait for vfs to be ready
sleep 5
i=0
while read pci_addr num_vfs
do
# unload VF driver
VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn)
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers/mlx5_core/unbind || true
done
# set PF to switchdev mode
devlink dev eswitch set pci/${pci_addr} mode switchdev
jq -c '.interfaces[]' $input | while read iface;
do
eswitch_mode=$(echo $iface | jq '.eSwitchMode' -r)
if [[ "$eswitch_mode" == "switchdev" ]]; then
pci_addr=$(echo $iface | jq '.pciAddress' -r)
name=$(echo $iface | jq '.name' -r)
ip link set ${names[i]} up
# Create udev rule to save PF name
add_udev_rule_for_sriov_pf $name
# turn hw-tc-offload on
/usr/sbin/ethtool -K ${names[i]} hw-tc-offload on
echo "unload VF driver for $pci_addr"
VfDirs=$(ls /sys/bus/pci/devices/${pci_addr} | grep virtfn)
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers/mlx5_core/unbind || true
done
# set PF to switchdev mode
devlink dev eswitch set pci/${pci_addr} mode switchdev
ip link set ${name} up
i=$(( i+1 ))
# turn hw-tc-offload on
/usr/sbin/ethtool -K ${name} hw-tc-offload on
# load VF driver
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers_probe
done
done <"$input"
# load VF driver
for VfDir in $VfDirs
do
VfPciAddr=$(basename "$( readlink -f /sys/bus/pci/devices/${pci_addr}/$VfDir )")
echo $VfPciAddr > /sys/bus/pci/drivers_probe
done
fi
done
12 changes: 12 additions & 0 deletions bindata/manifests/webhook/004-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nri-control-switches
namespace: {{.Namespace}}
data:
config.json: |
{
"features": {
"enableHugePageDownApi": true
}
}
1 change: 0 additions & 1 deletion bindata/manifests/webhook/server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ spec:
- -tls-cert-file=/etc/tls/tls.crt
- -alsologtostderr=true
- -insecure=true
- -injectHugepageDownApi=true
env:
- name: NAMESPACE
valueFrom:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovibnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodepolicies.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodestates.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovoperatorconfigs.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovibnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodepolicies.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodestates.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovoperatorconfigs.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovibnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodepolicies.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworknodestates.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworkpoolconfigs.sriovnetwork.openshift.io
spec:
Expand Down
2 changes: 1 addition & 1 deletion manifests/4.9/sriovnetwork.openshift.io_sriovnetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovnetworks.sriovnetwork.openshift.io
spec:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
name: sriovoperatorconfigs.sriovnetwork.openshift.io
spec:
Expand Down
27 changes: 22 additions & 5 deletions pkg/utils/switchdev.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package utils

import (
"fmt"
"bytes"
"encoding/json"
"io/ioutil"
"os"

Expand All @@ -11,9 +12,13 @@ import (
)

const (
switchDevConfPath = "/host/etc/switchdev.conf"
switchDevConfPath = "/host/etc/sriov_config.json"
)

type config struct {
Interfaces []sriovnetworkv1.Interface `json:"interfaces"`
}

func IsSwitchdevModeSpec(spec sriovnetworkv1.SriovNetworkNodeStateSpec) bool {
for _, iface := range spec.Interfaces {
if iface.EswitchMode == sriovnetworkv1.ESWITCHMODE_SWITCHDEV {
Expand All @@ -37,18 +42,30 @@ func WriteSwitchdevConfFile(newState *sriovnetworkv1.SriovNetworkNodeState) (upd
return
}
}
newContent := ""
cfg := config{}
for _, iface := range newState.Spec.Interfaces {
if iface.EswitchMode == sriovnetworkv1.ESWITCHMODE_SWITCHDEV {
newContent = newContent + fmt.Sprintln(iface.PciAddress, iface.NumVfs)
// Not passing all the contents, since only NumVfs and EswitchMode can be configured by configure-switchdev.sh currently.
i := sriovnetworkv1.Interface{
Name: iface.Name,
PciAddress: iface.PciAddress,
EswitchMode: iface.EswitchMode,
NumVfs: iface.NumVfs,
}
cfg.Interfaces = append(cfg.Interfaces, i)
}
}
oldContent, err := ioutil.ReadFile(switchDevConfPath)
if err != nil {
glog.Errorf("WriteSwitchdevConfFile(): fail to read file: %v", err)
return
}
if newContent == string(oldContent) {
newContent, err := json.Marshal(cfg)
if err != nil {
glog.Errorf("WriteSwitchdevConfFile(): fail to marshal config: %v", err)
return
}
if bytes.Equal(newContent, oldContent) {
glog.V(2).Info("WriteSwitchdevConfFile(): no update")
return
}
Expand Down
Loading

0 comments on commit 5c2581d

Please sign in to comment.