Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to get version without a server #95

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
43 changes: 12 additions & 31 deletions testing/kuttl/e2e/version/00--check-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,26 @@ apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
VERSION_OUTPUT=$(kubectl pgo version)
CLI_VERSION=$(kubectl pgo version | awk '{print $3}')
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }

# 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."
VERSION_OUTPUT=$(kubectl pgo version)
{ contains "${VERSION_OUTPUT}" "Client Version:"; } || {
echo "Expected: Client Version:*"
echo "Actual: ${VERSION_OUTPUT}"
exit 1
fi

case "${VERSION_OUTPUT}" in
*"Client Version: "*)
;;
*)
echo "Version output is: "
echo "$VERSION_OUTPUT"
exit 1
;;
esac
}
- script: |
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }

OPERATOR_VERSION=$(
kubectl get crd postgresclusters.postgres-operator.crunchydata.com \
-o go-template='{{ index .metadata.labels "app.kubernetes.io/version" }}'
)

VERSION_OUTPUT=$(kubectl pgo version)

# the operator version isn't empty and the version output matches the CRD value
if [ -z "$OPERATOR_VERSION" ]; then
echo "Operator version output is empty."
{ contains "${VERSION_OUTPUT}" "Operator Version: v${OPERATOR_VERSION}"; } || {
echo "Expected: ${OPERATOR_VERSION}"
echo "Actual: ${VERSION_OUTPUT}"
exit 1
fi

case "${VERSION_OUTPUT}" in
*"Operator Version: v$OPERATOR_VERSION"*)
;;
*)
echo "Version output is: "
echo "$VERSION_OUTPUT"
echo "Expected: v$OPERATOR_VERSION"
exit 1
;;
esac
}
15 changes: 15 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,15 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
# The following test should check that the client version output is returned
# when a kubernetes cluster is not available
- script: |
contains() { bash -ceu '[[ "$1" == *"$2"* ]]' - "$@"; }

VERSION_OUTPUT=$(KUBECONFIG=blah kubectl pgo version --client)

{ contains "${VERSION_OUTPUT}" "Client Version:"; } || {
echo "Expected: Client Version:*"
echo "Actual: ${VERSION_OUTPUT}"
exit 1
}
Loading