Skip to content

Commit

Permalink
refactor: Common methods (aquasecurity#143)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak authored Sep 7, 2020
1 parent e5963e5 commit 4aa0d52
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 14 deletions.
3 changes: 1 addition & 2 deletions pkg/find/vulnerabilities/trivy/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type Scanner struct {
clientset kubernetes.Interface
pods *pod.Manager
converter Converter
scanners.Base
}

func (s *Scanner) Scan(ctx context.Context, workload kube.Object) (reports vulnerabilities.WorkloadVulnerabilities, owner meta.Object, err error) {
Expand Down Expand Up @@ -270,7 +269,7 @@ func (s *Scanner) PrepareScanJob(ctx context.Context, workload kube.Object, spec
Spec: batch.JobSpec{
BackoffLimit: pointer.Int32Ptr(0),
Completions: pointer.Int32Ptr(1),
ActiveDeadlineSeconds: s.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
ActiveDeadlineSeconds: scanners.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
Template: core.PodTemplateSpec{
ObjectMeta: meta.ObjectMeta{
Labels: map[string]string{
Expand Down
4 changes: 2 additions & 2 deletions pkg/kube/pod/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ func (pw *Manager) GetTerminatedContainersStatusesByJob(ctx context.Context, job
if err != nil {
return
}
statuses = pw.GetTerminatedContainersStatusesByPod(pod)
statuses = GetTerminatedContainersStatusesByPod(pod)
return
}

func (pw *Manager) GetTerminatedContainersStatusesByPod(pod *core.Pod) map[string]*core.ContainerStateTerminated {
func GetTerminatedContainersStatusesByPod(pod *core.Pod) map[string]*core.ContainerStateTerminated {
states := make(map[string]*core.ContainerStateTerminated)
for _, status := range pod.Status.InitContainerStatuses {
if status.State.Terminated == nil {
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubebench/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ type Scanner struct {
clientset kubernetes.Interface
pods *pod.Manager
converter Converter
scanners.Base
}

func NewScanner(opts kube.ScannerOpts, clientset kubernetes.Interface) *Scanner {
Expand Down Expand Up @@ -123,7 +122,7 @@ func (s *Scanner) prepareKubeBenchJob(node core.Node) *batch.Job {
Spec: batch.JobSpec{
BackoffLimit: pointer.Int32Ptr(0),
Completions: pointer.Int32Ptr(1),
ActiveDeadlineSeconds: s.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
ActiveDeadlineSeconds: scanners.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
Template: core.PodTemplateSpec{
ObjectMeta: meta.ObjectMeta{
Labels: labels.Set{
Expand Down
3 changes: 1 addition & 2 deletions pkg/kubehunter/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ type Scanner struct {
opts kube.ScannerOpts
clientset kubernetes.Interface
pods *pod.Manager
scanners.Base
}

func NewScanner(opts kube.ScannerOpts, clientset kubernetes.Interface) *Scanner {
Expand Down Expand Up @@ -104,7 +103,7 @@ func (s *Scanner) prepareKubeHunterJob() *batch.Job {
Spec: batch.JobSpec{
BackoffLimit: pointer.Int32Ptr(0),
Completions: pointer.Int32Ptr(1),
ActiveDeadlineSeconds: s.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
ActiveDeadlineSeconds: scanners.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
Template: core.PodTemplateSpec{
ObjectMeta: meta.ObjectMeta{
Labels: map[string]string{
Expand Down
3 changes: 1 addition & 2 deletions pkg/polaris/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type Scanner struct {
clientset kubernetes.Interface
pods *pod.Manager
converter Converter
scanners.Base
}

func NewScanner(opts kube.ScannerOpts, clientset kubernetes.Interface) *Scanner {
Expand Down Expand Up @@ -95,7 +94,7 @@ func (s *Scanner) preparePolarisJob() *batch.Job {
Spec: batch.JobSpec{
BackoffLimit: pointer.Int32Ptr(0),
Completions: pointer.Int32Ptr(1),
ActiveDeadlineSeconds: s.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
ActiveDeadlineSeconds: scanners.GetActiveDeadlineSeconds(s.opts.ScanJobTimeout),
Template: core.PodTemplateSpec{
ObjectMeta: meta.ObjectMeta{
Labels: map[string]string{
Expand Down
5 changes: 1 addition & 4 deletions pkg/scanners/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"k8s.io/utils/pointer"
)

type Base struct {
}

func (s *Base) GetActiveDeadlineSeconds(d time.Duration) (timeout *int64) {
func GetActiveDeadlineSeconds(d time.Duration) (timeout *int64) {
if d > 0 {
timeout = pointer.Int64Ptr(int64(d.Seconds()))
return
Expand Down

0 comments on commit 4aa0d52

Please sign in to comment.