Repository: kubernetes-sigs/security-profiles-operator
Pull request #508 (2021-06-29 09:37:23)

Make enricher types private
#### What type of PR is this?

/kind cleanup

#### What this PR does / why we need it:
There is no reason to have those types or fields public, which is now
why we make them internally private in the first place.

#### 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
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/508#" 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-unit | 961cd4f80866483f76fc65a7b321d06b35c19a66 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_security-profiles-operator/508/pull-security-profiles-operator-test-unit/1409808209471868928) | `/test pull-security-profiles-operator-test-unit`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=security-profiles-operator&pr=508). [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/508?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
> Merging [#508](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/pull/508?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (961cd4f) into [master](https://codecov.io/gh/kubernetes-sigs/security-profiles-operator/commit/f3930af49684812a1ec01221f6209360be22a8b0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) (f3930af) will **not change** coverage.
> The diff coverage is `89.65%`.


```diff
@@           Coverage Diff           @@
##           master     #508   +/-   ##
=======================================
  Coverage   44.07%   44.07%           
=======================================
  Files          24       24           
  Lines        1207     1207           
=======================================
  Hits          532      532           
  Misses        644      644           
  Partials       31       31           
```

saschagrunert: /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/508#pullrequestreview-694841637" title="LGTM">jhrozek</a>*, *<a href="https://github.com/kubernetes-sigs/security-profiles-operator/pull/508#" 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/internal/pkg/daemon/enricher/audit.go b/internal/pkg/daemon/enricher/audit.go
index 2006ee886..9dee739ce 100644
--- a/internal/pkg/daemon/enricher/audit.go
+++ b/internal/pkg/daemon/enricher/audit.go
@@ -66,14 +66,14 @@ func extractSeccompLine(logLine string) *auditLine {
 	}
 
 	line := auditLine{}
-	line.Type = AuditTypeSeccomp
-	line.TimestampID = captures[2]
-	line.Executable = captures[4]
+	line.type_ = auditTypeSeccomp
+	line.timestampID = captures[2]
+	line.executable = captures[4]
 	if v, err := strconv.Atoi(captures[3]); err == nil {
-		line.ProcessID = v
+		line.processID = v
 	}
 	if v, err := strconv.Atoi(captures[5]); err == nil {
-		line.SystemCallID = v
+		line.systemCallID = v
 	}
 
 	return &line
@@ -86,10 +86,10 @@ func extractSelinuxLine(logLine string) *auditLine {
 	}
 
 	line := auditLine{}
-	line.Type = AuditTypeSelinux
-	line.TimestampID = captures[1]
+	line.type_ = auditTypeSelinux
+	line.timestampID = captures[1]
 	if v, err := strconv.Atoi(captures[2]); err == nil {
-		line.ProcessID = v
+		line.processID = v
 	}
 
 	return &line
diff --git a/internal/pkg/daemon/enricher/container.go b/internal/pkg/daemon/enricher/container.go
index 6c1c759bf..30e673869 100644
--- a/internal/pkg/daemon/enricher/container.go
+++ b/internal/pkg/daemon/enricher/container.go
@@ -78,10 +78,10 @@ func (e *Enricher) getNodeContainers(logger logr.Logger, nodeName string) (map[s
 					}
 
 					containers[rawContainerID] = containerInfo{
-						PodName:       pod.Name,
-						ContainerName: containerStatus.Name,
-						Namespace:     pod.Namespace,
-						ContainerID:   rawContainerID,
+						podName:       pod.Name,
+						containerName: containerStatus.Name,
+						namespace:     pod.Namespace,
+						containerID:   rawContainerID,
 					}
 				}
 			}
diff --git a/internal/pkg/daemon/enricher/enricher.go b/internal/pkg/daemon/enricher/enricher.go
index 34ac7283a..07158141e 100644
--- a/internal/pkg/daemon/enricher/enricher.go
+++ b/internal/pkg/daemon/enricher/enricher.go
@@ -95,9 +95,9 @@ func (e *Enricher) Run() error {
 			continue
 		}
 
-		cID, err := e.getContainerID(auditLine.ProcessID)
+		cID, err := e.getContainerID(auditLine.processID)
 		if err != nil {
-			e.logger.Error(err, "unable to get container ID", "processID", auditLine.ProcessID)
+			e.logger.Error(err, "unable to get container ID", "processID", auditLine.processID)
 			continue
 		}
 
