Skip to content

update mw client doc and build cli#487

Merged
clyang82 merged 1 commit intoopenshift-online:mainfrom
skeeey:cli
Feb 12, 2026
Merged

update mw client doc and build cli#487
clyang82 merged 1 commit intoopenshift-online:mainfrom
skeeey:cli

Conversation

@skeeey
Copy link
Contributor

@skeeey skeeey commented Feb 12, 2026

No description provided.

Signed-off-by: Wei Liu <liuweixa@redhat.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

Walkthrough

The changes introduce a new maestro-cli build target and add verbose logging support to the client. Documentation is updated to reflect KinD-based deployment instructions and CLI binary usage patterns across examples.

Changes

Cohort / File(s) Summary
CLI Build Configuration
.gitignore, Makefile
Added /maestro-cli to gitignore and introduced new .PHONY build target maestro-cli that compiles ./examples/manifestwork/client.go into a binary.
Documentation Updates
README.md, examples/manifestwork/README.md
Replaced local environment guidance with KinD cluster setup instructions; reorganized manifestwork examples to include filtering, label selectors, and pagination with metav1.ListOptions; updated all CLI invocations from go run to ./maestro-cli binary references; added explicit build and usage sections.
Client Implementation
examples/manifestwork/client.go
Integrated verbose logging via klog/logr dependency; added verbose flag to control logging verbosity; initialized klog flags to prevent duplicate registration; expanded usage/help text with categorized flag sections and updated CLI naming.
Dependency Management
go.mod
Moved github.com/go-logr/logr v1.4.3 from indirect to direct dependency requirement.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess whether the description relates to the changeset. Add a pull request description explaining the changes, such as why the documentation was updated, how the new CLI binary is used, and any setup/build instructions.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'update mw client doc and build cli' clearly summarizes the main changes: updating ManifestWork client documentation and adding a CLI build target.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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

Copy link

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
examples/manifestwork/README.md (1)

265-278: ⚠️ Potential issue | 🟡 Minor

Remove shell prompt $ to satisfy markdownlint MD014.

The lint warning is triggered by $ without output; consider removing the prompt marker for command-only blocks.

Example fix
-   $ cat << EOF | kubectl apply -f -
+   cat << EOF | kubectl apply -f -
🤖 Fix all issues with AI agents
In `@examples/manifestwork/client.go`:
- Around line 87-99: The custom argument parsing loop uses
flag.CommandLine.Lookup() before klog flags are registered, so user klog flags
(e.g. -v 4) get mis-parsed; move the klog flag initialization call
(klog.InitFlags(nil)) and any check for existing klog flags
(flag.CommandLine.Lookup("alsologtostderr")) to run before the custom argument
parsing loop, ensuring all klog flags are discoverable, then proceed to parse
otherArgs and apply the verbose handling (flag.Set("v", "...") /
klog.SetLogger(logr.Discard())) as currently implemented.
🧹 Nitpick comments (2)
Makefile (1)

192-194: Add maestro-cli to clean to avoid stale binaries.

The new target produces ./maestro-cli, but clean doesn’t remove it. Consider cleaning it alongside other build artifacts.

Proposed update to clean target
 clean:
 	rm -rf \
 		$(binary) \
