Skip to content

Commit

Permalink
docs: add the support of the exipration date in the input format of t…
Browse files Browse the repository at this point in the history
…he feature files

Signed-off-by: AhmedGrati <ahmedgrati1999@gmail.com>
  • Loading branch information
TessaIO committed Jul 28, 2023
1 parent 4952190 commit b90d2ea
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
7 changes: 7 additions & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ The label value defaults to `true`, if not specified.

Label namespace may be specified with `<namespace>/<name>[=<value>]`.

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
Expand Down
40 changes: 29 additions & 11 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,22 +270,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))
Expand All @@ -300,6 +297,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
Expand Down

0 comments on commit b90d2ea

Please sign in to comment.