Skip to content

Commit

Permalink
Merge pull request #1335 from AhmedGrati/feat-add-feature-file-size-l…
Browse files Browse the repository at this point in the history
…imit

feat: add feature file size limit
  • Loading branch information
k8s-ci-robot committed Sep 6, 2023
2 parents aa6e140 + 124dfbf commit 51c79fe
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/usage/customization-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ The label value defaults to `true`, if not specified.

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

> **NOTE:** The feature file size limit it 64kB. The feature file will be
> ignored if the size limit is exceeded.
Comment lines (starting with `#`) are ignored.

Adding following line anywhere to feature file defines date when
Expand Down
20 changes: 20 additions & 0 deletions source/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ const ExpiryTimeKey = "expiry-time"
// DirectivePrefix defines the prefix of directives that should be parsed
const DirectivePrefix = "# +"

// MaxFeatureFileSize defines the maximum size of a feature file size
const MaxFeatureFileSize = 65536

// Config
var (
featureFilesDir = "/etc/kubernetes/node-feature-discovery/features.d/"
Expand Down Expand Up @@ -321,6 +324,23 @@ func getFeaturesFromFiles() (map[string]string, error) {

for _, file := range files {
fileName := file.Name()

fileInfo, err := file.Info()
if err != nil {
klog.ErrorS(err, "failed to get file info", "fileName", fileName)
continue
}

fileSize := fileInfo.Size()
if fileSize > MaxFeatureFileSize {
klog.ErrorS(
fmt.Errorf("file size limit exceeded: %d bytes > %d bytes", fileSize, MaxFeatureFileSize),
"skipping too big feature file",
"fileName", fileName, "fileSize", fileSize,
)
continue
}

lines, err := getFileContent(fileName)
if err != nil {
klog.ErrorS(err, "failed to read file", "fileName", fileName)
Expand Down
197 changes: 197 additions & 0 deletions source/local/testdata/features.d/big_file

Large diffs are not rendered by default.

0 comments on commit 51c79fe

Please sign in to comment.