Skip to content

Commit

Permalink
Set default scan mode (#93)
Browse files Browse the repository at this point in the history
Co-authored-by: anjmao <andzej@cast.ai>
  • Loading branch information
anjmao and anjmao authored Jan 10, 2023
1 parent 4f077c2 commit d72c79b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 9 additions & 4 deletions imagescan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func (s *Scanner) ScanImage(ctx context.Context, params ScanImageParams) (rerr e

switch containerRuntime {
case "docker":
if mode == "" || mode == imgcollectorconfig.ModeDaemon {
if mode == "" {
mode = imgcollectorconfig.ModeDaemon
}
if mode == imgcollectorconfig.ModeDaemon {
vols.volumes = append(vols.volumes, corev1.Volume{
Name: "docker-sock",
VolumeSource: corev1.VolumeSource{
Expand All @@ -108,7 +111,10 @@ func (s *Scanner) ScanImage(ctx context.Context, params ScanImageParams) (rerr e
})
}
case "containerd":
if mode == "" || mode == imgcollectorconfig.ModeHostFS {
if mode == "" {
mode = imgcollectorconfig.ModeHostFS
}
if mode == imgcollectorconfig.ModeHostFS {
vols.volumes = append(vols.volumes, corev1.Volume{
Name: "containerd-content",
VolumeSource: corev1.VolumeSource{
Expand All @@ -123,8 +129,7 @@ func (s *Scanner) ScanImage(ctx context.Context, params ScanImageParams) (rerr e
ReadOnly: true,
MountPath: imgcollectorconfig.ContainerdContentDir,
})
}
if mode == imgcollectorconfig.ModeDaemon {
} else if mode == imgcollectorconfig.ModeDaemon {
vols.volumes = append(vols.volumes, corev1.Volume{
Name: "containerd-sock",
VolumeSource: corev1.VolumeSource{
Expand Down
14 changes: 7 additions & 7 deletions imagescan/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestScanner(t *testing.T) {
MemoryLimit: "2Gi",
ProfileEnabled: true,
PhlareEnabled: true,
Mode: "daemon",
Mode: "",
},
}, nil)
scanner.jobCheckInterval = 1 * time.Microsecond
Expand Down Expand Up @@ -125,7 +125,7 @@ func TestScanner(t *testing.T) {
},
{
Name: "COLLECTOR_MODE",
Value: "daemon",
Value: "hostfs",
},
{
Name: "COLLECTOR_RUNTIME",
Expand Down Expand Up @@ -169,9 +169,9 @@ func TestScanner(t *testing.T) {
},
VolumeMounts: []corev1.VolumeMount{
{
Name: "containerd-sock",
Name: "containerd-content",
ReadOnly: true,
MountPath: "/run/containerd/containerd.sock",
MountPath: "/var/lib/containerd/io.containerd.content.v1.content",
},
},
Resources: corev1.ResourceRequirements{
Expand All @@ -188,11 +188,11 @@ func TestScanner(t *testing.T) {
},
Volumes: []corev1.Volume{
{
Name: "containerd-sock",
Name: "containerd-content",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/run/containerd/containerd.sock",
Type: lo.ToPtr(corev1.HostPathSocket),
Path: "/var/lib/containerd/io.containerd.content.v1.content",
Type: lo.ToPtr(corev1.HostPathDirectory),
},
},
},
Expand Down

0 comments on commit d72c79b

Please sign in to comment.