mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-28 02:37:11 +00:00
feat: add support for feature files expiration
Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
parent
9ed191808d
commit
bd3ccf1e33
1 changed files with 21 additions and 1 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
|
@ -37,6 +38,10 @@ const Name = "local"
|
|||
// LabelFeature of this feature source
|
||||
const LabelFeature = "label"
|
||||
|
||||
// ExpiryDateKey is the key of this feature source indicating
|
||||
// when features should be removed.
|
||||
const ExpiryDateKey = "# +expiry-time"
|
||||
|
||||
// Config
|
||||
var (
|
||||
featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/"
|
||||
|
@ -271,9 +276,24 @@ func getFeaturesFromFiles() (map[string]string, error) {
|
|||
klog.ErrorS(err, "failed to read file", "fileName", fileName)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
// Append features
|
||||
fileFeatures := parseFeatures(lines)
|
||||
|
||||
// Check expiration of file features
|
||||
if expiryDate, ok := fileFeatures[ExpiryDateKey]; ok {
|
||||
expiryDate, err := time.Parse(time.RFC3339, expiryDate)
|
||||
if err != nil {
|
||||
klog.ErrorS(err, "failed to parse feature file expiry date", "fileName", fileName)
|
||||
continue
|
||||
}
|
||||
|
||||
// Features should not be included if they're expired
|
||||
if expiryDate.Before(time.Now()) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
klog.V(4).InfoS("feature file read", "fileName", fileName, "features", utils.DelayedDumper(fileFeatures))
|
||||
for k, v := range fileFeatures {
|
||||
if old, ok := features[k]; ok {
|
||||
|
|
Loading…
Add table
Reference in a new issue