-
Notifications
You must be signed in to change notification settings - Fork 7
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
Introduce --debug option; fix $patch=delete #31
Conversation
WalkthroughThe pull request introduces a new Changes
Sequence DiagramsequenceDiagram
participant User
participant CLI
participant Engine
participant Cluster
User->>CLI: Run command with --debug flag
CLI->>Engine: Configure Options with Debug=true
Engine->>Cluster: Apply Patches
Engine-->>User: Output detailed debug information
Poem
Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
pkg/commands/apply.go
(4 hunks)pkg/commands/root.go
(1 hunks)pkg/commands/template.go
(4 hunks)pkg/engine/engine.go
(10 hunks)
🔇 Additional comments (12)
pkg/commands/root.go (1)
43-43
: LGTM!The addition of the
Debug
field toTemplateOptions
follows the existing pattern and is properly tagged for YAML serialization.pkg/commands/apply.go (4)
32-32
: LGTM!The addition of the
debug
flag toapplyCmdFlags
follows the existing pattern.
58-60
: LGTM!The
PreRunE
check for the debug flag is properly implemented, ensuring consistency with the configuration.
95-95
: LGTM!The debug option is correctly passed to the engine options.
197-197
: LGTM!The flag initialization is properly implemented with a clear description.
pkg/commands/template.go (4)
35-35
: LGTM!The addition of the
debug
flag totemplateCmdFlags
maintains consistency withapply.go
.
68-70
: LGTM!The
PreRunE
check for the debug flag is properly implemented, ensuring consistency with the configuration.
206-206
: LGTM!The debug option is correctly passed to the engine options.
242-242
: LGTM!The flag initialization is properly implemented with a clear description.
pkg/engine/engine.go (3)
50-50
: LGTM!The addition of the
Debug
field toOptions
follows the existing pattern.
268-268
: Address the TODO comment.The TODO comment should be replaced with proper error handling or removed if no longer needed.
Let's check if there are similar patterns in the codebase:
467-468
: Verify the impact of patch application changes.The patch application logic has been modified to use machine type-specific flags. Please verify that this change aligns with the PR objective to "fix $patch=delete".
Let's check for related changes and tests:
// debugPhase is a unified debug function that prints debug information based on the given stage and context, | ||
// then exits the program. | ||
func debugPhase(opts Options, patches []string, clusterName string, clusterEndpoint string, mType machine.Type) { | ||
phase := 2 | ||
if clusterName == "" { | ||
clusterName = "dummy" | ||
phase = 1 | ||
} | ||
if clusterEndpoint == "" { | ||
clusterEndpoint = "clusterEndpoint" | ||
phase = 1 | ||
} | ||
|
||
fmt.Printf( | ||
"# DEBUG(phase %d): talosctl gen config %s %s -t %s --with-secrets=%s --talos-version=%s --kubernetes-version=%s -o -", | ||
phase, clusterName, clusterEndpoint, mType, | ||
opts.WithSecrets, opts.TalosVersion, opts.KubernetesVersion, | ||
) | ||
|
||
patchOption := "--config-patch-control-plane" | ||
if mType == machine.TypeWorker { | ||
patchOption = "--config-patch-worker" | ||
} | ||
|
||
// Print patches | ||
for _, patch := range patches { | ||
if string(patch[0]) == "@" { | ||
// Apply patch is always one | ||
fmt.Printf(" %s=%s\n", patchOption, patch) | ||
} else { | ||
fmt.Printf("\n---") | ||
fmt.Printf("\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch) | ||
} | ||
} | ||
|
||
os.Exit(0) | ||
} |
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.
🛠️ Refactor suggestion
Consider making the debug output less disruptive.
The debugPhase
function currently exits the program using os.Exit(0)
, which could be disruptive to the application flow. Consider:
- Making the exit behavior configurable
- Returning the debug information instead of printing directly
- Using a logger interface for better control over output
This would make the debug functionality more flexible and less intrusive.
-func debugPhase(opts Options, patches []string, clusterName string, clusterEndpoint string, mType machine.Type) {
+func debugPhase(opts Options, patches []string, clusterName string, clusterEndpoint string, mType machine.Type) string {
phase := 2
if clusterName == "" {
clusterName = "dummy"
phase = 1
}
if clusterEndpoint == "" {
clusterEndpoint = "clusterEndpoint"
phase = 1
}
- fmt.Printf(
+ output := fmt.Sprintf(
"# DEBUG(phase %d): talosctl gen config %s %s -t %s --with-secrets=%s --talos-version=%s --kubernetes-version=%s -o -",
phase, clusterName, clusterEndpoint, mType,
opts.WithSecrets, opts.TalosVersion, opts.KubernetesVersion,
)
patchOption := "--config-patch-control-plane"
if mType == machine.TypeWorker {
patchOption = "--config-patch-worker"
}
// Print patches
for _, patch := range patches {
if string(patch[0]) == "@" {
- fmt.Printf(" %s=%s\n", patchOption, patch)
+ output += fmt.Sprintf(" %s=%s\n", patchOption, patch)
} else {
- fmt.Printf("\n---")
- fmt.Printf("\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch)
+ output += fmt.Sprintf("\n---\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch)
}
}
- os.Exit(0)
+ return output
}
📝 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.
// debugPhase is a unified debug function that prints debug information based on the given stage and context, | |
// then exits the program. | |
func debugPhase(opts Options, patches []string, clusterName string, clusterEndpoint string, mType machine.Type) { | |
phase := 2 | |
if clusterName == "" { | |
clusterName = "dummy" | |
phase = 1 | |
} | |
if clusterEndpoint == "" { | |
clusterEndpoint = "clusterEndpoint" | |
phase = 1 | |
} | |
fmt.Printf( | |
"# DEBUG(phase %d): talosctl gen config %s %s -t %s --with-secrets=%s --talos-version=%s --kubernetes-version=%s -o -", | |
phase, clusterName, clusterEndpoint, mType, | |
opts.WithSecrets, opts.TalosVersion, opts.KubernetesVersion, | |
) | |
patchOption := "--config-patch-control-plane" | |
if mType == machine.TypeWorker { | |
patchOption = "--config-patch-worker" | |
} | |
// Print patches | |
for _, patch := range patches { | |
if string(patch[0]) == "@" { | |
// Apply patch is always one | |
fmt.Printf(" %s=%s\n", patchOption, patch) | |
} else { | |
fmt.Printf("\n---") | |
fmt.Printf("\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch) | |
} | |
} | |
os.Exit(0) | |
} | |
// debugPhase is a unified debug function that prints debug information based on the given stage and context, | |
// then exits the program. | |
func debugPhase(opts Options, patches []string, clusterName string, clusterEndpoint string, mType machine.Type) string { | |
phase := 2 | |
if clusterName == "" { | |
clusterName = "dummy" | |
phase = 1 | |
} | |
if clusterEndpoint == "" { | |
clusterEndpoint = "clusterEndpoint" | |
phase = 1 | |
} | |
output := fmt.Sprintf( | |
"# DEBUG(phase %d): talosctl gen config %s %s -t %s --with-secrets=%s --talos-version=%s --kubernetes-version=%s -o -", | |
phase, clusterName, clusterEndpoint, mType, | |
opts.WithSecrets, opts.TalosVersion, opts.KubernetesVersion, | |
) | |
patchOption := "--config-patch-control-plane" | |
if mType == machine.TypeWorker { | |
patchOption = "--config-patch-worker" | |
} | |
// Print patches | |
for _, patch := range patches { | |
if string(patch[0]) == "@" { | |
output += fmt.Sprintf(" %s=%s\n", patchOption, patch) | |
} else { | |
output += fmt.Sprintf("\n---\n# DEBUG(phase %d): %s=\n%s", phase, patchOption, patch) | |
} | |
} | |
return output | |
} |
Summary by CodeRabbit
Release Notes
New Features
--debug
flag toapply
andtemplate
commandsImprovements
Configuration
debug
option available in configuration files and command-line arguments