Repository: kubernetes-sigs/aws-ebs-csi-driver
Pull request #1510 (2023-02-13 18:50:01)

Fix --version output
Fix version handling code to output version info, which was inadvertantly removed in ad25982

Signed-off-by: Connor Catlett <conncatl@amazon.com>


k8s-ci-robot: [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 ask for approval from connorjc3. For more information see [the Kubernetes Code Review Process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process).

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Faws-ebs-csi-driver).

<details open>
Needs approval from an approver in each of these files:

- **[OWNERS](https://github.com/kubernetes-sigs/aws-ebs-csi-driver/blob/master/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["connorjc3"]} -->
k8s-ci-robot: @ConnorJC3: 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
--- | --- | --- | --- | ---
pull-aws-ebs-csi-driver-unit | b6e92d04779240c2f661dec0468a9d8eeb04dadb | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_aws-ebs-csi-driver/1510/pull-aws-ebs-csi-driver-unit/1625205679524417536) | true | `/test pull-aws-ebs-csi-driver-unit`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=aws-ebs-csi-driver&pr=1510). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3AConnorJC3). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/aws-ebs-csi-driver/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/cmd/options.go b/cmd/options.go
index bac6dd3e..370ff1e1 100644
--- a/cmd/options.go
+++ b/cmd/options.go
@@ -111,11 +111,13 @@ func GetOptions(fs *flag.FlagSet) *Options {
 	}
 
 	if *version {
-		info, err := driver.GetVersionJSON()
+		versionInfo, err := driver.GetVersionJSON()
 		if err != nil {
-			klog.ErrorS(err, "failed to get version", "version", info)
+			klog.ErrorS(err, "failed to get version")
 			klog.FlushAndExit(klog.ExitFlushTimeout, 1)
 		}
+		fmt.Println(versionInfo)
+		osExit(0)
 	}
 
 	if *toStderr {


Test patch:
diff --git a/cmd/options_test.go b/cmd/options_test.go
index 6defe59a..4c7e3ade 100644
--- a/cmd/options_test.go
+++ b/cmd/options_test.go
@@ -163,8 +163,10 @@ func TestGetOptions(t *testing.T) {
 				defer func() { osExit = oldOSExit }()
 
 				var exitCode int
+				calledExit := false
 				testExit := func(code int) {
 					exitCode = code
+					calledExit = true
 				}
 				osExit = testExit
 
@@ -181,6 +183,9 @@ func TestGetOptions(t *testing.T) {
 				if exitCode != 0 {
 					t.Fatalf("expected exit code 0 but got %d", exitCode)
 				}
+				if !calledExit {
+					t.Fatalf("expect osExit to be called, but wasn't")
+				}
 			},
 		},
 	}