Skip to content

NETOBSERV-3036: Rewrite plugin in Golang and reorganize collector packages - #605

Open
jpinsonneau wants to merge 7 commits into
netobserv:mainfrom
jpinsonneau:refactor/go-cli-collector
Open

jpinsonneau wants to merge 7 commits into
netobserv:mainfrom
jpinsonneau:refactor/go-cli-collector

Conversation

@jpinsonneau

@jpinsonneau jpinsonneau commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Summary

Rewrite the network-observability CLI from Bash to Go and reorganize the collector around focused packages.

  • Replace the shell kubectl netobserv plugin with a Go/Cobra plugin and typed Kubernetes manifests.
  • Split collector concerns into display, flow, packet, metrics, formatting, lifecycle, transport, cleanup, and Kubernetes packages.
  • Consume the shared capture, pipeline, TLS, monitoring, filter, and dashboard code from the operator.
  • Preserve standalone and managed capture workflows, filters, feature flags, TLS/plaintext packet output, pcap handling, output copy, cleanup, and client-side RBAC.
  • Write flow captures directly as streamed JSON arrays in output/flow/<timestamp>.json and preserve the SQLite .db output.
  • Keep packet captures as .pcapng, with optional decoded TLS plaintext in output/plaintext/<timestamp>.jsonl.
  • Keep managed collector pods available for copying after completion, and finalize flow JSON before completion is reported.
  • Make collector shutdown drain in-flight writes cleanly and avoid closed-database errors or panics.
  • Remove the old line-oriented .txt conversion path.
  • Update build tooling, multi-architecture packaging, documentation, examples, smoke coverage, and Kind E2E coverage.

Related PRs

Dependency

This PR consumes github.com/netobserv/netobserv-operator/pkg/capture from netobserv-operator#2993. The module is pinned to the compatible operator commit until the shared package is released from the canonical repository. The vendored flowlogs-pipeline shutdown behavior is included for safe collector draining.

Validation

  • go test ./...
  • make build, formatting, and golangci-lint
  • Smoke and Kind E2E tests
  • Manual OpenShift validation for flow, packet, and metrics captures, filters, features, TLS plaintext output, dashboard metrics, output retrieval, and cleanup
  • Verified flow output is a valid JSON array of objects, without legacy .txt files

@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch from d4b194a to 2019279 Compare October 14, 2026 15:25
@jpinsonneau jpinsonneau changed the title Rewrite CLI in Go and reorganize collector packages Rewrite plugin in Golang and reorganize collector packages Oct 14, 2026
@jpinsonneau jpinsonneau changed the title Rewrite plugin in Golang and reorganize collector packages NETOBSERV-3036: Rewrite plugin in Golang and reorganize collector packages Oct 14, 2026
@openshift-ci-robot

openshift-ci-robot commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

@jpinsonneau: This pull request references NETOBSERV-3036 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.1.0" version, but no target version was set.

Details

In response to this:

Summary

Rewrite the CLI from Bash/YAML generation to Go, with a focused package layout for the collector and plugin.

Review guide

  • refactor: split collector into focused Go packages

  • Moves collector startup and runtime code under internal/collector.

  • Separates display, flow, packet, metrics, format, lifecycle, transport, and test helpers.

  • Adds shared Kubernetes client, OpenShift, TLS, and Kind configuration packages.

  • refactor: replace shell plugin with Go implementation

  • Replaces the shell/oc exec workflow with a Go client plugin.

  • Builds typed manifests and agent configuration in Go.

  • Adds capture lifecycle, waiting, logs, copy/progress, cleanup, filters, and subnet handling.

  • Removes obsolete shell scripts and legacy resources.

  • build: update tooling, docs, and release packaging

  • Separates collector and plugin build targets while preserving compatibility targets.

  • Adds multi-architecture Krew plugin packaging.

  • Moves devtools to Go and updates E2E setup, documentation, and examples.

Validation

  • Unit tests, lint, vet, collector/plugin builds, smoke tests, and E2E tests pass.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch 3 times, most recently from b0b652c to 8649969 Compare October 15, 2026 15:59
@github-actions

Copy link
Copy Markdown

New image:

quay.io/netobserv/network-observability-cli:86499694

It will expire in two weeks.

To use this build, update your commands using:

USER=netobserv VERSION=86499694 make commands

or download the updated commands.

@codecov

codecov Bot commented Oct 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.75174% with 2475 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.78%. Comparing base (39d3f1d) to head (8649969).

