Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sync-20240201
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeke committed Feb 1, 2024
2 parents 5898650 + a3a5ba9 commit d0cebac
Show file tree
Hide file tree
Showing 487 changed files with 13,214 additions and 5,843 deletions.
29 changes: 16 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -32,10 +32,10 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand All @@ -46,34 +46,37 @@ jobs:
- name: test controllers on opensfhit
run: CLUSTER_TYPE=openshift make test-controllers

- name: test controllers on kubernetes
run: CLUSTER_TYPE=kubernetes make test-controllers

- name: test bindata/scripts
run: make test-bindata-scripts

golangci:
name: Golangci-lint
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.51.0
version: v1.55.2

test-coverage:
name: test-coverage
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.20.x
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2
Expand Down Expand Up @@ -107,10 +110,10 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: 1.20.x
go-version: 1.21.x

- name: run test
run: make test-e2e-conformance-virtual-k8s-cluster-ci
Expand Down Expand Up @@ -141,10 +144,10 @@ jobs:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Set up Go 1.20
- name: Set up Go 1.21
uses: actions/setup-go@v3
with:
go-version: 1.20.x
go-version: 1.21.x

- name: run test
run: make test-e2e-conformance-virtual-ocp-cluster-ci
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ tags
# End of https://www.gitignore.io/api/go,vim,emacs,visualstudiocode
#IDE (GoLand) specific
.idea/

# test-environment files
registry-login.conf
16 changes: 9 additions & 7 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ run:
- pkg/client
linters-settings:
depguard:
list-type: blacklist
packages:
# logging is allowed only by logutils.Log, logrus
# is allowed to use only in logutils package
- github.com/sirupsen/logrus
packages-with-error-message:
- github.com/sirupsen/logrus: "logging is allowed only by logutils.Log"
rules:
main:
deny:
- pkg: github.com/sirupsen/logrus
desc: "logging is allowed only by logutils.Log"
dupl:
threshold: 100
funlen:
Expand All @@ -25,6 +23,7 @@ linters-settings:
goconst:
min-len: 2
min-occurrences: 2
ignore-tests: true
gocritic:
enabled-tags:
- diagnostic
Expand Down Expand Up @@ -118,4 +117,7 @@ issues:
- lll
- stylecheck
- goconst
- path: test/conformance/tests
linters:
- goconst

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS builder
FROM golang:1.21 AS builder
WORKDIR /go/src/github.com/k8snetworkplumbingwg/sriov-network-operator
COPY . .
RUN make _build-manager BIN_PATH=build/_output/cmd
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.sriov-network-config-daemon
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS builder
FROM golang:1.21 AS builder
WORKDIR /go/src/github.com/k8snetworkplumbingwg/sriov-network-operator
COPY . .
RUN make _build-sriov-network-config-daemon BIN_PATH=build/_output/cmd
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.webhook
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20 AS builder
FROM golang:1.21 AS builder
WORKDIR /go/src/github.com/k8snetworkplumbingwg/sriov-network-operator
COPY . .
RUN make _build-webhook BIN_PATH=build/_output/cmd
Expand Down
28 changes: 10 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export WATCH_NAMESPACE?=openshift-sriov-network-operator
export GOFLAGS+=-mod=vendor
export GO111MODULE=on
PKGS=$(shell go list ./... | grep -v -E '/vendor/|/test|/examples')
TESTPKGS?=./...

# go source files, ignore vendor directory
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
Expand All @@ -51,7 +52,7 @@ GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
# golangci-lint version should be updated periodically
# we keep it fixed to avoid it from unexpectedly failing on the project
# in case of a version bump
GOLANGCI_LINT_VER = v1.51.0
GOLANGCI_LINT_VER = v1.55.2

GOLANGCI_LINT = $(BIN_DIR)/golangci-lint
# golangci-lint version should be updated periodically
Expand All @@ -62,7 +63,7 @@ GOLANGCI_LINT_VER = v1.46.1

.PHONY: all build clean gendeepcopy test test-e2e test-e2e-k8s run image fmt sync-manifests test-e2e-conformance manifests update-codegen

all: generate vet build
all: generate lint build

build: manager _build-sriov-network-config-daemon _build-webhook

Expand All @@ -82,14 +83,14 @@ image: ; $(info Building images...)
$(IMAGE_BUILDER) build -f $(DOCKERFILE_WEBHOOK) -t $(WEBHOOK_IMAGE_TAG) $(CURPATH) $(IMAGE_BUILD_OPTS)

# Run tests
test: generate vet manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)" HOME="$(shell pwd)" go test ./... -coverprofile cover.out -v
test: generate lint manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)" HOME="$(shell pwd)" go test -coverprofile cover.out -v ${TESTPKGS}

# Build manager binary
manager: generate vet _build-manager
manager: generate _build-manager

# Run against the configured Kubernetes cluster in ~/.kube/config
run: vet skopeo install
run: skopeo install
hack/run-locally.sh

# Install CRDs into a cluster
Expand Down Expand Up @@ -137,10 +138,6 @@ fmt: ## Go fmt your code
fmt-code:
go fmt ./...

# Run go vet against code
vet:
go vet ./...

# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
Expand All @@ -162,7 +159,7 @@ envtest: ## Download envtest-setup locally if necessary.

GOMOCK = $(shell pwd)/bin/mockgen
gomock:
$(call go-get-tool,$(GOMOCK),github.com/golang/mock/[email protected])
$(call go-install-tool,$(GOMOCK),github.com/golang/mock/[email protected])

# go-install-tool will 'go install' any package $2 and install it to $1.
define go-install-tool
Expand Down Expand Up @@ -210,7 +207,7 @@ redeploy-operator-virtual-cluster:
test-e2e-validation-only:
SUITE=./test/validation ./hack/run-e2e-conformance.sh

test-e2e: generate vet manifests skopeo envtest
test-e2e: generate manifests skopeo envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)"; source hack/env.sh; HOME="$(shell pwd)" go test ./test/e2e/... -timeout 60m -coverprofile cover.out -v

test-e2e-k8s: export NAMESPACE=sriov-network-operator
Expand All @@ -219,14 +216,9 @@ test-e2e-k8s: test-e2e
test-bindata-scripts: fakechroot
fakechroot ./test/scripts/enable-kargs_test.sh

test-%: generate vet manifests envtest
test-%: generate manifests envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir=/tmp -p path)" HOME="$(shell pwd)" go test ./$*/... -coverprofile cover-$*.out -coverpkg ./... -v

# deploy-setup-k8s: export NAMESPACE=sriov-network-operator
# deploy-setup-k8s: export ADMISSION_CONTROLLERS_ENABLED=false
# deploy-setup-k8s: export CNI_BIN_PATH=/opt/cni/bin
# test-e2e-k8s: test-e2e

GOCOVMERGE = $(BIN_DIR)/gocovmerge
gocovmerge: ## Download gocovmerge locally if necessary.
$(call go-install-tool,$(GOCOVMERGE),github.com/shabbyrobe/gocovmerge/cmd/gocovmerge@latest)
Expand Down
85 changes: 82 additions & 3 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
logf "sigs.k8s.io/controller-runtime/pkg/log"

"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/render"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
)

