-
Notifications
You must be signed in to change notification settings - Fork 318
Fix: CLI config values from ~/.kagent/config.yaml not being used #983
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
base: main
Are you sure you want to change the base?
Fix: CLI config values from ~/.kagent/config.yaml not being used #983
Conversation
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.
Pull Request Overview
This PR fixes an issue where the CLI was ignoring configuration values from ~/.kagent/config.yaml and always using hardcoded defaults. The fix ensures that user configuration files are properly respected by loading the config early and using those values as flag defaults.
- Moves config initialization to occur before setting up command flags
- Implements fallback logic to use hardcoded defaults when config values are empty
- Uses loaded config values as the default values for CLI flags
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
go/cli/cmd/kagent/main.go
Outdated
| kagentURL := cfg.KAgentURL | ||
| if kagentURL == "" { | ||
| kagentURL = "http://localhost:8083" | ||
| } | ||
|
|
||
| namespace := cfg.Namespace | ||
| if namespace == "" { | ||
| namespace = "kagent" | ||
| } | ||
|
|
||
| outputFormat := cfg.OutputFormat | ||
| if outputFormat == "" { | ||
| outputFormat = "table" | ||
| } | ||
|
|
||
| timeout := cfg.Timeout | ||
| if timeout == 0 { | ||
| timeout = 300 * time.Second | ||
| } |
Copilot
AI
Oct 1, 2025
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.
[nitpick] This fallback logic is repetitive and could be simplified using a helper function or ternary-like pattern. Consider creating a helper function like getConfigWithDefault(configValue, defaultValue string) string to reduce code duplication.
go/cli/cmd/kagent/main.go
Outdated
| kagentURL := cfg.KAgentURL | ||
| if kagentURL == "" { | ||
| kagentURL = "http://localhost:8083" | ||
| } | ||
|
|
||
| namespace := cfg.Namespace | ||
| if namespace == "" { | ||
| namespace = "kagent" | ||
| } | ||
|
|
||
| outputFormat := cfg.OutputFormat | ||
| if outputFormat == "" { | ||
| outputFormat = "table" | ||
| } | ||
|
|
||
| timeout := cfg.Timeout | ||
| if timeout == 0 { | ||
| timeout = 300 * time.Second | ||
| } |
Copilot
AI
Oct 1, 2025
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.
Variable names should follow Go naming conventions. Use camelCase consistently: kagentURL, namespace, outputFormat, and timeout should be kagentURL, namespace, outputFormat, and timeout respectively. However, the indentation is inconsistent - these lines use spaces instead of tabs.
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } | |
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } |
go/cli/cmd/kagent/main.go
Outdated
| kagentURL := cfg.KAgentURL | ||
| if kagentURL == "" { | ||
| kagentURL = "http://localhost:8083" | ||
| } | ||
|
|
||
| namespace := cfg.Namespace | ||
| if namespace == "" { | ||
| namespace = "kagent" | ||
| } | ||
|
|
||
| outputFormat := cfg.OutputFormat | ||
| if outputFormat == "" { | ||
| outputFormat = "table" | ||
| } | ||
|
|
||
| timeout := cfg.Timeout | ||
| if timeout == 0 { | ||
| timeout = 300 * time.Second | ||
| } |
Copilot
AI
Oct 1, 2025
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.
Variable names should follow Go naming conventions. Use camelCase consistently: kagentURL, namespace, outputFormat, and timeout should be kagentURL, namespace, outputFormat, and timeout respectively. However, the indentation is inconsistent - these lines use spaces instead of tabs.
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } | |
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } |
go/cli/cmd/kagent/main.go
Outdated
| kagentURL := cfg.KAgentURL | ||
| if kagentURL == "" { | ||
| kagentURL = "http://localhost:8083" | ||
| } | ||
|
|
||
| namespace := cfg.Namespace | ||
| if namespace == "" { | ||
| namespace = "kagent" | ||
| } | ||
|
|
||
| outputFormat := cfg.OutputFormat | ||
| if outputFormat == "" { | ||
| outputFormat = "table" | ||
| } | ||
|
|
||
| timeout := cfg.Timeout | ||
| if timeout == 0 { | ||
| timeout = 300 * time.Second | ||
| } |
Copilot
AI
Oct 1, 2025
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.
Variable names should follow Go naming conventions. Use camelCase consistently: kagentURL, namespace, outputFormat, and timeout should be kagentURL, namespace, outputFormat, and timeout respectively. However, the indentation is inconsistent - these lines use spaces instead of tabs.
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } | |
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } |
go/cli/cmd/kagent/main.go
Outdated
| kagentURL := cfg.KAgentURL | ||
| if kagentURL == "" { | ||
| kagentURL = "http://localhost:8083" | ||
| } | ||
|
|
||
| namespace := cfg.Namespace | ||
| if namespace == "" { | ||
| namespace = "kagent" | ||
| } | ||
|
|
||
| outputFormat := cfg.OutputFormat | ||
| if outputFormat == "" { | ||
| outputFormat = "table" | ||
| } | ||
|
|
||
| timeout := cfg.Timeout | ||
| if timeout == 0 { | ||
| timeout = 300 * time.Second | ||
| } |
Copilot
AI
Oct 1, 2025
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.
Variable names should follow Go naming conventions. Use camelCase consistently: kagentURL, namespace, outputFormat, and timeout should be kagentURL, namespace, outputFormat, and timeout respectively. However, the indentation is inconsistent - these lines use spaces instead of tabs.
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } | |
| kagentURL := cfg.KAgentURL | |
| if kagentURL == "" { | |
| kagentURL = "http://localhost:8083" | |
| } | |
| namespace := cfg.Namespace | |
| if namespace == "" { | |
| namespace = "kagent" | |
| } | |
| outputFormat := cfg.OutputFormat | |
| if outputFormat == "" { | |
| outputFormat = "table" | |
| } | |
| timeout := cfg.Timeout | |
| if timeout == 0 { | |
| timeout = 300 * time.Second | |
| } |
go/cli/cmd/kagent/main.go
Outdated
| } | ||
|
|
||
| // Set fallback defaults if config values are empty | ||
| kagentURL := cfg.KAgentURL |
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.
I think the defaults are set in the Init func in the config.go (not sure if using viper is the right thing to do there, but we should set the defaults there if the config is not available)
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.
You're absolutely right, I can see the defaults are already in Init(). I'll remove the redundant fallbacks in main.go.
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.
i did the changes that uses the Init() function using viper.SetDefault() now
725cfc6 to
06ed213
Compare
| rootCmd.PersistentFlags().StringVarP(&cfg.Namespace, "namespace", "n", "kagent", "Namespace") | ||
| rootCmd.PersistentFlags().StringVarP(&cfg.OutputFormat, "output-format", "o", "table", "Output format") | ||
| rootCmd.PersistentFlags().BoolVarP(&cfg.Verbose, "verbose", "v", false, "Verbose output") | ||
| rootCmd.PersistentFlags().DurationVar(&cfg.Timeout, "timeout", 300*time.Second, "Timeout") |
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.
you removed the 300*time.Second, yet you left the time import -- this tells me you didn't even run the code, because if you would, you'd see that it fails with:
❯ go run cli/cmd/kagent/main.go dashboard
# command-line-arguments
cli/cmd/kagent/main.go:9:2: "time" imported and not used
Please run and test your code; and make sure it actually works and fixes the issue.
peterj
left a comment
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.
I don't think you compiled & tested this code at all:
go run cli/cmd/kagent/main.go dashboard
# command-line-arguments
cli/cmd/kagent/main.go:9:2: "time" imported and not used
Load config early and use values from ~/.kagent/config.yaml as flag defaults instead of hardcoded values. Falls back to defaults when config is missing. Resolves kagent-dev#973 Signed-off-by: Utkarsh Kumar <[email protected]>
06ed213 to
f145529
Compare
|
I am sorry for that .I removed the unused time import and have now tested the fix. |
|
So this still doesn't work. The reason is that the To fix this, we should use |
EItanya
left a comment
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.
At a more general level I think we should get rid of the config file altogether, I don't think it has really provided any value, and the plumbing isn't correct to make it worth it. Rather let's just rely on flags and defaults as most CLIs do. What do others think?
yeah i also think config is not that helpful so should i make changes to this issue or add another issue to remove config file altogether? |
Feel free to make changes to the existing |
FWIW: Im working on a PR that completely refactors the config file parsing and handling, so perhaps give me some days to finish it and then you guys can decide wether you wanna have it or get rid of the config file entirely |
The issue was CLI was ignoring configuration values from
~/.kagent/config.yamland always using hardcoded defaults.Solution
config.Init()andconfig.Get()early in the main function, before setting up command flagsChanges
go/cli/cmd/kagent/main.goto load config early and use config values as flag defaultsCloses #973