Files with missing lines Patch % Lines
internal/collector/format/table_protocol.go 3.93% 317 Missing ⚠️
internal/plugin/commands/run.go 0.00% 212 Missing ⚠️
internal/plugin/capture/exec.go 0.00% 106 Missing ⚠️
internal/collector/metrics_screen.go 35.00% 98 Missing and 6 partials ⚠️
internal/plugin/commands/helpers.go 11.92% 96 Missing ⚠️
internal/collector/flow_table.go 39.31% 82 Missing and 6 partials ⚠️
internal/collector/capture_packet.go 34.21% 67 Missing and 8 partials ⚠️
internal/collector/flow_screen.go 53.37% 58 Missing and 11 partials ⚠️
internal/plugin/commands/packets.go 29.88% 61 Missing ⚠️
cmd/devtools/gendocs/main.go 0.00% 60 Missing ⚠️
... and 71 more
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #605       +/-   ##
===========================================
+ Coverage   35.05%   46.78%   +11.72%     
===========================================
  Files          29       93       +64     
  Lines        4082     5966     +1884     
===========================================
+ Hits         1431     2791     +1360     
- Misses       2498     2892      +394     
- Partials      153      283      +130     
Flag Coverage Δ
unittests 46.78% <47.75%> (+11.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
internal/collector/commands.go 75.00% <100.00%> (ø)
internal/collector/display/options.go 100.00% <100.00%> (ø)
internal/collector/format/plaintext_decode.go 57.04% <100.00%> (ø)
internal/collector/packet/plaintext.go 83.07% <100.00%> (ø)
internal/collector/transport/tls.go 90.00% <100.00%> (ø)
internal/k8s/tls/config.go 85.00% <ø> (ø)
internal/k8s/tls/resolve.go 43.85% <ø> (ø)
internal/plugin/manifests/configmap.go 100.00% <100.00%> (ø)
internal/plugin/manifests/namespace.go 100.00% <ø> (ø)
internal/plugin/manifests/pipeline.go 50.00% <ø> (ø)
... and 83 more

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch from 926a69c to 8649969 Compare October 22, 2026 09:34
@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch from 9219616 to a8e8f46 Compare October 23, 2026 14:49
@jpinsonneau jpinsonneau changed the title NETOBSERV-3036: Rewrite plugin in Golang and reorganize collector packages refactor: rewrite CLI and split collector packages Oct 23, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Collaborator

@jpinsonneau: No Jira issue is referenced in the title of this pull request.
To reference a jira issue, add 'XYZ-NNN:' to the title of this pull request and request another refresh with /jira refresh.

Details

In response to this:

Summary

Rewrite the CLI from Bash to Go and reorganize the collector while consuming the shared capture package from the operator repository.

Review commits in order:

  • Split the collector into focused display, flow, packet, metrics, formatting, lifecycle, and transport packages.
  • Replaced the shell plugin with a Go/Cobra implementation using typed Kubernetes resources and generated Go manifests.
  • Added collector TUI, PTY, smoke, and E2E coverage.
  • Updated build tooling, multi-architecture packaging, documentation, and examples.
  • Hardened capture lifecycle behavior, including pcap flushing, TLS setup, cleanup progress, and CLI RBAC.
  • Integrated the shared capture, pipeline, TLS, dashboard, monitoring, and filter code from the operator repository.

Dependency

This PR consumes the shared public package introduced by netobserv-operator#2993. The operator PR should merge first; the CLI module currently points to its pinned commit until that package is released.

Validation

  • Vendored unit tests
  • Lint and collector/plugin builds
  • Smoke and Kind E2E tests
  • Manual OpenShift 4.22 validation for flows, packets, metrics, filters, TLS, and FlowCapture interoperability

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jpinsonneau jpinsonneau changed the title refactor: rewrite CLI and split collector packages NETOBSERV-3036: Rewrite plugin in Golang and reorganize collector packages Oct 23, 2026
@openshift-ci-robot

openshift-ci-robot commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

@jpinsonneau: This pull request references NETOBSERV-3036 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the story to target the "5.1.0" version, but no target version was set.

Details

In response to this:

Summary

Rewrite the CLI from Bash to Go and reorganize the collector while consuming the shared capture package from the operator repository.

Review commits in order:

  • Split the collector into focused display, flow, packet, metrics, formatting, lifecycle, and transport packages.
  • Replaced the shell plugin with a Go/Cobra implementation using typed Kubernetes resources and generated Go manifests.
  • Added collector TUI, PTY, smoke, and E2E coverage.
  • Updated build tooling, multi-architecture packaging, documentation, and examples.
  • Hardened capture lifecycle behavior, including pcap flushing, TLS setup, cleanup progress, and CLI RBAC.
  • Integrated the shared capture, pipeline, TLS, dashboard, monitoring, and filter code from the operator repository.

Dependency

This PR consumes the shared public package introduced by netobserv-operator#2993. The operator PR should merge first; the CLI module currently points to its pinned commit until that package is released.

Validation

  • Vendored unit tests
  • Lint and collector/plugin builds
  • Smoke and Kind E2E tests
  • Manual OpenShift 4.22 validation for flows, packets, metrics, filters, TLS, and FlowCapture interoperability

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci

openshift-ci Bot commented Oct 23, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign jotak for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jpinsonneau jpinsonneau added the needs-review Tells that the PR needs a review label Oct 29, 2026
@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch 2 times, most recently from 86b5f10 to 6d058e7 Compare November 2, 2026 17:27
@openshift-ci

openshift-ci Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

@jpinsonneau: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/integration-tests da7b2b6 link true /test integration-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

New image:

quay.io/netobserv/network-observability-cli:b52d4de0

It will expire in two weeks.

To use this build, update your commands using:

USER=netobserv VERSION=b52d4de0 make commands

or download the updated commands.

Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
@github-actions

Copy link
Copy Markdown

New image:

quay.io/netobserv/network-observability-cli:228bad0a

It will expire in two weeks.

To use this build, update your commands using:

USER=netobserv VERSION=228bad0a make commands

or download the updated commands.

@leandroberetta leandroberetta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @jpinsonneau ! I did a first review, I left some comments below.

startFlowCollector()
return
}
go startFlowCollector()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When pressing Ctrl+C, the UI stops and this function returns while the flow collector is still running. That leaves the JSON file without its closing ], since the collector doesn’t get to run its deferred cleanup. I tried it locally and could reproduce it consistently.

