Skip to content

nit: remove double validation on folder when register flag #2173

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

Open
wants to merge 1 commit into
base: reboot
Choose a base branch
from

Conversation

SamYuan1990
Copy link
Collaborator

I suppose we double validate /sys or /proc folder if we follow the default settings, or if we set up another folder other than /sys or /proc we still validate those folder during flag reg process and we have another validation function to check if the config is validated. So in this PR, just remove validation in flag reg process.

@SamYuan1990 SamYuan1990 requested a review from sthaha June 20, 2025 11:50
@github-actions github-actions bot added the fix A bug fix label Jun 21, 2025
@SamYuan1990
Copy link
Collaborator Author

@sthaha , I am confused with the code logic in config pkg, as there many times validation been invoked. I hope we can make it clean as a Validation function in public or a validation function as hook. To follow single response, or KISS.

Comment on lines +108 to +113
// Validate config before run
if err := cfg.Validate(); err != nil {
logger.Error("Error validate command line flags", "error", err.Error())
return nil, err
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not make it the responsibility of the caller to validate the config.

Comment on lines -189 to -192
if err := cfg.Validate(); err != nil {
return nil, err
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Load should validate

Comment on lines -240 to -241
hostSysFS := app.Flag(HostSysFSFlag, "Host sysfs path").Default("/sys").ExistingDir()
hostProcFS := app.Flag(HostProcFSFlag, "Host procfs path").Default("/proc").ExistingDir()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets not make it String since we must ensure the that the directory exists

Copy link
Collaborator

@sthaha sthaha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double validation is fine since config can be loaded through yaml which can be the overriden by flags.

@SamYuan1990
Copy link
Collaborator Author

Double validation is fine since config can be loaded through yaml which can be the overriden by flags.

but wait, if /sys and /proc have validation as those folder must exist, are those configurable?
or say, do we need those configurable?

For instance, on Mac OS, /sys not exists at init configuration phase, ExistingDir been executed and error at here blocked the configuration.
Otherwise, on Linux, /sys is a default path and always there, so user don't need to overwrite this config?

@sthaha
Copy link
Collaborator

sthaha commented Jun 22, 2025

Double validation is fine since config can be loaded through yaml which can be the overriden by flags.

but wait, if /sys and /proc have validation as those folder must exist, are those configurable? or say, do we need those configurable?

I agree that if --host.sys=/foo/bar is set, then /sys must not be validated. If I understand correctly, it should be the case now but I will check and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix A bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants