Repository: aquasecurity/starboard
Pull request #636 (2021-07-04 21:43:43)

refactor: Rename CISKubeBenchOutput to CISKubeBenchReportData
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>

codecov[bot]: # [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) Report
> Merging [#636](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) (dc6a461) into [main](https://codecov.io/gh/aquasecurity/starboard/commit/e6229a372e9dbb34848e96f8643dd39be903b45a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) (e6229a3) will **decrease** coverage by `23.14%`.
> The diff coverage is `42.85%`.

[![Impacted file tree graph](https://codecov.io/gh/aquasecurity/starboard/pull/636/graphs/tree.svg?width=650&height=150&src=pr&token=qqTGKAJ0Wb&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)

```diff
@@             Coverage Diff             @@
##             main     #636       +/-   ##
===========================================
- Coverage   68.41%   45.26%   -23.15%     
===========================================
  Files          58       41       -17     
  Lines        4454     3599      -855     
===========================================
- Hits         3047     1629     -1418     
- Misses       1050     1871      +821     
+ Partials      357       99      -258     
```


| [Impacted Files](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) | Coverage Δ | |
|---|---|---|
| [pkg/operator/controller/ciskubebenchreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvY2lza3ViZWJlbmNocmVwb3J0Lmdv) | `0.00% <0.00%> (-59.05%)` | :arrow_down: |
| [pkg/kubebench/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmViZW5jaC9zY2FubmVyLmdv) | `61.81% <40.00%> (-26.82%)` | :arrow_down: |
| [pkg/kubebench/builder.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmViZW5jaC9idWlsZGVyLmdv) | `84.61% <100.00%> (ø)` | |
| [pkg/kubehunter/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmVodW50ZXIvc2Nhbm5lci5nbw==) | `0.00% <0.00%> (-80.51%)` | :arrow_down: |
| [pkg/plugin/factory.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL3BsdWdpbi9mYWN0b3J5Lmdv) | `0.00% <0.00%> (-80.49%)` | :arrow_down: |
| [pkg/configauditreport/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2NvbmZpZ2F1ZGl0cmVwb3J0L3NjYW5uZXIuZ28=) | `0.00% <0.00%> (-70.77%)` | :arrow_down: |
| [pkg/vulnerabilityreport/scanner.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL3Z1bG5lcmFiaWxpdHlyZXBvcnQvc2Nhbm5lci5nbw==) | `0.00% <0.00%> (-70.54%)` | :arrow_down: |
| [pkg/operator/controller/configauditreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvY29uZmlnYXVkaXRyZXBvcnQuZ28=) | `0.00% <0.00%> (-68.06%)` | :arrow_down: |
| [pkg/operator/controller/vulnerabilityreport.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL29wZXJhdG9yL2NvbnRyb2xsZXIvdnVsbmVyYWJpbGl0eXJlcG9ydC5nbw==) | `0.00% <0.00%> (-68.04%)` | :arrow_down: |
| [pkg/kube/runnable\_job.go](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity#diff-cGtnL2t1YmUvcnVubmFibGVfam9iLmdv) | `0.00% <0.00%> (-64.39%)` | :arrow_down: |
| ... and [32 more](https://codecov.io/gh/aquasecurity/starboard/pull/636/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity). Last update [e6229a3...dc6a461](https://codecov.io/gh/aquasecurity/starboard/pull/636?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aquasecurity).


Patch:
diff --git a/pkg/apis/aquasecurity/v1alpha1/cis_kube_bench_types.go b/pkg/apis/aquasecurity/v1alpha1/cis_kube_bench_types.go
index a22e140..f849b0f 100644
--- a/pkg/apis/aquasecurity/v1alpha1/cis_kube_bench_types.go
+++ b/pkg/apis/aquasecurity/v1alpha1/cis_kube_bench_types.go
@@ -20,7 +20,7 @@ type CISKubeBenchReport struct {
 	metav1.TypeMeta   `json:",inline"`
 	metav1.ObjectMeta `json:"metadata,omitempty"`
 
-	Report CISKubeBenchOutput `json:"report"`
+	Report CISKubeBenchReportData `json:"report"`
 }
 
 // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
@@ -33,7 +33,7 @@ type CISKubeBenchReportList struct {
 	Items []CISKubeBenchReport `json:"items"`
 }
 
-type CISKubeBenchOutput struct {
+type CISKubeBenchReportData struct {
 	UpdateTimestamp metav1.Time           `json:"updateTimestamp"`
 	Scanner         Scanner               `json:"scanner"`
 	Summary         CISKubeBenchSummary   `json:"summary"`
diff --git a/pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go
index 60f8e69..85ec711 100644
--- a/pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go
@@ -24,32 +24,6 @@ func (in *Artifact) DeepCopy() *Artifact {
 	return out
 }
 
-// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *CISKubeBenchOutput) DeepCopyInto(out *CISKubeBenchOutput) {
-	*out = *in
-	in.UpdateTimestamp.DeepCopyInto(&out.UpdateTimestamp)
-	out.Scanner = in.Scanner
-	out.Summary = in.Summary
-	if in.Sections != nil {
-		in, out := &in.Sections, &out.Sections
-		*out = make([]CISKubeBenchSection, len(*in))
-		for i := range *in {
-			(*in)[i].DeepCopyInto(&(*out)[i])
-		}
-	}
-	return
-}
-
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CISKubeBenchOutput.
-func (in *CISKubeBenchOutput) DeepCopy() *CISKubeBenchOutput {
-	if in == nil {
-		return nil
-	}
-	out := new(CISKubeBenchOutput)
-	in.DeepCopyInto(out)
-	return out
-}
-
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *CISKubeBenchReport) DeepCopyInto(out *CISKubeBenchReport) {
 	*out = *in
@@ -77,6 +51,32 @@ func (in *CISKubeBenchReport) DeepCopyObject() runtime.Object {
 	return nil
 }
 
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *CISKubeBenchReportData) DeepCopyInto(out *CISKubeBenchReportData) {
+	*out = *in
+	in.UpdateTimestamp.DeepCopyInto(&out.UpdateTimestamp)
+	out.Scanner = in.Scanner
+	out.Summary = in.Summary
+	if in.Sections != nil {
+		in, out := &in.Sections, &out.Sections
+		*out = make([]CISKubeBenchSection, len(*in))
+		for i := range *in {
+			(*in)[i].DeepCopyInto(&(*out)[i])
+		}
+	}
+	return
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CISKubeBenchReportData.
+func (in *CISKubeBenchReportData) DeepCopy() *CISKubeBenchReportData {
+	if in == nil {
+		return nil
+	}
+	out := new(CISKubeBenchReportData)
+	in.DeepCopyInto(out)
+	return out
+}
+
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *CISKubeBenchReportList) DeepCopyInto(out *CISKubeBenchReportList) {
 	*out = *in
diff --git a/pkg/kubebench/builder.go b/pkg/kubebench/builder.go
index 04f5d72..6942f55 100644
--- a/pkg/kubebench/builder.go
+++ b/pkg/kubebench/builder.go
@@ -12,39 +12,33 @@ import (
 	"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
 )
 
-type Builder interface {
-	Controller(controller metav1.Object) Builder
-	Data(data v1alpha1.CISKubeBenchOutput) Builder
-	Get() (v1alpha1.CISKubeBenchReport, error)
-}
-
-func NewBuilder(scheme *runtime.Scheme) Builder {
-	return &builder{
+func NewBuilder(scheme *runtime.Scheme) *Builder {
+	return &Builder{
 		scheme: scheme,
 	}
 }
 
-type builder struct {
+type Builder struct {
 	scheme     *runtime.Scheme
 	controller metav1.Object
-	data       v1alpha1.CISKubeBenchOutput
+	data       v1alpha1.CISKubeBenchReportData
 }
 
-func (b *builder) Controller(controller metav1.Object) Builder {
+func (b *Builder) Controller(controller metav1.Object) *Builder {
 	b.controller = controller
 	return b
 }
 
-func (b *builder) Data(data v1alpha1.CISKubeBenchOutput) Builder {
+func (b *Builder) Data(data v1alpha1.CISKubeBenchReportData) *Builder {
 	b.data = data
 	return b
 }
 
-func (b *builder) reportName() string {
+func (b *Builder) reportName() string {
 	return b.controller.GetName()
 }
 
-func (b *builder) Get() (v1alpha1.CISKubeBenchReport, error) {
+func (b *Builder) Get() (v1alpha1.CISKubeBenchReport, error) {
 	kind, err := kube.KindForObject(b.controller, b.scheme)
 	if err != nil {
 		return v1alpha1.CISKubeBenchReport{}, fmt.Errorf("getting kind for object: %w", err)
diff --git a/pkg/kubebench/plugin.go b/pkg/kubebench/plugin.go
index 5a07fd0..48cde57 100644
--- a/pkg/kubebench/plugin.go
+++ b/pkg/kubebench/plugin.go
@@ -16,9 +16,9 @@ type Plugin interface {
 	// node.
 	GetScanJobSpec(node corev1.Node) (corev1.PodSpec, error)
 
-	// ParseCISKubeBenchOutput is a callback to parse and convert logs of
-	// the pod controlled by the scan job to v1alpha1.CISKubeBenchOutput.
-	ParseCISKubeBenchOutput(logsStream io.ReadCloser) (v1alpha1.CISKubeBenchOutput, error)
+	// ParseCISKubeBenchReportData is a callback to parse and convert logs of
+	// the pod controlled by the scan job to v1alpha1.CISKubeBenchReportData.
+	ParseCISKubeBenchReportData(logsStream io.ReadCloser) (v1alpha1.CISKubeBenchReportData, error)
 
 	GetContainerName() string
 }
diff --git a/pkg/kubebench/scanner.go b/pkg/kubebench/scanner.go
index 60d1d73..da38230 100644
--- a/pkg/kubebench/scanner.go
+++ b/pkg/kubebench/scanner.go
@@ -87,7 +87,7 @@ func (s *Scanner) Scan(ctx context.Context, node corev1.Node) (v1alpha1.CISKubeB
 	}()
 
 	// 4. Parse the CISBenchmarkReport from the logs Reader
-	output, err := s.plugin.ParseCISKubeBenchOutput(logsStream)
+	output, err := s.plugin.ParseCISKubeBenchReportData(logsStream)
 	if err != nil {
 		return v1alpha1.CISKubeBenchReport{}, err
 	}
@@ -287,7 +287,7 @@ func (k *kubeBenchPlugin) GetScanJobSpec(node corev1.Node) (corev1.PodSpec, erro
 	}, nil
 }
 
-func (k *kubeBenchPlugin) ParseCISKubeBenchOutput(logsStream io.ReadCloser) (v1alpha1.CISKubeBenchOutput, error) {
+func (k *kubeBenchPlugin) ParseCISKubeBenchReportData(logsStream io.ReadCloser) (v1alpha1.CISKubeBenchReportData, error) {
 	output := &struct {
 		Controls []v1alpha1.CISKubeBenchSection `json:"Controls"`
 	}{}
@@ -295,19 +295,19 @@ func (k *kubeBenchPlugin) ParseCISKubeBenchOutput(logsStream io.ReadCloser) (v1a
 	decoder := json.NewDecoder(logsStream)
 	err := decoder.Decode(output)
 	if err != nil {
-		return v1alpha1.CISKubeBenchOutput{}, err
+		return v1alpha1.CISKubeBenchReportData{}, err
 	}
 
 	imageRef, err := k.config.GetKubeBenchImageRef()
 	if err != nil {
-		return v1alpha1.CISKubeBenchOutput{}, err
+		return v1alpha1.CISKubeBenchReportData{}, err
 	}
 	version, err := starboard.GetVersionFromImageRef(imageRef)
 	if err != nil {
-		return v1alpha1.CISKubeBenchOutput{}, err
+		return v1alpha1.CISKubeBenchReportData{}, err
 	}
 
-	return v1alpha1.CISKubeBenchOutput{
+	return v1alpha1.CISKubeBenchReportData{
 		Scanner: v1alpha1.Scanner{
 			Name:    "kube-bench",
 			Vendor:  "Aqua Security",
diff --git a/pkg/operator/controller/ciskubebenchreport.go b/pkg/operator/controller/ciskubebenchreport.go
index 4ddf05d..0e7c50e 100644
--- a/pkg/operator/controller/ciskubebenchreport.go
+++ b/pkg/operator/controller/ciskubebenchreport.go
@@ -278,7 +278,7 @@ func (r *CISKubeBenchReportReconciler) processCompleteScanJob(ctx context.Contex
 		return fmt.Errorf("getting logs: %w", err)
 	}
 
-	output, err := r.Plugin.ParseCISKubeBenchOutput(logsStream)
+	output, err := r.Plugin.ParseCISKubeBenchReportData(logsStream)
 	defer func() {
 		_ = logsStream.Close()
 	}()


Test patch:
diff --git a/pkg/kubebench/builder_test.go b/pkg/kubebench/builder_test.go
index f09e994..2a92f7a 100644
--- a/pkg/kubebench/builder_test.go
+++ b/pkg/kubebench/builder_test.go
@@ -22,7 +22,7 @@ func TestBuilder(t *testing.T) {
 				Name: "control-plane",
 			},
 		}).
-		Data(v1alpha1.CISKubeBenchOutput{}).Get()
+		Data(v1alpha1.CISKubeBenchReportData{}).Get()
 
 	g.Expect(err).ToNot(gomega.HaveOccurred())
 	g.Expect(report).To(gomega.Equal(v1alpha1.CISKubeBenchReport{
@@ -42,6 +42,6 @@ func TestBuilder(t *testing.T) {
 				starboard.LabelResourceName: "control-plane",
 			},
 		},
-		Report: v1alpha1.CISKubeBenchOutput{},
+		Report: v1alpha1.CISKubeBenchReportData{},
 	}))
 }
diff --git a/pkg/kubebench/io_test.go b/pkg/kubebench/io_test.go
index 29985cc..9d635bc 100644
--- a/pkg/kubebench/io_test.go
+++ b/pkg/kubebench/io_test.go
@@ -29,7 +29,7 @@ func TestReadWriter(t *testing.T) {
 					starboard.LabelResourceName: "control-plane",
 				},
 			},
-			Report: v1alpha1.CISKubeBenchOutput{
+			Report: v1alpha1.CISKubeBenchReportData{
 				Scanner: v1alpha1.Scanner{
 					Vendor:  "Aqua Security",
 					Name:    "kube-bench",
@@ -62,7 +62,7 @@ func TestReadWriter(t *testing.T) {
 					starboard.LabelResourceName: "control-plane",
 				},
 			},
-			Report: v1alpha1.CISKubeBenchOutput{
+			Report: v1alpha1.CISKubeBenchReportData{
 				Scanner: v1alpha1.Scanner{
 					Vendor:  "Aqua Security",
 					Name:    "kube-bench",
@@ -90,7 +90,7 @@ func TestReadWriter(t *testing.T) {
 						starboard.LabelResourceName: "control-plane",
 					},
 				},
-				Report: v1alpha1.CISKubeBenchOutput{
+				Report: v1alpha1.CISKubeBenchReportData{
 					Scanner: v1alpha1.Scanner{
 						Vendor:  "Aqua Security",
 						Name:    "kube-bench",
@@ -114,7 +114,7 @@ func TestReadWriter(t *testing.T) {
 					starboard.LabelResourceName: "control-plane",
 				},
 			},
-			Report: v1alpha1.CISKubeBenchOutput{
+			Report: v1alpha1.CISKubeBenchReportData{
 				Scanner: v1alpha1.Scanner{
 					Vendor:  "Aqua Security",
 					Name:    "kube-bench",
@@ -147,7 +147,7 @@ func TestReadWriter(t *testing.T) {
 				},
 				ResourceVersion: "1",
 			},
-			Report: v1alpha1.CISKubeBenchOutput{
+			Report: v1alpha1.CISKubeBenchReportData{
 				Scanner: v1alpha1.Scanner{
 					Vendor:  "Aqua Security",
 					Name:    "kube-bench",
@@ -175,7 +175,7 @@ func TestReadWriter(t *testing.T) {
 						starboard.LabelResourceName: "control-plane",
 					},
 				},
-				Report: v1alpha1.CISKubeBenchOutput{
+				Report: v1alpha1.CISKubeBenchReportData{
 					Scanner: v1alpha1.Scanner{
 						Vendor:  "Aqua Security",
 						Name:    "kube-bench",
@@ -197,7 +197,7 @@ func TestReadWriter(t *testing.T) {
 						starboard.LabelResourceName: "worker",
 					},
 				},
-				Report: v1alpha1.CISKubeBenchOutput{
+				Report: v1alpha1.CISKubeBenchReportData{
 					Scanner: v1alpha1.Scanner{
 						Vendor:  "Aqua Security",
 						Name:    "kube-bench",
@@ -230,7 +230,7 @@ func TestReadWriter(t *testing.T) {
 					starboard.LabelResourceName: "worker",
 				},
 			},
-			Report: v1alpha1.CISKubeBenchOutput{
+			Report: v1alpha1.CISKubeBenchReportData{
 				Scanner: v1alpha1.Scanner{
 					Vendor:  "Aqua Security",
 					Name:    "kube-bench",
diff --git a/pkg/kubebench/scanner_test.go b/pkg/kubebench/scanner_test.go
index 419f769..df6e984 100644
--- a/pkg/kubebench/scanner_test.go
+++ b/pkg/kubebench/scanner_test.go
@@ -189,7 +189,7 @@ func TestKubeBenchPlugin_ParseCISKubeBenchOutput(t *testing.T) {
 			}()
 
 			instance := kubebench.NewKubeBenchPlugin(fixedClock, config)
-			output, err := instance.ParseCISKubeBenchOutput(inFile)
+			output, err := instance.ParseCISKubeBenchReportData(inFile)
 
 			switch {
 			case tc.err == nil:
@@ -203,14 +203,14 @@ func TestKubeBenchPlugin_ParseCISKubeBenchOutput(t *testing.T) {
 	}
 }
 
-func expectedOutputFrom(t *testing.T, fileName string) v1alpha1.CISKubeBenchOutput {
+func expectedOutputFrom(t *testing.T, fileName string) v1alpha1.CISKubeBenchReportData {
 	t.Helper()
 
 	file, err := os.Open(fileName)
 	require.NoError(t, err)
 	defer file.Close()
 
-	var expectedOutput v1alpha1.CISKubeBenchOutput
+	var expectedOutput v1alpha1.CISKubeBenchReportData
 	err = json.NewDecoder(file).Decode(&expectedOutput)
 	require.NoError(t, err)