@@ -107,28 +107,28 @@ func (e *Enricher) Run() error {
 		if !found {
 			e.logger.Error(
 				err, "containerID not found in cluster",
-				"processID", auditLine.ProcessID,
+				"processID", auditLine.processID,
 				"containerID", cID,
 			)
 			continue
 		}
 
-		syscallName := systemCalls[auditLine.SystemCallID]
+		syscallName := systemCalls[auditLine.systemCallID]
 		e.logger.Info("audit",
-			"timestamp", auditLine.TimestampID,
-			"type", auditLine.Type,
+			"timestamp", auditLine.timestampID,
+			"type", auditLine.type_,
 			"node", nodeName,
-			"namespace", c.Namespace,
-			"pod", c.PodName,
-			"container", c.ContainerName,
-			"executable", auditLine.Executable,
-			"pid", auditLine.ProcessID,
-			"syscallID", auditLine.SystemCallID,
+			"namespace", c.namespace,
+			"pod", c.podName,
+			"container", c.containerName,
+			"executable", auditLine.executable,
+			"pid", auditLine.processID,
+			"syscallID", auditLine.systemCallID,
 			"syscallName", syscallName,
 		)
 
 		metricsType := api.MetricsAuditRequest_SECCOMP
-		if auditLine.Type == AuditTypeSelinux {
+		if auditLine.type_ == auditTypeSelinux {
 			metricsType = api.MetricsAuditRequest_SELINUX
 		}
 		if _, err := e.impl.MetricsAuditInc(
@@ -136,10 +136,10 @@ func (e *Enricher) Run() error {
 			&api.MetricsAuditRequest{
 				Type:       metricsType,
 				Node:       nodeName,
-				Namespace:  c.Namespace,
-				Pod:        c.PodName,
-				Container:  c.ContainerName,
-				Executable: auditLine.Executable,
+				Namespace:  c.namespace,
+				Pod:        c.podName,
+				Container:  c.containerName,
+				Executable: auditLine.executable,
 				Syscall:    syscallName,
 			},
 		); err != nil {
diff --git a/internal/pkg/daemon/enricher/types.go b/internal/pkg/daemon/enricher/types.go
index aa1f4ee9d..4659d7ce1 100644
--- a/internal/pkg/daemon/enricher/types.go
+++ b/internal/pkg/daemon/enricher/types.go
@@ -24,23 +24,23 @@ var (
 )
 
 const (
-	AuditTypeSeccomp = "seccomp"
-	AuditTypeSelinux = "selinux"
+	auditTypeSeccomp = "seccomp"
+	auditTypeSelinux = "selinux"
 )
 
 type auditLine struct {
-	ProcessID    int
-	SystemCallID int
-	Type         string
-	TimestampID  string
-	Executable   string
+	processID    int
+	systemCallID int
+	type_        string
+	timestampID  string
+	executable   string
 }
 
 type containerInfo struct {
-	PodName       string
-	ContainerName string
-	Namespace     string
-	ContainerID   string
+	podName       string
+	containerName string
+	namespace     string
+	containerID   string
 }
 
 // List of x86-x64 syscalls


Test patch:
diff --git a/internal/pkg/daemon/enricher/audit_test.go b/internal/pkg/daemon/enricher/audit_test.go
index 0eaebb275..3957e9e2e 100644
--- a/internal/pkg/daemon/enricher/audit_test.go
+++ b/internal/pkg/daemon/enricher/audit_test.go
@@ -82,11 +82,11 @@ func Test_extractAuditLine(t *testing.T) {
 			//nolint:lll
 			`audit: type=1326 audit(1612299677.115:549067): auid=4294967295 uid=0 gid=0 ses=4294967295 pid=3109464 comm="sh" exe="/bin/busybox" sig=0 arch=c000003e syscall=0 compat=0 ip=0x7fce771ae923 code=0x7ffc0000`,
 			&auditLine{
-				Type:         "seccomp",
-				TimestampID:  "1612299677.115:549067",
-				SystemCallID: 0,
-				ProcessID:    3109464,
-				Executable:   "/bin/busybox",
+				type_:        "seccomp",
+				timestampID:  "1612299677.115:549067",
+				systemCallID: 0,
+				processID:    3109464,
+				executable:   "/bin/busybox",
 			},
 			nil,
 		},
@@ -95,11 +95,11 @@ func Test_extractAuditLine(t *testing.T) {
 			//nolint:lll
 			`type=SECCOMP msg=audit(1613596317.899:6461): auid=4294967295 uid=0 gid=0 ses=4294967295 subj=system_u:system_r:spc_t:s0:c284,c594 pid=2039886 comm="ls" exe="/bin/ls" sig=0 arch=c000003e syscall=3 compat=0 ip=0x7f62dce3d4c7 code=0x7ffc0000AUID="unset" UID="root" GID="root" ARCH=x86_64 SYSCALL=close`,
 			&auditLine{
-				Type:         "seccomp",
-				TimestampID:  "1613596317.899:6461",
-				SystemCallID: 3,
-				ProcessID:    2039886,
-				Executable:   "/bin/ls",
+				type_:        "seccomp",
+				timestampID:  "1613596317.899:6461",
+				systemCallID: 3,
+				processID:    2039886,
+				executable:   "/bin/ls",
 			},
 			nil,
 		},
@@ -108,11 +108,11 @@ func Test_extractAuditLine(t *testing.T) {
 			//nolint:lll
 			`type=AVC msg=audit(1613173578.156:2945): avc:  denied  { read } for  pid=75593 comm="security-profil" name="token" dev="tmpfs" ino=612459 scontext=system_u:system_r:container_t:s0:c4,c808 tcontext=system_u:object_r:var_lib_t:s0 tclass=lnk_file permissive=0`,
 			&auditLine{
-				Type:         "selinux",
-				TimestampID:  "1613173578.156:2945",
-				SystemCallID: 0,
-				ProcessID:    75593,
-				Executable:   "",
+				type_:        "selinux",
+				timestampID:  "1613173578.156:2945",
+				systemCallID: 0,
+				processID:    75593,
+				executable:   "",
 			},
 			nil,
 		},