Skip to content

Add operator set-log-level CLI command#2008

Open
kajalpareek-lab wants to merge 1 commit into
noobaa:masterfrom
kajalpareek-lab:kajal/set-operator-log-level-cli
Open

Add operator set-log-level CLI command#2008
kajalpareek-lab wants to merge 1 commit into
noobaa:masterfrom
kajalpareek-lab:kajal/set-operator-log-level-cli

Conversation

@kajalpareek-lab

@kajalpareek-lab kajalpareek-lab commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add nb operator set-log-level <warn|info|debug> to update OPERATOR_LOG_LEVEL in noobaa-config at runtime
  • Provide a CLI equivalent to nb system set-debug-level for operator logging after install
  • Document the new command and its example output in doc/operator-log-level.md

Test plan

  • nb operator set-log-level debug -n <namespace> updates OPERATOR_LOG_LEVEL in noobaa-config
  • nb operator set-log-level warn -n <namespace> reduces operator log noise
  • Invalid level returns a clear CLI error
  • Operator picks up the change on next reconcile without restarting core/endpoint pods
  • oc logs -n <namespace> -l noobaa-operator=deployment -f shows expected verbosity

Summary by CodeRabbit

  • New Features

    • Added an operator set-log-level <level> CLI subcommand supporting warn, info, and debug.
    • Persists the requested log level and confirms it will be applied on the next reconcile cycle without restarting core or endpoint pods.
  • Documentation

    • Updated the operator log-level guide to include an “Or use the CLI” example and a simplified success output (including the nb operator set-log-level debug -n <namespace> command).

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e3f629d1-9ab9-4ae2-b97c-483a9a697289

📥 Commits

Reviewing files that changed from the base of the PR and between 2258bd0 and 7b040ca.

📒 Files selected for processing (2)
  • doc/operator-log-level.md
  • pkg/operator/operator.go
✅ Files skipped from review due to trivial changes (1)
  • doc/operator-log-level.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/operator/operator.go

📝 Walkthrough

Walkthrough

Adds a new operator set-log-level <level> CLI subcommand that validates the log level, updates OPERATOR_LOG_LEVEL in the noobaa-config ConfigMap, and persists it. The documentation now shows the CLI usage and updated example output.

Changes

Set Log Level CLI Command

Layer / File(s) Summary
CLI command implementation and registration
pkg/operator/operator.go
Adds CmdSetLogLevel and RunSetLogLevel, validates input, updates OPERATOR_LOG_LEVEL in noobaa-config, persists the change, and registers the subcommand under operator.
Documentation update for CLI usage
doc/operator-log-level.md
Replaces the detailed example output with CLI usage guidance and a shorter success example noting the change is applied on the next reconcile cycle.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers: dannyzaken, naveenpaul1

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the summary and tests, but it omits the required problem, changes, issues, and testing instruction sections. Reformat it to the template with Describe the Problem, Explain the changes, Issues, Testing Instructions, and the two checkboxes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely matches the main change: adding a new operator set-log-level CLI command.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kajalpareek-lab
kajalpareek-lab force-pushed the kajal/set-operator-log-level-cli branch from 5b8f686 to 2258bd0 Compare July 7, 2026 09:25

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@doc/operator-log-level.md`:
- Around line 75-85: The example output in the operator log level doc uses an
unlabeled fenced block, which will trip markdownlint MD040. Update the second
fenced example under the set-log-level output to use a Bash info tag in the
fence, or remove the fence entirely, so the example remains valid and consistent
with the existing `nb operator set-log-level` snippet.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d73f908e-861f-49f0-a2ae-d233f6724251

📥 Commits

Reviewing files that changed from the base of the PR and between 5b8f686 and 2258bd0.

📒 Files selected for processing (2)
  • doc/operator-log-level.md
  • pkg/operator/operator.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/operator/operator.go

Comment thread doc/operator-log-level.md
@kajalpareek-lab
kajalpareek-lab force-pushed the kajal/set-operator-log-level-cli branch from 2258bd0 to 98fc0d0 Compare July 7, 2026 09:28
Expose a runtime CLI for changing OPERATOR_LOG_LEVEL in noobaa-config,
matching the existing nb system set-debug-level flow for core/endpoints.

Signed-off-by: Kajal Pareek <pareekkajal97@gmail.com>
@kajalpareek-lab
kajalpareek-lab force-pushed the kajal/set-operator-log-level-cli branch from fd5146a to 7b040ca Compare July 7, 2026 09:33
Comment thread doc/operator-log-level.md
-p '{"data":{"OPERATOR_LOG_LEVEL":"info"}}'
```

The operator picks up the change on the next reconcile cycle (no restart needed).

Copy link
Copy Markdown
Contributor

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 need to remove the examples; they were fine.

Comment thread doc/operator-log-level.md

```bash
noobaa-operator operator --operator-log-level=warn
```

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This part is where you need to update.
The CLI in this doc doesn't work noobaa-operator operator --operator-log-level=warn.

Comment thread doc/operator-log-level.md
time="2025-10-10T13:20:54Z" level=info msg="Update event detected for noobaa (openshift-storage), queuing Reconcile"
time="2025-10-10T13:20:54Z" level=info msg="Update event detected for noobaa-default-backing-store (openshift-storage), queuing Reconcile"
```bash
nb operator set-log-level debug -n <namespace>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that in docs they prefer it to be noobaa and not the alias of the binary (if you want, you can add a comment about nb as an alias.

Comment thread doc/operator-log-level.md
time="2025-10-10T13:20:57Z" level=info msg="Delete event detected for noobaa-default-backing-store (openshift-storage), queuing Reconcile"
time="2025-10-10T13:20:57Z" level=debug msg="Generic event detected for noobaa (openshift-storage), queuing Reconcile"
Operator log level was set to "debug" successfully
The operator picks up the change on the next reconcile. Core and endpoint pods are not restarted.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

They are not affected, writing that they are not restarted is confusing.

Comment thread doc/operator-log-level.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need to delete the global --operator-log-level that was added?

Comment thread pkg/operator/operator.go
func CmdSetLogLevel() *cobra.Command {
cmd := &cobra.Command{
Use: "set-log-level <level>",
Short: "Sets the operator log level in noobaa-config. level can be 'warn', 'info', or 'debug'",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can add 'Long` and add additional details.

Comment thread pkg/operator/operator.go
cm.Namespace = options.Namespace
cm.Name = "noobaa-config"

_, _, err := util.KubeGet(cm)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think that usually we use KubeCheck and then you don't need to use blank identifier (_).

Comment thread pkg/operator/operator.go

_, _, err := util.KubeGet(cm)
if err != nil {
log.Fatalf(`❌ ConfigMap "noobaa-config" not found in namespace %q. Create a NooBaa system first.`, options.Namespace)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have the name "noobaa-config" in variable cm.Name; you can reuse it.

Comment thread pkg/operator/operator.go
cm.Data["OPERATOR_LOG_LEVEL"] = level

if !util.KubeUpdate(cm) {
log.Fatal(`❌ Failed to update ConfigMap "noobaa-config"`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You have the name "noobaa-config" in variable cm.Name; you can reuse it.

Comment thread pkg/operator/operator.go

fmt.Println("")
fmt.Printf("Operator log level was set to %q successfully\n", level)
fmt.Println("The operator picks up the change on the next reconcile. Core and endpoint pods are not restarted.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, core and endpoint are not affected, so it is clear that they should not be restarted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants