Skip to content

Conversation

@FalcoSuessgott
Copy link
Contributor

@FalcoSuessgott FalcoSuessgott commented Oct 1, 2025

This PR prints out the kagent version even if a port-forwarding to the kagent server fails. In case the port-forwarding does not succeed, the unavailable versions will be marked as <unknown>:

Fixes: #868
Related to: #879

> go run cli/cmd/kagent/main.go version
Error starting port-forward: failed to establish connection to kagent-controller. error connecting to server. Please run 'install' command first
{"backend_version":"unknown","build_date":"unknown","git_commit":"none","kagent_version":"dev"}

Note: We might can consider removing the error message as it breaks the json output ...

Furthermore:

  • This PR uses cmd.Context() consistently throughout all kagent subcommands.
  • It adds a help Makefile target for a neat list of available Makefile targets
> make
controller-gen                 Download controller-gen locally if necessary.
envtest                        Download setup-envtest locally if necessary.
fmt                            Run go fmt against code.
generate                       Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
golangci-lint                  Download golangci-lint locally if necessary.
help                           list makefile targets
lint-config                    Verify golangci-lint linter configuration
lint-fix                       Run golangci-lint linter and perform fixes
lint                           Run golangci-lint linter
manifests                      Generate ClusterRole and CustomResourceDefinition objects.
run                            Run a controller from your host.
setup-envtest                  Download the binaries required for ENVTEST in the local bin directory.
vet                            Run go vet against code.

Copilot AI review requested due to automatic review settings October 1, 2025 02:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the version command to print the kagent CLI version regardless of whether port-forwarding to the kagent server succeeds. The changes ensure version information is always displayed, with remote versions reported as "unknown" when unavailable.

  • Modified version command to use defer for version printing, ensuring it always executes
  • Updated all port-forwarding operations to use cmd.Context() instead of a global context variable
  • Added a help target to the Makefile

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
go/cli/cmd/kagent/main.go Fixed version command to always print version info and updated context usage throughout CLI commands
go/Makefile Added default help target for listing makefile targets

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@FalcoSuessgott FalcoSuessgott force-pushed the version-fix branch 2 times, most recently from 6d9b95f to 3a235d4 Compare October 1, 2025 06:18
@FalcoSuessgott FalcoSuessgott changed the title fix(version): print out version regardless of port-forwarding fix(version): print out version regardless of port-forwarding; pass through contexts Oct 1, 2025
@EItanya EItanya merged commit d6d3660 into kagent-dev:main Oct 6, 2025
16 checks passed
supreme-gg-gg pushed a commit to supreme-gg-gg/kagent that referenced this pull request Oct 7, 2025
…hrough contexts (kagent-dev#980)

This PR prints out the `kagent` version even if a port-forwarding to the
`kagent` server fails. In case the port-forwarding does not succeed, the
unavailable versions will be marked as `<unknown>`:

Fixes: kagent-dev#868
Related to: kagent-dev#879
```sh
> go run cli/cmd/kagent/main.go version
Error starting port-forward: failed to establish connection to kagent-controller. error connecting to server. Please run 'install' command first
{"backend_version":"unknown","build_date":"unknown","git_commit":"none","kagent_version":"dev"}
```

~~**Note:** We might can consider removing the error message as it
breaks the `json` output ...~~


Furthermore: 
- This PR uses `cmd.Context()` consistently throughout all `kagent`
subcommands.
- It adds a `help` Makefile target for a neat list of available Makefile
targets

```sh
> make
controller-gen                 Download controller-gen locally if necessary.
envtest                        Download setup-envtest locally if necessary.
fmt                            Run go fmt against code.
generate                       Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
golangci-lint                  Download golangci-lint locally if necessary.
help                           list makefile targets
lint-config                    Verify golangci-lint linter configuration
lint-fix                       Run golangci-lint linter and perform fixes
lint                           Run golangci-lint linter
manifests                      Generate ClusterRole and CustomResourceDefinition objects.
run                            Run a controller from your host.
setup-envtest                  Download the binaries required for ENVTEST in the local bin directory.
vet                            Run go vet against code.
```

Signed-off-by: Tom Morelly <[email protected]>
jmhbh pushed a commit to jmhbh/kagent that referenced this pull request Oct 10, 2025
…hrough contexts (kagent-dev#980)

This PR prints out the `kagent` version even if a port-forwarding to the
`kagent` server fails. In case the port-forwarding does not succeed, the
unavailable versions will be marked as `<unknown>`:

Fixes: kagent-dev#868
Related to: kagent-dev#879
```sh
> go run cli/cmd/kagent/main.go version
Error starting port-forward: failed to establish connection to kagent-controller. error connecting to server. Please run 'install' command first
{"backend_version":"unknown","build_date":"unknown","git_commit":"none","kagent_version":"dev"}
```

~~**Note:** We might can consider removing the error message as it
breaks the `json` output ...~~


Furthermore: 
- This PR uses `cmd.Context()` consistently throughout all `kagent`
subcommands.
- It adds a `help` Makefile target for a neat list of available Makefile
targets

```sh
> make
controller-gen                 Download controller-gen locally if necessary.
envtest                        Download setup-envtest locally if necessary.
fmt                            Run go fmt against code.
generate                       Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
golangci-lint                  Download golangci-lint locally if necessary.
help                           list makefile targets
lint-config                    Verify golangci-lint linter configuration
lint-fix                       Run golangci-lint linter and perform fixes
lint                           Run golangci-lint linter
manifests                      Generate ClusterRole and CustomResourceDefinition objects.
run                            Run a controller from your host.
setup-envtest                  Download the binaries required for ENVTEST in the local bin directory.
vet                            Run go vet against code.
```

Signed-off-by: Tom Morelly <[email protected]>
@marcinkubica
Copy link
Contributor

cheers for this one @FalcoSuessgott

I'm getting on mac m4, not sure if expected

 kagent version
{"backend_version":"unknown","build_date":"2025-10-08","git_commit":"7a264e9","kagent_version":"0.6.19"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x8 pc=0x101b90ffc]

goroutine 1 [running]:
github.com/kagent-dev/kagent/go/cli/internal/cli/agent.(*PortForward).Stop(0x0)
	/home/runner/work/kagent/kagent/go/cli/internal/cli/agent/utils.go:70 +0x1c
main.main.func7(0x14000788f08, {0x101d11703?, 0x4?, 0x101d11707?})
	/home/runner/work/kagent/kagent/go/cli/cmd/kagent/main.go:128 +0xcc
github.com/spf13/cobra.(*Command).execute(0x14000788f08, {0x1036c7340, 0x0, 0x0})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1019 +0x7bc
github.com/spf13/cobra.(*Command).ExecuteC(0x14000788008)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1148 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1071
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1064
main.main()
	/home/runner/work/kagent/kagent/go/cli/cmd/kagent/main.go:336 +0x11b4

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.

[BUG] cli: kagent version should not fail when controller is unavailable

3 participants