1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

kernel: more agressively sanitize full kernel version

Trim illegal characters from the beginning and end of the kernel version
string. Label values must start and end with an alphanumeric and we want
to have some 'version.full' label, even if a sanitized one.
This commit is contained in:
Markus Lehtonen 2020-11-23 15:51:11 +02:00
parent 83e2a9defb
commit ba4ecfe7dc

View file

@ -19,6 +19,7 @@ package kernel
import ( import (
"log" "log"
"regexp" "regexp"
"strings"
"sigs.k8s.io/node-feature-discovery/source" "sigs.k8s.io/node-feature-discovery/source"
"sigs.k8s.io/node-feature-discovery/source/internal/kernelutils" "sigs.k8s.io/node-feature-discovery/source/internal/kernelutils"
@ -114,6 +115,8 @@ func parseVersion() (map[string]string, error) {
// Replace forbidden symbols // Replace forbidden symbols
fullRegex := regexp.MustCompile("[^-A-Za-z0-9_.]") fullRegex := regexp.MustCompile("[^-A-Za-z0-9_.]")
full = fullRegex.ReplaceAllString(full, "_") full = fullRegex.ReplaceAllString(full, "_")
// Label values must start and end with an alphanumeric
full = strings.Trim(full, "-_.")
version["full"] = full version["full"] = full