mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2024-12-14 11:57:51 +00:00
source/system: advertise major and minor OS version
Add two new attributes 'VERSION_ID.major' and 'VERSION_ID.minor' to the os_release feature. These represent the first two components of the OS version (version components are assumed to be separated by a dot). E.g. if VERSION_ID would be 1.2.rc3 major and minor versions would be 1 and 2, respectively: feature.node.kubernetes.io/system-os_release.VERSION_ID=1.2.rc3 feature.node.kubernetes.io/system-os_release.VERSION_ID.major=1 feature.node.kubernetes.io/system-os_release.VERSION_ID.minor=2 The version components must be purely numerical in order for them to be advertised. This way they can be fully (and reliably) utilized in nodeAffinity, including relative (Gt and Lt) operators.
This commit is contained in:
parent
fcb530c19e
commit
af22702b93
2 changed files with 31 additions and 5 deletions
10
README.md
10
README.md
|
@ -305,10 +305,12 @@ for more information on NFD config.
|
|||
|
||||
### System Features
|
||||
|
||||
| Feature | Attribute | Description |
|
||||
| ----------- | ---------- | --------------------------------------------------|
|
||||
| os_release | ID | Operating system identifier
|
||||
| <br> | VERSION_ID | Operating system version identifier
|
||||
| Feature | Attribute | Description |
|
||||
| ----------- | ---------------- | --------------------------------------------|
|
||||
| os_release | ID | Operating system identifier
|
||||
| <br> | VERSION_ID | Operating system version identifier (e.g. '6.7')
|
||||
| <br> | VERSION_ID.major | First component of the OS version id (e.g. '6')
|
||||
| <br> | VERSION_ID.minor | Second component of the OS version id (e.g. '7')
|
||||
|
||||
## Getting started
|
||||
### System requirements
|
||||
|
|
|
@ -45,7 +45,15 @@ func (s Source) Discover() (source.Features, error) {
|
|||
} else {
|
||||
for _, key := range osReleaseFields {
|
||||
if value, exists := release[key]; exists {
|
||||
features["os_release."+key] = value
|
||||
feature := "os_release." + key
|
||||
features[feature] = value
|
||||
|
||||
if key == "VERSION_ID" {
|
||||
versionComponents := splitVersion(value)
|
||||
for subKey, subValue := range versionComponents {
|
||||
features[feature+"."+subKey] = subValue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,3 +82,19 @@ func parseOSRelease() (map[string]string, error) {
|
|||
|
||||
return release, nil
|
||||
}
|
||||
|
||||
// Split version number into sub-components. Verifies that they are numerical
|
||||
// so that they can be fully utilized in k8s nodeAffinity
|
||||
func splitVersion(version string) map[string]string {
|
||||
components := map[string]string{}
|
||||
// Currently, split out just major and minor version
|
||||
re := regexp.MustCompile(`^(?P<major>\d+)(\.(?P<minor>\d+))?(\..*)?$`)
|
||||
if m := re.FindStringSubmatch(version); m != nil {
|
||||
for i, name := range re.SubexpNames() {
|
||||
if i != 0 && name != "" {
|
||||
components[name] = m[i]
|
||||
}
|
||||
}
|
||||
}
|
||||
return components
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue