Skip to content

Commit

Permalink
Allow user to get version without a server
Browse files Browse the repository at this point in the history
  • Loading branch information
jmckulk committed Jan 23, 2024
1 parent 857b133 commit b2766b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/content/reference/pgo_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Operator Version: v5.5.0
### Options

```
-h, --help help for version
--client If true, shows client version only (no server required).
-h, --help help for version
```

### Options inherited from parent commands
Expand Down
6 changes: 6 additions & 0 deletions internal/cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func newVersionCommand(config *internal.Config) *cobra.Command {
// No arguments for 'version'
cmd.Args = cobra.NoArgs

var clientOnly bool
cmd.Flags().BoolVar(&clientOnly, "client", false, "If true, shows client version only (no server required).")

cmd.Example = internal.FormatExample(fmt.Sprintf(`# Request the version of the client and the operator
pgo version
Expand All @@ -57,6 +60,9 @@ Operator Version: v5.5.0`, clientVersion))
cmd.RunE = func(cmd *cobra.Command, args []string) error {

cmd.Printf("Client Version: %s\n", clientVersion)
if clientOnly {
return nil
}

ctx := context.Background()
restConfig, err := config.ToRESTConfig()
Expand Down
22 changes: 22 additions & 0 deletions testing/kuttl/e2e/version/01--check-client-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
VERSION_OUTPUT=$(kubectl pgo version --client)
CLI_VERSION=$(kubectl pgo version --client | awk '{print $3}')
# the CLI version isn't empty and the CLI version output follows the expected format
if [ -z "$CLI_VERSION" ]; then
echo "Client version output is empty."
exit 1
fi
case "${VERSION_OUTPUT}" in
*"Client Version: "*)
;;
*)
echo "Version output is: "
echo "$VERSION_OUTPUT"
exit 1
;;
esac

0 comments on commit b2766b1

Please sign in to comment.