From 2e81d67ada2e3f82ea0f80d12d9dc9cf7b21c3ce Mon Sep 17 00:00:00 2001 From: jmckulk Date: Tue, 23 Jan 2024 12:47:01 -0500 Subject: [PATCH 1/3] Allow user to get version without a server --- docs/content/reference/pgo_version.md | 3 ++- internal/cmd/version.go | 6 ++++++ .../e2e/version/01--check-client-version.yaml | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testing/kuttl/e2e/version/01--check-client-version.yaml diff --git a/docs/content/reference/pgo_version.md b/docs/content/reference/pgo_version.md index 6478aae..14efb0d 100644 --- a/docs/content/reference/pgo_version.md +++ b/docs/content/reference/pgo_version.md @@ -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 diff --git a/internal/cmd/version.go b/internal/cmd/version.go index 8d9b0b4..89ebcba 100644 --- a/internal/cmd/version.go +++ b/internal/cmd/version.go @@ -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 @@ -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() diff --git a/testing/kuttl/e2e/version/01--check-client-version.yaml b/testing/kuttl/e2e/version/01--check-client-version.yaml new file mode 100644 index 0000000..716a99f --- /dev/null +++ b/testing/kuttl/e2e/version/01--check-client-version.yaml @@ -0,0 +1,14 @@ +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 ${VERSION_OUTPUT} + exit 1 + } From df735a5a68c80c32c05b3bdebbb8d1101d40ffd8 Mon Sep 17 00:00:00 2001 From: jmckulk Date: Tue, 23 Jan 2024 16:29:48 -0500 Subject: [PATCH 2/3] Update output checking logic We have been using a contains function to check these sorts of outputs in newer tests --- .../kuttl/e2e/version/00--check-version.yaml | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/testing/kuttl/e2e/version/00--check-version.yaml b/testing/kuttl/e2e/version/00--check-version.yaml index 0c59989..ebb44d3 100644 --- a/testing/kuttl/e2e/version/00--check-version.yaml +++ b/testing/kuttl/e2e/version/00--check-version.yaml @@ -2,25 +2,16 @@ 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 ${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" }}' @@ -28,19 +19,8 @@ commands: 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 ${VERSION_OUTPUT} + echo ${OPERATOR_VERSION} 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 + } From 6b956b652c5e95996eeb803010d6eac5faa521ea Mon Sep 17 00:00:00 2001 From: jmckulk Date: Tue, 23 Jan 2024 16:54:13 -0500 Subject: [PATCH 3/3] Update debug output --- testing/kuttl/e2e/version/00--check-version.yaml | 7 ++++--- testing/kuttl/e2e/version/01--check-client-version.yaml | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/testing/kuttl/e2e/version/00--check-version.yaml b/testing/kuttl/e2e/version/00--check-version.yaml index ebb44d3..8f72100 100644 --- a/testing/kuttl/e2e/version/00--check-version.yaml +++ b/testing/kuttl/e2e/version/00--check-version.yaml @@ -6,7 +6,8 @@ commands: VERSION_OUTPUT=$(kubectl pgo version) { contains "${VERSION_OUTPUT}" "Client Version:"; } || { - echo ${VERSION_OUTPUT} + echo "Expected: Client Version:*" + echo "Actual: ${VERSION_OUTPUT}" exit 1 } - script: | @@ -20,7 +21,7 @@ commands: VERSION_OUTPUT=$(kubectl pgo version) { contains "${VERSION_OUTPUT}" "Operator Version: v${OPERATOR_VERSION}"; } || { - echo ${VERSION_OUTPUT} - echo ${OPERATOR_VERSION} + echo "Expected: ${OPERATOR_VERSION}" + echo "Actual: ${VERSION_OUTPUT}" exit 1 } diff --git a/testing/kuttl/e2e/version/01--check-client-version.yaml b/testing/kuttl/e2e/version/01--check-client-version.yaml index 716a99f..56733a5 100644 --- a/testing/kuttl/e2e/version/01--check-client-version.yaml +++ b/testing/kuttl/e2e/version/01--check-client-version.yaml @@ -9,6 +9,7 @@ commands: VERSION_OUTPUT=$(KUBECONFIG=blah kubectl pgo version --client) { contains "${VERSION_OUTPUT}" "Client Version:"; } || { - echo ${VERSION_OUTPUT} + echo "Expected: Client Version:*" + echo "Actual: ${VERSION_OUTPUT}" exit 1 }