Repository: kubernetes-sigs/security-profiles-operator
Pull request #533 (2021-07-09 08:23:35)

Preserve reason if tail fails
#### What type of PR is this?


/kind cleanup


#### What this PR does / why we need it:
We should still track the reason if the tail of the log file files, which is now the case.

#### 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?
Yes
<!--
If tests aren't applicable just write N/A.
-->

#### Special notes for your reviewer:
Prow e2e tests are broken until https://github.com/kubernetes/test-infra/pull/22823 got merged.
#### 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
None
```


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/533#" 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":[]} -->
k8s-ci-robot: @saschagrunert: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-security-profiles-operator-test-e2e | 2d55f149b220a892d2836740684223967963b82d | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_security-profiles-operator/533/pull-security-profiles-operator-test-e2e/1413413515535847424) | `/test pull-security-profiles-operator-test-e2e`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=security-profiles-operator&pr=533). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Asaschagrunert). 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/security-profiles-operator/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 -->
codecov-commenter: # [Codecov](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/533?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#533](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/533?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (2d55f14) into [master](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/commit/a5930e28a3cef4272b497e37268b33e0f59919de?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (a5930e2) will **decrease** coverage by `0.03%`.
> The diff coverage is `50.00%`.


```diff
@@            Coverage Diff             @@
##           master     #533      +/-   ##
==========================================
- Coverage   44.12%   44.08%   -0.04%     
==========================================
  Files          25       25              
  Lines        1310     1311       +1     
==========================================
  Hits          578      578              
- Misses        695      696       +1     
  Partials       37       37              
```

JAORMX: /retest
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/533#pullrequestreview-703484078" title="LGTM">JAORMX</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/533#" 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":[]} -->
k8s-ci-robot: @saschagrunert: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-security-profiles-operator-test-e2e | 2d55f149b220a892d2836740684223967963b82d | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_security-profiles-operator/533/pull-security-profiles-operator-test-e2e/1413779199545577472) | `/test pull-security-profiles-operator-test-e2e`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=security-profiles-operator&pr=533). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Asaschagrunert). 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/security-profiles-operator/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 -->
saschagrunert: /retest

Patch:
diff --git a/internal/pkg/daemon/enricher/enricher.go b/internal/pkg/daemon/enricher/enricher.go
index 984bdd821..236f2f5ef 100644
--- a/internal/pkg/daemon/enricher/enricher.go
+++ b/internal/pkg/daemon/enricher/enricher.go
@@ -199,7 +199,7 @@ func (e *Enricher) Run() error {
 		}
 	}
 
-	return errors.New("enricher failed")
+	return errors.Wrap(e.impl.Reason(tailFile), "enricher failed")
 }
 
 // logFilePath returns either the path to the audit logs or falls back to
diff --git a/internal/pkg/daemon/enricher/enricherfakes/fake_impl.go b/internal/pkg/daemon/enricher/enricherfakes/fake_impl.go
index 4c6d9381e..59ad5f4b1 100644
--- a/internal/pkg/daemon/enricher/enricherfakes/fake_impl.go
+++ b/internal/pkg/daemon/enricher/enricherfakes/fake_impl.go
@@ -142,6 +142,17 @@ type FakeImpl struct {
 		result1 *os.File
 		result2 error
 	}
+	ReasonStub        func(*tail.Tail) error
+	reasonMutex       sync.RWMutex
+	reasonArgsForCall []struct {
+		arg1 *tail.Tail
+	}
+	reasonReturns struct {
+		result1 error
+	}
+	reasonReturnsOnCall map[int]struct {
+		result1 error
+	}
 	RecordSyscallStub        func(api.SecurityProfilesOperatorClient) (api.SecurityProfilesOperator_RecordSyscallClient, error)
 	recordSyscallMutex       sync.RWMutex
 	recordSyscallArgsForCall []struct {
@@ -761,6 +772,67 @@ func (fake *FakeImpl) OpenReturnsOnCall(i int, result1 *os.File, result2 error)
 	}{result1, result2}
 }
 
+func (fake *FakeImpl) Reason(arg1 *tail.Tail) error {
+	fake.reasonMutex.Lock()
+	ret, specificReturn := fake.reasonReturnsOnCall[len(fake.reasonArgsForCall)]
+	fake.reasonArgsForCall = append(fake.reasonArgsForCall, struct {
+		arg1 *tail.Tail
+	}{arg1})
+	stub := fake.ReasonStub
+	fakeReturns := fake.reasonReturns
+	fake.recordInvocation("Reason", []interface{}{arg1})
+	fake.reasonMutex.Unlock()
+	if stub != nil {
+		return stub(arg1)
+	}
+	if specificReturn {
+		return ret.result1
+	}
+	return fakeReturns.result1
+}
+
+func (fake *FakeImpl) ReasonCallCount() int {
+	fake.reasonMutex.RLock()
+	defer fake.reasonMutex.RUnlock()
+	return len(fake.reasonArgsForCall)
+}
+
+func (fake *FakeImpl) ReasonCalls(stub func(*tail.Tail) error) {
+	fake.reasonMutex.Lock()
+	defer fake.reasonMutex.Unlock()
+	fake.ReasonStub = stub
+}
+
+func (fake *FakeImpl) ReasonArgsForCall(i int) *tail.Tail {
+	fake.reasonMutex.RLock()
+	defer fake.reasonMutex.RUnlock()
+	argsForCall := fake.reasonArgsForCall[i]
+	return argsForCall.arg1
+}
+
+func (fake *FakeImpl) ReasonReturns(result1 error) {
+	fake.reasonMutex.Lock()
+	defer fake.reasonMutex.Unlock()
+	fake.ReasonStub = nil
+	fake.reasonReturns = struct {
+		result1 error
+	}{result1}
+}
+
+func (fake *FakeImpl) ReasonReturnsOnCall(i int, result1 error) {
+	fake.reasonMutex.Lock()
+	defer fake.reasonMutex.Unlock()
+	fake.ReasonStub = nil
+	if fake.reasonReturnsOnCall == nil {
+		fake.reasonReturnsOnCall = make(map[int]struct {
+			result1 error
+		})
+	}
+	fake.reasonReturnsOnCall[i] = struct {
+		result1 error
+	}{result1}
+}
+
 func (fake *FakeImpl) RecordSyscall(arg1 api.SecurityProfilesOperatorClient) (api.SecurityProfilesOperator_RecordSyscallClient, error) {
 	fake.recordSyscallMutex.Lock()
 	ret, specificReturn := fake.recordSyscallReturnsOnCall[len(fake.recordSyscallArgsForCall)]
@@ -1097,6 +1169,8 @@ func (fake *FakeImpl) Invocations() map[string][][]interface{} {
 	defer fake.newForConfigMutex.RUnlock()
 	fake.openMutex.RLock()
 	defer fake.openMutex.RUnlock()
+	fake.reasonMutex.RLock()
+	defer fake.reasonMutex.RUnlock()
 	fake.recordSyscallMutex.RLock()
 	defer fake.recordSyscallMutex.RUnlock()
 	fake.sendMetricMutex.RLock()
diff --git a/internal/pkg/daemon/enricher/impl.go b/internal/pkg/daemon/enricher/impl.go
index 3cf3fe436..c6f552163 100644
--- a/internal/pkg/daemon/enricher/impl.go
+++ b/internal/pkg/daemon/enricher/impl.go
@@ -44,6 +44,7 @@ type impl interface {
 	Close(*grpc.ClientConn) error
 	TailFile(filename string, config tail.Config) (*tail.Tail, error)
 	Lines(tailFile *tail.Tail) chan *tail.Line
+	Reason(tailFile *tail.Tail) error
 	Open(name string) (*os.File, error)
 	InClusterConfig() (*rest.Config, error)
 	NewForConfig(c *rest.Config) (*kubernetes.Clientset, error)
@@ -90,6 +91,10 @@ func (d *defaultImpl) Lines(tailFile *tail.Tail) chan *tail.Line {
 	return tailFile.Lines
 }
 
+func (d *defaultImpl) Reason(tailFile *tail.Tail) error {
+	return tailFile.Err()
+}
+
 func (d *defaultImpl) Open(name string) (*os.File, error) {
 	return os.Open(name)
 }


Test patch:
diff --git a/internal/pkg/daemon/enricher/enricher_test.go b/internal/pkg/daemon/enricher/enricher_test.go
index 09edacb3f..4f20282a1 100644
--- a/internal/pkg/daemon/enricher/enricher_test.go
+++ b/internal/pkg/daemon/enricher/enricher_test.go
@@ -165,6 +165,7 @@ func TestRun(t *testing.T) {
 				mock.GetenvReturns(node)
 				close(lineChan)
 				mock.LinesReturns(lineChan)
+				mock.ReasonReturns(errTest)
 			},
 			assert: func(mock *enricherfakes.FakeImpl, lineChan chan *tail.Line, err error) {
 				require.NotNil(t, err)