Skip to content

Commit

Permalink
chore: Rename KubeHunterOutput to KubeHunterReportData (#730)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <[email protected]>
  • Loading branch information
danielpacak authored Oct 2, 2021
1 parent 7390f4f commit 230bf7c
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/aquasecurity/v1alpha1/kube_hunter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type KubeHunterReport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Report KubeHunterOutput `json:"report"`
Report KubeHunterReportData `json:"report"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand All @@ -47,7 +47,7 @@ type KubeHunterReportList struct {
Items []KubeHunterReport `json:"items"`
}

type KubeHunterOutput struct {
type KubeHunterReportData struct {
UpdateTimestamp metav1.Time `json:"updateTimestamp"`
Scanner Scanner `json:"scanner"`
Summary KubeHunterSummary `json:"summary"`
Expand Down
48 changes: 24 additions & 24 deletions pkg/apis/aquasecurity/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions pkg/kubehunter/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"io"
"time"

sec "github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/aquasecurity/starboard/pkg/apis/aquasecurity/v1alpha1"
"github.com/aquasecurity/starboard/pkg/starboard"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func toSummary(vulnerabilities []sec.KubeHunterVulnerability) (summary sec.KubeHunterSummary) {
func toSummary(vulnerabilities []v1alpha1.KubeHunterVulnerability) (summary v1alpha1.KubeHunterSummary) {
for _, v := range vulnerabilities {
switch v.Severity {
case sec.KubeHunterSeverityHigh:
case v1alpha1.KubeHunterSeverityHigh:
summary.HighCount++
case sec.KubeHunterSeverityMedium:
case v1alpha1.KubeHunterSeverityMedium:
summary.MediumCount++
case sec.KubeHunterSeverityLow:
case v1alpha1.KubeHunterSeverityLow:
summary.LowCount++
default:
summary.UnknownCount++
Expand All @@ -26,27 +26,29 @@ func toSummary(vulnerabilities []sec.KubeHunterVulnerability) (summary sec.KubeH
return
}

func OutputFrom(config Config, reader io.Reader) (report sec.KubeHunterOutput, err error) {
func OutputFrom(config Config, reader io.Reader) (v1alpha1.KubeHunterReportData, error) {
imageRef, err := config.GetKubeHunterImageRef()
if err != nil {
return report, err
return v1alpha1.KubeHunterReportData{}, err
}
version, err := starboard.GetVersionFromImageRef(imageRef)
if err != nil {
return sec.KubeHunterOutput{}, err
return v1alpha1.KubeHunterReportData{}, err
}

report.Scanner = sec.Scanner{
Name: "kube-hunter",
Vendor: "Aqua Security",
Version: version,
report := v1alpha1.KubeHunterReportData{
Scanner: v1alpha1.Scanner{
Name: "kube-hunter",
Vendor: "Aqua Security",
Version: version,
},
}
report.UpdateTimestamp = metav1.NewTime(time.Now())
err = json.NewDecoder(reader).Decode(&report)
if err != nil {
return
return v1alpha1.KubeHunterReportData{}, err
}

report.Summary = toSummary(report.Vulnerabilities)
return
return report, nil
}
8 changes: 4 additions & 4 deletions pkg/kubehunter/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ func NewScanner(
}
}

func (s *Scanner) Scan(ctx context.Context) (v1alpha1.KubeHunterOutput, error) {
func (s *Scanner) Scan(ctx context.Context) (v1alpha1.KubeHunterReportData, error) {
// 1. Prepare descriptor for the Kubernetes Job which will run kube-hunter
job, err := s.prepareKubeHunterJob()
if err != nil {
return v1alpha1.KubeHunterOutput{}, err
return v1alpha1.KubeHunterReportData{}, err
}

// 2. Run the prepared Job and wait for its completion or failure
err = runner.New().Run(ctx, kube.NewRunnableJob(s.scheme, s.clientset, job))
if err != nil {
return v1alpha1.KubeHunterOutput{}, fmt.Errorf("running kube-hunter job: %w", err)
return v1alpha1.KubeHunterReportData{}, fmt.Errorf("running kube-hunter job: %w", err)
}

defer func() {
Expand All @@ -82,7 +82,7 @@ func (s *Scanner) Scan(ctx context.Context) (v1alpha1.KubeHunterOutput, error) {
job.Namespace, job.Name)
logsStream, err := s.logsReader.GetLogsByJobAndContainerName(ctx, job, kubeHunterContainerName)
if err != nil {
return v1alpha1.KubeHunterOutput{}, fmt.Errorf("getting logs: %w", err)
return v1alpha1.KubeHunterReportData{}, fmt.Errorf("getting logs: %w", err)
}
defer func() {
_ = logsStream.Close()
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubehunter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Writer interface {
Write(ctx context.Context, report v1alpha1.KubeHunterOutput, cluster string) error
Write(ctx context.Context, report v1alpha1.KubeHunterReportData, cluster string) error
}

type writer struct {
Expand All @@ -26,7 +26,7 @@ func NewWriter(clientset versioned.Interface) Writer {
}
}

func (w *writer) Write(ctx context.Context, report v1alpha1.KubeHunterOutput, cluster string) error {
func (w *writer) Write(ctx context.Context, report v1alpha1.KubeHunterReportData, cluster string) error {
if strings.TrimSpace(cluster) == "" {
return errors.New("cluster name must not be blank")
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/kubehunter/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestWriter_Write(t *testing.T) {
clientset := fake.NewSimpleClientset()

writer := kubehunter.NewWriter(clientset)
err := writer.Write(context.TODO(), v1alpha1.KubeHunterOutput{
err := writer.Write(context.TODO(), v1alpha1.KubeHunterReportData{
Summary: v1alpha1.KubeHunterSummary{
HighCount: 7,
},
Expand All @@ -42,7 +42,7 @@ func TestWriter_Write(t *testing.T) {
starboard.LabelResourceName: "my-cluster",
},
},
Report: v1alpha1.KubeHunterOutput{
Report: v1alpha1.KubeHunterReportData{
Summary: v1alpha1.KubeHunterSummary{
HighCount: 7,
},
Expand All @@ -60,15 +60,15 @@ func TestWriter_Write(t *testing.T) {
starboard.LabelResourceName: "my-cluster",
},
},
Report: v1alpha1.KubeHunterOutput{
Report: v1alpha1.KubeHunterReportData{
Summary: v1alpha1.KubeHunterSummary{
HighCount: 1,
},
},
})

writer := kubehunter.NewWriter(clientset)
err := writer.Write(context.TODO(), v1alpha1.KubeHunterOutput{
err := writer.Write(context.TODO(), v1alpha1.KubeHunterReportData{
Summary: v1alpha1.KubeHunterSummary{
HighCount: 3,
},
Expand All @@ -91,7 +91,7 @@ func TestWriter_Write(t *testing.T) {
starboard.LabelResourceName: "my-cluster",
},
},
Report: v1alpha1.KubeHunterOutput{
Report: v1alpha1.KubeHunterReportData{
Summary: v1alpha1.KubeHunterSummary{
HighCount: 3,
},
Expand Down

0 comments on commit 230bf7c

Please sign in to comment.