Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add feature file size limit #1335

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
// 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 @@

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

Check warning on line 331 in source/local/local.go

View check run for this annotation

Codecov / codecov/patch

source/local/local.go#L330-L331

Added lines #L330 - L331 were not covered by tests
}

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.