Could we stop the collector and wait for it to finish writing and close its files before returning here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ctrl+C: Fixed; shutdown now stops the collector and waits for JSON/DB cleanup before returning.

}

// EnablePacketDrops replaces the --enable_pkt_drop branch of parse_args (privileged + env var).
func (b *Builder) EnablePacketDrops() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These feature methods enable the environment variables, but the corresponding host mounts seem to be missing. Packet drops need /sys/kernel/debug, and network events and UDN mapping need the OVN/OVS directories.

The shared builder adds those mounts when it receives the features, but we currently create the DaemonSet without them. Could we pass the enabled features to the shared builder, or add the required mounts here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added idempotent mounts for debugfs, OVN/OVS, and network namespaces.

},
}
if openShift {
scc := &securityv1.SecurityContextConstraints{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this SCC need to allow hostPID and SYS_PTRACE for OpenSSL captures? --enable_openssl requests both, but they aren't allowed here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added hostPID and SYS_PTRACE. Thanks !

return err
}
if capOpts.outputYAML {
printYAMLInstructions(r.out, kind)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The generated file includes the agents and collector Service, but no collector Pod, I think we need to add the pod creation too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

YAML output now includes a collector Pod manifest.

// Flow-filter flags (--protocol, --port, ...) and the bare "or" separator are handled by
// splitFilterArgs/applyFilterGroups from the explicit argv snapshot, not registered on
// this FlagSet (see filters.go) — so Cobra must not error on them as "unknown flag".
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Allowing unknown flags makes sense here for the custom filter parser. Could we validate the remaining arguments afterward, though? For example, flows --protcol=TCP currently succeeds without applying any protocol filter, since Cobra allows it and splitFilterArgs leaves it in the discarded remainder.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Remaining unrecognized options now fail instead of being silently ignored.


// prepareBuilder replaces the handful of edit_manifest calls setup() makes itself (as opposed to
// parse_args' flag-driven ones, already applied by the caller): node selector, TLS, subnets.
func (r *captureRun) prepareBuilder() error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we also call r.builder.SetLogLevel(r.capOpts.logLevel) here? Currently, --log-level=debug is passed to the collector, but the agents keep LOG_LEVEL=info. I noticed this in the generated YAML, and the flag description says it configures both.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Agent configuration now receives the requested --log-level.

enableAll bool
}

func registerFlowMetricsFlags(cmd *cobra.Command, f *flowMetricsFlags) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we preserve --enable_secondary_networks as part of this rewrite? The previous implementation enabled secondary-network capture, mounted /var/run/netns, and added SYS_ADMIN. It was also enabled by --enable_all and --privileged.

I couldn't find the equivalent configuration here. Passing the flag currently succeeds, but it doesn't enable secondary-network capture.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Restored --enable_secondary_networks, including /var/run/[netns](https://github.com/var/run/netns), SYS_ADMIN, and the legacy --privileged behavior.

Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
@jpinsonneau
jpinsonneau force-pushed the refactor/go-cli-collector branch from 6179f2a to 4ec1f25 Compare November 30, 2026 09:39
@jpinsonneau

Copy link
Copy Markdown
Member Author

Thanks for the feedback @leandroberetta ! Good catches !

Signed-off-by: Julien Pinsonneau <jpinsonn@redhat.com>
@openshift-ci

openshift-ci Bot commented Dec 4, 2026

Copy link
Copy Markdown

PR needs rebase.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

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.

4 participants