+		maestro-cli \
 		data/generated/openapi/*.json \
examples/manifestwork/client.go (1)

175-201: Keep usage strings consistent across the CLI.

Since printUsage now advertises maestro-cli, consider updating the log.Fatalf("usage: client.go ...") strings to match.

Example consistency update (outside this block)
- log.Fatalf("usage: client.go get <work-name>")
+ log.Fatalf("usage: maestro-cli get <work-name>")

Comment on lines +87 to +99
// check if the klog flag is already registered to avoid duplicate flag define error
if flag.CommandLine.Lookup("alsologtostderr") == nil {
klog.InitFlags(nil)
}
flag.CommandLine.Parse(otherArgs)

// Configure klog based on verbose flag
if *verbose {
flag.Set("v", "4")
} else {
// Completely disable klog output by setting a discard logger
klog.SetLogger(logr.Discard())
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

find . -name "client.go" -path "*/manifestwork/*"

Repository: openshift-online/maestro

Length of output: 101


🏁 Script executed:

cat -n examples/manifestwork/client.go | head -120

Repository: openshift-online/maestro

Length of output: 4931


🏁 Script executed:

cat > /tmp/test_flags.go << 'EOF'
package main

import (
	"flag"
	"fmt"
	"k8s.io/klog/v2"
)

func main() {
	// Before registering klog flags
	fmt.Println("Before klog.InitFlags:")
	v := flag.CommandLine.Lookup("v")
	fmt.Printf("  flag.Lookup(\"v\"): %v\n", v)

	// Register klog flags
	klog.InitFlags(nil)

	// After registering klog flags
	fmt.Println("After klog.InitFlags:")
	v = flag.CommandLine.Lookup("v")
	fmt.Printf("  flag.Lookup(\"v\"): %v\n", v)
}
EOF

Repository: openshift-online/maestro

Length of output: 50


🏁 Script executed:

cat > /tmp/analyze_parsing.py << 'EOF'
# Simulate the custom argument parsing logic
import sys

def simulate_parsing(os_args):
    """Simulate the custom parsing loop from the code"""
    command = ""
    commandArgs = []
    otherArgs = []
    
    # Simulate registered flags (before klog.InitFlags)
    registered_flags = {
        "source", "maestro-server", "grpc-server", "grpc-server-ca-file",
        "grpc-client-cert-file", "grpc-client-key-file", "grpc-client-token-file",
        "consumer-name", "server-healthiness-timeout", "print-work-details",
        "insecure-skip-verify", "verbose"
    }
    
    i = 0
    while i < len(os_args):
        arg = os_args[i]
        
        if arg.startswith("-"):
            # Keep the flag token itself
            otherArgs.append(arg)
            
            # Check if flag has a value
            if "=" not in arg and i + 1 < len(os_args) and not os_args[i + 1].startswith("-"):
                name = arg.lstrip("-")
                # Simulate flag.CommandLine.Lookup
                if name in registered_flags:
                    # For simplicity, assume all are not bool flags (except print-work-details, verbose, insecure-skip-verify)
                    bool_flags = {"print-work-details", "verbose", "insecure-skip-verify"}
                    if name not in bool_flags:
                        i += 1
                        otherArgs.append(os_args[i])
                # If flag NOT in registered_flags, don't consume next arg
        else:
            if command == "":
                command = arg
            else:
                commandArgs.append(arg)
        
        i += 1
    
    return command, commandArgs, otherArgs

# Test with "-v 4" (klog flag, not in registered_flags)
print("Test 1: User passes '-v 4' (klog flag not yet registered)")
os_args = ["prog", "-v", "4", "watch"]
cmd, cmdargs, otherargs = simulate_parsing(os_args)
print(f"  os.Args: {os_args}")
print(f"  command: {cmd}")
print(f"  commandArgs: {cmdargs}")
print(f"  otherArgs: {otherargs}")
print(f"  Problem: '4' was treated as command instead of value for '-v'!")
print()

# Test with "-verbose" (custom flag, registered)
print("Test 2: User passes '-verbose true' (custom flag, registered)")
os_args = ["prog", "-verbose", "true", "watch"]
cmd, cmdargs, otherargs = simulate_parsing(os_args)
print(f"  os.Args: {os_args}")
print(f"  command: {cmd}")
print(f"  commandArgs: {cmdargs}")
print(f"  otherArgs: {otherargs}")
print(f"  Correct: '-verbose' and 'true' both in otherArgs")
EOF
python /tmp/analyze_parsing.py

Repository: openshift-online/maestro

Length of output: 534


🏁 Script executed:

python /tmp/analyze_parsing.py

Repository: openshift-online/maestro

Length of output: 534


Move klog flag initialization before the custom argument parsing loop.

The custom argument parsing uses flag.CommandLine.Lookup() to detect whether a flag takes a value. Since klog flags are not registered until line 89, user-provided klog flags like -v 4 will be incorrectly parsed—the value 4 will be treated as a command instead of the flag's argument. Initialize klog flags before the parsing loop to ensure all flags are discoverable.

Suggested adjustment
 func main() {
+	// Register klog flags before custom parsing
+	if flag.CommandLine.Lookup("alsologtostderr") == nil {
+		klog.InitFlags(nil)
+	}
+
 	// Custom argument parsing to allow flags anywhere
 	var command string
 	var commandArgs []string
 	var otherArgs []string
@@
-	// Parse flags
-	// check if the klog flag is already registered to avoid duplicate flag define error
-	if flag.CommandLine.Lookup("alsologtostderr") == nil {
-		klog.InitFlags(nil)
-	}
+	// Parse flags
 	flag.CommandLine.Parse(otherArgs)
🤖 Prompt for AI Agents
In `@examples/manifestwork/client.go` around lines 87 - 99, The custom argument
parsing loop uses flag.CommandLine.Lookup() before klog flags are registered, so
user klog flags (e.g. -v 4) get mis-parsed; move the klog flag initialization
call (klog.InitFlags(nil)) and any check for existing klog flags
(flag.CommandLine.Lookup("alsologtostderr")) to run before the custom argument
parsing loop, ensuring all klog flags are discoverable, then proceed to parse
otherArgs and apply the verbose handling (flag.Set("v", "...") /
klog.SetLogger(logr.Discard())) as currently implemented.

@skeeey
Copy link
Contributor Author

skeeey commented Feb 12, 2026

/cc @clyang82

.PHONY: binary

maestro-cli:
${GO} build $(BUILD_OPTS) -o maestro-cli ./examples/manifestwork/client.go
Copy link
Contributor

Choose a reason for hiding this comment

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

can we support cloudevents as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there may be some gap in get/list/watch if we support both, I think we can think this later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe a unify client for resources

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. Let us think over

Copy link
Contributor

@clyang82 clyang82 left a comment

Choose a reason for hiding this comment

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

LGTM

@clyang82 clyang82 merged commit 0154ff4 into openshift-online:main Feb 12, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants