diff --git a/source/local/local.go b/source/local/local.go index 9d1459572..c8e8f1193 100644 --- a/source/local/local.go +++ b/source/local/local.go @@ -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 {