1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Merge pull request #1351 from marquiz/devel/local-refactor

source/local: simplify feature file size checking
This commit is contained in:
Kubernetes Prow Robot 2023-09-08 07:10:17 -07:00 committed by GitHub
commit b7aa0b2273
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -324,23 +324,6 @@ 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)
@ -374,6 +357,10 @@ func getFileContent(fileName string) ([][]byte, error) {
}
if filestat.Mode().IsRegular() {
if filestat.Size() > MaxFeatureFileSize {
return lines, fmt.Errorf("file size limit exceeded: %d bytes > %d bytes", filestat.Size(), MaxFeatureFileSize)
}
fileContent, err := os.ReadFile(path)
// Do not return any lines if an error occurred