1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2025-03-05 08:17:04 +00:00

docs: add the support of the exipration date in the input format of the feature files

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
This commit is contained in:
AhmedGrati 2023-07-28 16:46:17 +01:00
parent bd3ccf1e33
commit f0edc6532a
2 changed files with 37 additions and 11 deletions

View file

@ -316,6 +316,14 @@ Label namespace may be specified with `<namespace>/<name>[=<value>]`.
Comment lines (starting with `#`) are ignored.
You can include the following block if you want to define the expiration date
of features that are described in the feature files:
```plaintext
# +expiry-time: 2023-07-29T11:22:33Z
```
**Note: The time format that we are supporting is RFC3339.**
### Mounts
The standard NFD deployments contain `hostPath` mounts for

View file

@ -276,22 +276,19 @@ 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
}
expiryDate, err := getExpirationDate(lines)
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
}
if expiryDate.Before(time.Now()) {
continue
}
klog.V(4).InfoS("feature file read", "fileName", fileName, "features", utils.DelayedDumper(fileFeatures))
@ -306,6 +303,27 @@ func getFeaturesFromFiles() (map[string]string, error) {
return features, nil
}
// Return the expiration date of a feature file
func getExpirationDate(lines [][]byte) (time.Time, error) {
for _, line := range lines {
if len(line) > 0 {
lineSplit := strings.SplitN(string(line), ":", 2)
key := lineSplit[0]
if key == ExpiryDateKey {
expiryDate, err := time.Parse(time.RFC3339, lineSplit[1])
if err != nil {
return time.Now(), err
}
return expiryDate, nil
}
}
}
return time.Now(), nil
}
// Read one file
func getFileContent(fileName string) ([][]byte, error) {
var lines [][]byte