Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source/system: advertise major and minor OS version #211

Merged
merged 1 commit into from
Feb 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,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
Expand Down
26 changes: 25 additions & 1 deletion source/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
}
Expand Down Expand Up @@ -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
}