-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8416 from RamLavi/release-0.53_move_multus_methods
[release-0.53] sriov: Fix network to PCI-Address mapping
- Loading branch information
Showing
53 changed files
with
1,639 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -482,6 +482,7 @@ spec: | |
- delete | ||
- update | ||
- create | ||
- patch | ||
- apiGroups: | ||
- "" | ||
resources: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,6 +384,7 @@ rules: | |
- delete | ||
- update | ||
- create | ||
- patch | ||
- apiGroups: | ||
- "" | ||
resources: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["networknamescheme.go"], | ||
importpath = "kubevirt.io/kubevirt/pkg/network/namescheme", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/network/vmispec:go_default_library", | ||
"//staging/src/kubevirt.io/api/core/v1:go_default_library", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "go_default_test", | ||
srcs = [ | ||
"networknamescheme_suite_test.go", | ||
"networknamescheme_test.go", | ||
], | ||
deps = [ | ||
":go_default_library", | ||
"//staging/src/kubevirt.io/api/core/v1:go_default_library", | ||
"//staging/src/kubevirt.io/client-go/testutils:go_default_library", | ||
"//vendor/github.com/onsi/ginkgo/v2:go_default_library", | ||
"//vendor/github.com/onsi/gomega:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2022 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package namescheme | ||
|
||
import ( | ||
"fmt" | ||
|
||
v1 "kubevirt.io/api/core/v1" | ||
|
||
"kubevirt.io/kubevirt/pkg/network/vmispec" | ||
) | ||
|
||
const PrimaryPodInterfaceName = "eth0" | ||
|
||
// CreateNetworkNameScheme iterates over the VMI's Networks, and creates for each a pod interface name. | ||
// The returned map associates between the network name and the generated pod interface name. | ||
// Primary network will use "eth0" and the secondary ones will use "net<id>" format, where id is an enumeration | ||
// from 1 to n. | ||
func CreateNetworkNameScheme(vmiNetworks []v1.Network) map[string]string { | ||
networkNameSchemeMap := mapMultusNonDefaultNetworksToPodInterfaceName(vmiNetworks) | ||
|
||
if multusDefaultNetwork := vmispec.LookUpDefaultNetwork(vmiNetworks); multusDefaultNetwork != nil { | ||
networkNameSchemeMap[multusDefaultNetwork.Name] = PrimaryPodInterfaceName | ||
} | ||
|
||
return networkNameSchemeMap | ||
} | ||
|
||
func mapMultusNonDefaultNetworksToPodInterfaceName(networks []v1.Network) map[string]string { | ||
networkNameSchemeMap := map[string]string{} | ||
for i, network := range vmispec.FilterMultusNonDefaultNetworks(networks) { | ||
networkNameSchemeMap[network.Name] = secondaryInterfaceName(i + 1) | ||
} | ||
return networkNameSchemeMap | ||
} | ||
|
||
func secondaryInterfaceName(idx int) string { | ||
return fmt.Sprintf("net%d", idx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright 2022 Red Hat, Inc. | ||
* | ||
*/ | ||
|
||
package namescheme_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
virtv1 "kubevirt.io/api/core/v1" | ||
|
||
"kubevirt.io/kubevirt/pkg/network/namescheme" | ||
) | ||
|
||
var _ = Describe("Network Name Scheme", func() { | ||
Context("CreateNetworkNameScheme", func() { | ||
DescribeTable("should return the expected NetworkNameSchemeMap", | ||
func(networkList []virtv1.Network, expectedNetworkNameSchemeMap map[string]string) { | ||
podIfacesNameScheme := namescheme.CreateNetworkNameScheme(networkList) | ||
|
||
Expect(podIfacesNameScheme).To(Equal(expectedNetworkNameSchemeMap)) | ||
}, | ||
Entry("when network list is nil", nil, map[string]string{}), | ||
Entry("when no multus networks exist", | ||
[]virtv1.Network{ | ||
newPodNetwork("default"), | ||
}, | ||
map[string]string{ | ||
"default": namescheme.PrimaryPodInterfaceName, | ||
}), | ||
Entry("when default multus networks exist", | ||
[]virtv1.Network{ | ||
createMultusDefaultNetwork("network0", "default/nad0"), | ||
createMultusSecondaryNetwork("network1", "default/nad1"), | ||
createMultusSecondaryNetwork("network2", "default/nad2"), | ||
}, | ||
map[string]string{ | ||
"network0": namescheme.PrimaryPodInterfaceName, | ||
"network1": "net1", | ||
"network2": "net2", | ||
}), | ||
) | ||
}) | ||
}) | ||
|
||
func createMultusSecondaryNetwork(name, networkName string) virtv1.Network { | ||
return createMultusNetwork(name, networkName) | ||
} | ||
|
||
func createMultusDefaultNetwork(name, networkName string) virtv1.Network { | ||
multusNetwork := createMultusNetwork(name, networkName) | ||
multusNetwork.Multus.Default = true | ||
return multusNetwork | ||
} | ||
|
||
func createMultusNetwork(name, networkName string) virtv1.Network { | ||
return virtv1.Network{ | ||
Name: name, | ||
NetworkSource: virtv1.NetworkSource{ | ||
Multus: &virtv1.MultusNetwork{ | ||
NetworkName: networkName, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func newPodNetwork(name string) virtv1.Network { | ||
return virtv1.Network{ | ||
Name: name, | ||
NetworkSource: virtv1.NetworkSource{ | ||
Pod: &virtv1.PodNetwork{}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.