-
Notifications
You must be signed in to change notification settings - Fork 19
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
env var for config file added #135
Conversation
Signed-off-by: siddhikhapare <siddhikhapare77@gmail.com>
@@ -26,7 +26,12 @@ import ( | |||
func main() { | |||
ctx := context.Background() | |||
|
|||
c, err := config.LoadConfig("/etc/config") | |||
configPath := os.Getenv("CONFIG") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@matthyx what do you think is the proper solution here? Because we are thinking of having multiple configuration files...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly, the goal is to split the config between component and cluster like in node-agent.
/improve |
configPath := os.Getenv("CONFIG") | ||
if configPath == "" { | ||
configPath = "/etc/config" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: It's a good practice to define default values as constants at the beginning of the file or package. This makes it easier to manage and change these values in the future.
configPath := os.Getenv("CONFIG") | |
if configPath == "" { | |
configPath = "/etc/config" | |
} | |
const defaultConfigPath = "/etc/config" | |
... | |
configPath := os.Getenv("CONFIG") | |
if configPath == "" { | |
configPath = defaultConfigPath | |
} |
if err != nil { | ||
logger.L().Ctx(ctx).Fatal("load config error", helpers.Error(err)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Error messages should be descriptive and provide context for easier debugging. Consider adding more information to the error message when the configuration file fails to load.
if err != nil { | |
logger.L().Ctx(ctx).Fatal("load config error", helpers.Error(err)) | |
} | |
if err != nil { | |
logger.L().Ctx(ctx).Fatal("Failed to load config from path: "+configPath, helpers.Error(err)) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay
Overview
Use the CONFIG environment variable to load the config file, but it currently doesn't allow custom file paths. Kubevuln always defaults to searching for the config file in the /etc/config path, regardless of the CONFIG env value.
How to Test
Build kubevuln using
make
Load config file using the CONFIG environment variable
export CONFIG=path/to/clusterData.json
Set the PORT environment variable to 8081
export PORT=8080
Related issues/PRs:
Resolved #129
Checklist before requesting a review