const (
Expand All @@ -35,7 +37,8 @@ const (
SriovCniStateAuto = "auto"
SriovCniStateOff = "off"
SriovCniStateOn = "on"
SriovCniIpamEmpty = "\"ipam\":{}"
SriovCniIpam = "\"ipam\""
SriovCniIpamEmpty = SriovCniIpam + ":{}"
)

const invalidVfIndex = -1
Expand All @@ -47,6 +50,8 @@ var log = logf.Log.WithName("sriovnetwork")
// Vendor ID, Physical Function Device ID, Virtual Function Device ID
var NicIDMap = []string{}

var InitialState SriovNetworkNodeState

// NetFilterType Represents the NetFilter tags to be used
type NetFilterType int

Expand Down Expand Up @@ -211,6 +216,80 @@ func GetVfDeviceID(deviceID string) string {
return ""
}

func IsSwitchdevModeSpec(spec SriovNetworkNodeStateSpec) bool {
for _, iface := range spec.Interfaces {
if iface.EswitchMode == ESwithModeSwitchDev {
return true
}
}
return false
}

func FindInterface(interfaces Interfaces, name string) (iface Interface, err error) {
for _, i := range interfaces {
if i.Name == name {
return i, nil
}
}
return Interface{}, fmt.Errorf("unable to find interface: %v", name)
}

func NeedToUpdateSriov(ifaceSpec *Interface, ifaceStatus *InterfaceExt) bool {
if ifaceSpec.Mtu > 0 {
mtu := ifaceSpec.Mtu
if mtu != ifaceStatus.Mtu {
log.V(2).Info("NeedToUpdateSriov(): MTU needs update", "desired", mtu, "current", ifaceStatus.Mtu)
return true
}
}

if ifaceSpec.NumVfs != ifaceStatus.NumVfs {
log.V(2).Info("NeedToUpdateSriov(): NumVfs needs update", "desired", ifaceSpec.NumVfs, "current", ifaceStatus.NumVfs)
return true
}
if ifaceSpec.NumVfs > 0 {
for _, vfStatus := range ifaceStatus.VFs {
ingroup := false
for _, groupSpec := range ifaceSpec.VfGroups {
if IndexInRange(vfStatus.VfID, groupSpec.VfRange) {
ingroup = true
if groupSpec.DeviceType != consts.DeviceTypeNetDevice {
if groupSpec.DeviceType != vfStatus.Driver {
log.V(2).Info("NeedToUpdateSriov(): Driver needs update",
"desired", groupSpec.DeviceType, "current", vfStatus.Driver)
return true
}
} else {
if StringInArray(vfStatus.Driver, vars.DpdkDrivers) {
log.V(2).Info("NeedToUpdateSriov(): Driver needs update",
"desired", groupSpec.DeviceType, "current", vfStatus.Driver)
return true
}
if vfStatus.Mtu != 0 && groupSpec.Mtu != 0 && vfStatus.Mtu != groupSpec.Mtu {
log.V(2).Info("NeedToUpdateSriov(): VF MTU needs update",
"vf", vfStatus.VfID, "desired", groupSpec.Mtu, "current", vfStatus.Mtu)
return true
}

// this is needed to be sure the admin mac address is configured as expected
if ifaceSpec.ExternallyManaged {
log.V(2).Info("NeedToUpdateSriov(): need to update the device as it's externally manage",
"device", ifaceStatus.PciAddress)
return true
}
}
break
}
}
if !ingroup && StringInArray(vfStatus.Driver, vars.DpdkDrivers) {
// VF which has DPDK driver loaded but not in any group, needs to be reset to default driver.
return true
}
}
}
return false
}

type ByPriority []SriovNetworkNodePolicy

func (a ByPriority) Len() int {
Expand Down Expand Up @@ -517,7 +596,7 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
}

if cr.Spec.IPAM != "" {
data.Data["SriovCniIpam"] = "\"ipam\":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
data.Data["SriovCniIpam"] = SriovCniIpam + ":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
} else {
data.Data["SriovCniIpam"] = SriovCniIpamEmpty
}
Expand Down Expand Up @@ -652,7 +731,7 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
}

if cr.Spec.IPAM != "" {
data.Data["SriovCniIpam"] = "\"ipam\":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
data.Data["SriovCniIpam"] = SriovCniIpam + ":" + strings.Join(strings.Fields(cr.Spec.IPAM), "")
} else {
data.Data["SriovCniIpam"] = SriovCniIpamEmpty
}
Expand Down
1 change: 1 addition & 0 deletions api/v1/sriovnetworknodestate_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type VirtualFunction struct {
Vlan int `json:"Vlan,omitempty"`
Mtu int `json:"mtu,omitempty"`
VfID int `json:"vfID"`
VdpaType string `json:"vdpaType,omitempty"`
}

// SriovNetworkNodeStateStatus defines the observed state of SriovNetworkNodeState
Expand Down
Loading

0 comments on commit d0cebac

Please sign in to comment.