Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ func (o *ValidateOptions) Run() error {
return fmt.Errorf("matching against target cluster: %w", err)
}
report.Mode = "live"
// Get the actual context being used (either from flag or current-context)
rawConfig, err := o.configFlags.ToRawKubeConfigLoader().RawConfig()
if err == nil {
report.ClusterContext = rawConfig.CurrentContext
}
Comment on lines +124 to +128

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Log a warning when context inference fails.

The error from RawConfig() is silently ignored. If this call fails (due to file system changes, library issues, etc.), report.ClusterContext remains empty and the user sees Mode: live (context: ) without explanation, which partially defeats the purpose of this fix.

While Complete() already validates kubeconfig loading at line 38, making failure here unlikely, explicit error handling improves observability and aligns with the coding guidelines. As per coding guidelines, "Prefer explicit error messages with context in Go code" and "Do not skip error context."

📋 Proposed fix to log a warning
 	report.Mode = "live"
 	// Get the actual context being used (either from flag or current-context)
 	rawConfig, err := o.configFlags.ToRawKubeConfigLoader().RawConfig()
-	if err == nil {
+	if err != nil {
+		log.Warnf("Could not determine cluster context from kubeconfig: %v", err)
+	} else {
 		report.ClusterContext = rawConfig.CurrentContext
 	}
 	// Override with explicit --context flag if provided
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Get the actual context being used (either from flag or current-context)
rawConfig, err := o.configFlags.ToRawKubeConfigLoader().RawConfig()
if err == nil {
report.ClusterContext = rawConfig.CurrentContext
}
// Get the actual context being used (either from flag or current-context)
rawConfig, err := o.configFlags.ToRawKubeConfigLoader().RawConfig()
if err != nil {
log.Warnf("Could not determine cluster context from kubeconfig: %v", err)
} else {
report.ClusterContext = rawConfig.CurrentContext
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/validate/validate.go` around lines 124 - 128, The RawConfig() error is
being ignored so report.ClusterContext can stay empty; update the block that
calls o.configFlags.ToRawKubeConfigLoader().RawConfig() to handle the error by
logging a warning that includes the error details (and a brief context message)
when err != nil, and only set report.ClusterContext when RawConfig() succeeds;
reference the RawConfig() call and report.ClusterContext (and keep consistency
with existing logging conventions used elsewhere, e.g., how Complete() reports
kubeconfig issues).

Source: Coding guidelines

// Override with explicit --context flag if provided
if o.configFlags.Context != nil && *o.configFlags.Context != "" {
report.ClusterContext = *o.configFlags.Context
}
Expand Down
Loading