Repository: kubernetes-sigs/security-profiles-operator
Pull request #556 (2021-07-29 11:16:14)

Add missing libseccomp version to init log

#### What type of PR is this?

/kind cleanup

#### What this PR does / why we need it:
We now print the libseccomp version also on operator startup. To achieve
that, we now add a dedicated method to retrieve the keys and values from
the version. Tests have been added as well.

#### Which issue(s) this PR fixes:

<!--
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.

Fixes #

or

None
-->
None
#### Does this PR have test?
None
<!--
If tests aren't applicable just write N/A.
-->

#### Special notes for your reviewer:
None
#### Does this PR introduce a user-facing change?

<!--
If no, just write "NONE" in the release-note block below.
If yes, a release note is required:
Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".

For more information on release notes see: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

```release-note
Log libseccomp version on operator startup.
```


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/556#" title="Author self-approved">saschagrunert</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/kubernetes-sigs/security-profiles-operator/blob/master/OWNERS)~~ [saschagrunert]

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":[]} -->
codecov-commenter: # [Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/556?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#556](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/556?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (f44df8a) into [master](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/commit/165693fb3670daf682ee303ef3e2f3b16ecc400d?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (165693f) will **increase** coverage by `0.37%`.
> The diff coverage is `100.00%`.


```diff
@@            Coverage Diff             @@
##           master     #556      +/-   ##
==========================================
+ Coverage   44.02%   44.39%   +0.37%     
==========================================
  Files          26       26              
  Lines        1338     1347       +9     
==========================================
+ Hits          589      598       +9     
  Misses        709      709              
  Partials       40       40              
```

k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/556#pullrequestreview-719108046" title="LGTM">jhrozek</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/556#" title="Author self-approved">saschagrunert</a>*

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

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

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

- ~~[OWNERS](https://github.com/kubernetes-sigs/security-profiles-operator/blob/master/OWNERS)~~ [saschagrunert]

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":[]} -->

Patch:
diff --git a/cmd/security-profiles-operator/main.go b/cmd/security-profiles-operator/main.go
index 80e9a24da..80c747482 100644
--- a/cmd/security-profiles-operator/main.go
+++ b/cmd/security-profiles-operator/main.go
@@ -152,16 +152,9 @@ func main() {
 }
 
 func printInfo(component string) {
-	v := version.Get()
 	setupLog.Info(
 		fmt.Sprintf("starting component: %s", component),
-		"version", v.Version,
-		"gitCommit", v.GitCommit,
-		"gitTreeState", v.GitTreeState,
-		"buildDate", v.BuildDate,
-		"goVersion", v.GoVersion,
-		"compiler", v.Compiler,
-		"platform", v.Platform,
+		version.Get().AsKeyValues()...,
 	)
 }
 
diff --git a/internal/pkg/version/version.go b/internal/pkg/version/version.go
index ba7848b3b..865efab31 100644
--- a/internal/pkg/version/version.go
+++ b/internal/pkg/version/version.go
@@ -84,3 +84,17 @@ func (i *Info) JSONString() (string, error) {
 	}
 	return string(b), nil
 }
+
+// AsKeyValues returns a key value slice of the info.
+func (i *Info) AsKeyValues() []interface{} {
+	return []interface{}{
+		"version", i.Version,
+		"gitCommit", i.GitCommit,
+		"gitTreeState", i.GitTreeState,
+		"buildDate", i.BuildDate,
+		"goVersion", i.GoVersion,
+		"compiler", i.Compiler,
+		"platform", i.Platform,
+		"libseccomp", i.Libseccomp,
+	}
+}


Test patch:
diff --git a/internal/pkg/version/version_test.go b/internal/pkg/version/version_test.go
index 210fbeb11..463fd7c15 100644
--- a/internal/pkg/version/version_test.go
+++ b/internal/pkg/version/version_test.go
@@ -43,3 +43,9 @@ func TestVersionJSON(t *testing.T) {
 	require.Nil(t, err)
 	require.NotEmpty(t, sut)
 }
+
+func TestAsKeyValues(t *testing.T) {
+	t.Parallel()
+	sut := Get().AsKeyValues()
+	require.Len(t, sut, 2*8)
+}