mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-28 02:37:11 +00:00
Merge pull request #20 from IRCody/whitelist
Automatic merge from submit-queue Adds label-whitelist option. The --label-whitelist option takes a regex and matches against labels. If set, labels will only be published if they match the whitelist regex. ### No whitelist: ``` % docker run quay.io/kubernetes_incubator/node-feature-discovery:91b50e441347 --no-publish 2016-10-17 17:30:21.853659 I | node.alpha.intel.com/node-feature-discovery.version = d4eec17-dirty 2016-10-17 17:30:21.853975 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE3 = true 2016-10-17 17:30:21.853993 I | node.alpha.intel.com/d4eec17-dirty-cpuid-BMI1 = true 2016-10-17 17:30:21.854007 I | node.alpha.intel.com/d4eec17-dirty-cpuid-RDTSCP = true 2016-10-17 17:30:21.854020 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSSE3 = true 2016-10-17 17:30:21.854032 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE4.1 = true 2016-10-17 17:30:21.854045 I | node.alpha.intel.com/d4eec17-dirty-cpuid-AVX = true 2016-10-17 17:30:21.854057 I | node.alpha.intel.com/d4eec17-dirty-cpuid-F16C = true 2016-10-17 17:30:21.854071 I | node.alpha.intel.com/d4eec17-dirty-cpuid-LZCNT = true 2016-10-17 17:30:21.854083 I | node.alpha.intel.com/d4eec17-dirty-cpuid-POPCNT = true 2016-10-17 17:30:21.854096 I | node.alpha.intel.com/d4eec17-dirty-cpuid-CX16 = true 2016-10-17 17:30:21.854108 I | node.alpha.intel.com/d4eec17-dirty-cpuid-CMOV = true 2016-10-17 17:30:21.854119 I | node.alpha.intel.com/d4eec17-dirty-cpuid-NX = true 2016-10-17 17:30:21.854134 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE = true 2016-10-17 17:30:21.854146 I | node.alpha.intel.com/d4eec17-dirty-cpuid-FMA3 = true 2016-10-17 17:30:21.854158 I | node.alpha.intel.com/d4eec17-dirty-cpuid-AESNI = true 2016-10-17 17:30:21.854170 I | node.alpha.intel.com/d4eec17-dirty-cpuid-RDRAND = true 2016-10-17 17:30:21.854183 I | node.alpha.intel.com/d4eec17-dirty-cpuid-CLMUL = true 2016-10-17 17:30:21.854195 I | node.alpha.intel.com/d4eec17-dirty-cpuid-HTT = true 2016-10-17 17:30:21.854206 I | node.alpha.intel.com/d4eec17-dirty-cpuid-MMX = true 2016-10-17 17:30:21.854218 I | node.alpha.intel.com/d4eec17-dirty-cpuid-MMXEXT = true 2016-10-17 17:30:21.854230 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE2 = true 2016-10-17 17:30:21.854243 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE4.2 = true 2016-10-17 17:30:21.854256 I | node.alpha.intel.com/d4eec17-dirty-cpuid-AVX2 = true 2016-10-17 17:30:21.854268 I | node.alpha.intel.com/d4eec17-dirty-cpuid-BMI2 = true 2016-10-17 17:30:21.854281 I | node.alpha.intel.com/d4eec17-dirty-cpuid-ERMS = true 2016-10-17 17:30:21.868136 I | node.alpha.intel.com/d4eec17-dirty-rdt-RDTMON = true 2016-10-17 17:30:21.868247 I | node.alpha.intel.com/d4eec17-dirty-pstate-turbo = true ``` ### ".*rdt.*" ``` % docker run quay.io/kubernetes_incubator/node-feature-discovery:91b50e441347 --no-publish --label-whitelist=".*rdt.*" 2016-10-17 17:31:37.299285 I | node.alpha.intel.com/node-feature-discovery.version = d4eec17-dirty 2016-10-17 17:31:37.313323 I | node.alpha.intel.com/d4eec17-dirty-rdt-RDTMON = true ``` ### ".*(AVX|SSE|MMX).*" ``` % docker run quay.io/kubernetes_incubator/node-feature-discovery:91b50e441347 --no-publish --label-whitelist=".*(AVX|SSE|MMX).*" 2016-10-17 17:32:36.385967 I | node.alpha.intel.com/node-feature-discovery.version = d4eec17-dirty 2016-10-17 17:32:36.386253 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE = true 2016-10-17 17:32:36.386272 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSSE3 = true 2016-10-17 17:32:36.386286 I | node.alpha.intel.com/d4eec17-dirty-cpuid-AVX = true 2016-10-17 17:32:36.386354 I | node.alpha.intel.com/d4eec17-dirty-cpuid-MMX = true 2016-10-17 17:32:36.386368 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE4.1 = true 2016-10-17 17:32:36.386410 I | node.alpha.intel.com/d4eec17-dirty-cpuid-MMXEXT = true 2016-10-17 17:32:36.386424 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE4.2 = true 2016-10-17 17:32:36.386439 I | node.alpha.intel.com/d4eec17-dirty-cpuid-AVX2 = true 2016-10-17 17:32:36.386495 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE2 = true 2016-10-17 17:32:36.386520 I | node.alpha.intel.com/d4eec17-dirty-cpuid-SSE3 = true ```
This commit is contained in:
commit
6e9cdb4a7c
1 changed files with 23 additions and 9 deletions
32
main.go
32
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docopt/docopt-go"
|
||||
|
@ -60,17 +61,19 @@ func main() {
|
|||
usage := fmt.Sprintf(`%s.
|
||||
|
||||
Usage:
|
||||
%s [--no-publish --sources=<sources>]
|
||||
%s [--no-publish --sources=<sources> --label-whitelist=<pattern>]
|
||||
%s -h | --help
|
||||
%s --version
|
||||
|
||||
Options:
|
||||
-h --help Show this screen.
|
||||
--version Output version and exit.
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpuid,rdt,pstate]
|
||||
--no-publish Do not publish discovered features to the cluster-local
|
||||
Kubernetes API server.`,
|
||||
-h --help Show this screen.
|
||||
--version Output version and exit.
|
||||
--sources=<sources> Comma separated list of feature sources.
|
||||
[Default: cpuid,rdt,pstate]
|
||||
--no-publish Do not publish discovered features to the cluster-local
|
||||
Kubernetes API server.
|
||||
--label-whitelist=<pattern> Regular expression to filter label names to publish to the Kubernetes API server.
|
||||
[Default: ]`,
|
||||
ProgramName,
|
||||
ProgramName,
|
||||
ProgramName,
|
||||
|
@ -83,6 +86,7 @@ func main() {
|
|||
// Parse argument values as usable types.
|
||||
noPublish := arguments["--no-publish"].(bool)
|
||||
sourcesArg := strings.Split(arguments["--sources"].(string), ",")
|
||||
whiteListArg := arguments["--label-whitelist"].(string)
|
||||
|
||||
enabledSources := map[string]struct{}{}
|
||||
for _, s := range sourcesArg {
|
||||
|
@ -103,8 +107,13 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
labels := Labels{}
|
||||
// compile whiteListArg regex
|
||||
labelWhiteList, err := regexp.Compile(whiteListArg)
|
||||
if err != nil {
|
||||
log.Fatalf("Error parsing whitelist regex (%s): %s", whiteListArg, err)
|
||||
}
|
||||
|
||||
labels := Labels{}
|
||||
// Add the version of this discovery code as a node label
|
||||
versionLabel := fmt.Sprintf("%s/%s.version", Namespace, ProgramName)
|
||||
labels[versionLabel] = version
|
||||
|
@ -119,9 +128,14 @@ func main() {
|
|||
}
|
||||
|
||||
for name, value := range labelsFromSource {
|
||||
labels[name] = value
|
||||
// Log discovered feature.
|
||||
log.Printf("%s = %s", name, value)
|
||||
// Skip if label doesn't match labelWhiteList
|
||||
if !labelWhiteList.Match([]byte(name)) {
|
||||
log.Printf("%s does not match the whitelist (%s) and will not be published.", name, whiteListArg)
|
||||
continue
|
||||
}
|
||||
labels[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue