mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-28 02:37:11 +00:00
Adding SR-IOV capability discovery to node-feature-discovery (#49)
* Adding SR-IOV capability discovery to node-feature-discovery * SR-IOV capability discovery in NFD : code update after PR review - using hostnetwork instead of volume mount in file node-feature-discovery-job.json.template - iterating through network interfaces that are "up" in sources.go - inserting logs in sources.go - change in feature source name from "netid" to "network" in sources.go, README.md and main.go * Added code for labels sriov=true (sriov_totalvfs > 0) and sriov-configured=true (sriov_numvfs > 0) * Code Refactored: Added Network package and network.go
This commit is contained in:
parent
59b0d5000a
commit
41da99a435
4 changed files with 100 additions and 5 deletions
15
README.md
15
README.md
|
@ -41,7 +41,7 @@ node-feature-discovery.
|
|||
-h --help Show this screen.
|
||||
--version Output version and exit.
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpuid,rdt,pstate]
|
||||
[Default: cpuid,rdt,pstate,network]
|
||||
--no-publish Do not publish discovered features to the
|
||||
cluster-local Kubernetes API server.
|
||||
--label-whitelist=<pattern> Regular expression to filter label names to
|
||||
|
@ -57,6 +57,7 @@ The current set of feature sources are the following:
|
|||
- [CPUID][cpuid] for x86 CPU details
|
||||
- [Intel Resource Director Technology][intel-rdt]
|
||||
- [Intel P-State driver][intel-pstate]
|
||||
- Network
|
||||
|
||||
### Feature labels
|
||||
|
||||
|
@ -77,7 +78,8 @@ the only label value published for features is the string `"true"`._
|
|||
"node.alpha.kubernetes-incubator.io/node-feature-discovery.version": "v0.1.0",
|
||||
"node.alpha.kubernetes-incubator.io/nfd-cpuid-<feature-name>": "true",
|
||||
"node.alpha.kubernetes-incubator.io/nfd-rdt-<feature-name>": "true",
|
||||
"node.alpha.kubernetes-incubator.io/nfd-pstate-<feature-name>": "true"
|
||||
"node.alpha.kubernetes-incubator.io/nfd-pstate-<feature-name>": "true",
|
||||
"node.alpha.kubernetes-incubator.io/nfd-network-<feature-name>": "true"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -110,6 +112,12 @@ such as restricting discovered features with the --label-whitelist option._
|
|||
| SSE4.2 | Streaming SIMD Extensions 4.2 (SSE4.2)
|
||||
| SGX | Software Guard Extensions (SGX)
|
||||
|
||||
### Network Features
|
||||
|
||||
| Feature name | Description |
|
||||
| :------------: | :---------------------------------------------------------------------------------: |
|
||||
| [SRIOV][sriov] | Single Root Input/Output Virtualization (SR-IOV) enabled Network Interface Card
|
||||
|
||||
## Getting started
|
||||
### System requirements
|
||||
|
||||
|
@ -129,7 +137,7 @@ repo that demonstrates how to deploy the job to unlabeled nodes.
|
|||
|
||||
The discovery script will launch a job on each unlabeled node in the
|
||||
cluster. When the job runs, it contacts the Kubernetes API server to add labels
|
||||
to the node to advertise hardware features (initially, from `cpuid`, RDT and p-state).
|
||||
to the node to advertise hardware features (initially, from `cpuid`, RDT, p-state and network).
|
||||
|
||||
[](https://asciinema.org/a/11wir751y89617oemwnsgli4a)
|
||||
|
||||
|
@ -226,6 +234,7 @@ A demo on the benefits of using node feature discovery can be found in [demo](de
|
|||
[cpuid]: http://man7.org/linux/man-pages/man4/cpuid.4.html
|
||||
[intel-rdt]: http://www.intel.com/content/www/us/en/architecture-and-technology/resource-director-technology.html
|
||||
[intel-pstate]: https://www.kernel.org/doc/Documentation/cpu-freq/intel-pstate.txt
|
||||
[sriov]: http://www.intel.com/content/www/us/en/pci-express/pci-sig-sr-iov-primer-sr-iov-technology-paper.html
|
||||
[docker-down]: https://docs.docker.com/engine/installation
|
||||
[golang-down]: https://golang.org/dl
|
||||
[gcc-down]: https://gcc.gnu.org
|
||||
|
|
4
main.go
4
main.go
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/kubernetes-incubator/node-feature-discovery/source"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/cpuid"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/fake"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/network"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/panic_fake"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/pstate"
|
||||
"github.com/kubernetes-incubator/node-feature-discovery/source/rdt"
|
||||
|
@ -110,7 +111,7 @@ func argsParse(argv []string) (noPublish bool, sourcesArg []string, whiteListArg
|
|||
-h --help Show this screen.
|
||||
--version Output version and exit.
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpuid,rdt,pstate]
|
||||
[Default: cpuid,rdt,pstate,network]
|
||||
--no-publish Do not publish discovered features to the
|
||||
cluster-local Kubernetes API server.
|
||||
--label-whitelist=<pattern> Regular expression to filter label names to
|
||||
|
@ -145,6 +146,7 @@ func configureParameters(sourcesArg []string, whiteListArg string) (sources []so
|
|||
cpuid.Source{},
|
||||
rdt.Source{},
|
||||
pstate.Source{},
|
||||
network.Source{},
|
||||
fake.Source{},
|
||||
panic_fake.Source{},
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
}
|
||||
},
|
||||
"spec": {
|
||||
"hostNetwork": true,
|
||||
"containers": [
|
||||
{
|
||||
"env": [
|
||||
|
@ -41,7 +42,7 @@
|
|||
"name": "node-feature-discovery",
|
||||
"ports": [
|
||||
{
|
||||
"containerPort": 2233,
|
||||
"containerPort": 7156,
|
||||
"hostPort": 7156
|
||||
}
|
||||
]
|
||||
|
|
83
source/network/network.go
Normal file
83
source/network/network.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
package network
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
// Source implements FeatureSource.
|
||||
type Source struct{}
|
||||
|
||||
func (s Source) Name() string { return "network" }
|
||||
|
||||
// returns feature names sriov-configured and sriov if SR-IOV capable NICs are present and/or SR-IOV virtual functions are configured on the node
|
||||
func (s Source) Discover() ([]string, error) {
|
||||
features := []string{}
|
||||
netInterfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("can't obtain the network interfaces details: %s", err.Error())
|
||||
}
|
||||
// iterating through network interfaces to obtain their respective number of virtual functions
|
||||
for _, netInterface := range netInterfaces {
|
||||
if strings.Contains(netInterface.Flags.String(), "up") && !strings.Contains(netInterface.Flags.String(), "loopback") {
|
||||
totalVfsPath := "/sys/class/net/" + netInterface.Name + "/device/sriov_totalvfs"
|
||||
totalBytes, err := ioutil.ReadFile(totalVfsPath)
|
||||
if err != nil {
|
||||
glog.Errorf("SR-IOV not supported for network interface: %s: %v", netInterface.Name, err)
|
||||
continue
|
||||
}
|
||||
total := bytes.TrimSpace(totalBytes)
|
||||
t, err := strconv.Atoi(string(total))
|
||||
if err != nil {
|
||||
glog.Errorf("Error in obtaining maximum supported number of virtual functions for network interface: %s: %v", netInterface.Name, err)
|
||||
continue
|
||||
}
|
||||
if t > 0 {
|
||||
glog.Infof("SR-IOV capability is detected on the network interface: %s", netInterface.Name)
|
||||
glog.Infof("%d maximum supported number of virtual functions on network interface: %s", t, netInterface.Name)
|
||||
features = append(features, "sriov")
|
||||
numVfsPath := "/sys/class/net/" + netInterface.Name + "/device/sriov_numvfs"
|
||||
numBytes, err := ioutil.ReadFile(numVfsPath)
|
||||
if err != nil {
|
||||
glog.Errorf("SR-IOV not configured for network interface: %s: %s", netInterface.Name, err)
|
||||
continue
|
||||
}
|
||||
num := bytes.TrimSpace(numBytes)
|
||||
n, err := strconv.Atoi(string(num))
|
||||
if err != nil {
|
||||
glog.Errorf("Error in obtaining the configured number of virtual functions for network interface: %s: %v", netInterface.Name, err)
|
||||
continue
|
||||
}
|
||||
if n > 0 {
|
||||
glog.Infof("%d virtual functions configured on network interface: %s", n, netInterface.Name)
|
||||
features = append(features, "sriov-configured")
|
||||
break
|
||||
} else if n == 0 {
|
||||
glog.Errorf("SR-IOV not configured on network interface: %s", netInterface.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return features, nil
|
||||
}
|
Loading…
Add table
Reference in a new issue