Skip to content

Commit

Permalink
Fix ClientServer scan (#1344)
Browse files Browse the repository at this point in the history
Fixes an issue where client server setups create multiple volume mounts for ignore files, failing with a "Duplicate value" error
  • Loading branch information
filipepazrodrigues authored Jul 9, 2023
1 parent cb0e940 commit b1caf82
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions pkg/plugins/trivy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func (p *plugin) getPodSpecForClientServerMode(ctx trivyoperator.PluginContext,
MountPath: "/tmp",
},
}
volumeMounts = append(volumeMounts, getScanResultVolumeMount())

// add tmp volume
volumes := []corev1.Volume{
{
Expand All @@ -959,7 +959,23 @@ func (p *plugin) getPodSpecForClientServerMode(ctx trivyoperator.PluginContext,
},
},
}

volumeMounts = append(volumeMounts, getScanResultVolumeMount())
volumes = append(volumes, getScanResultVolume())

if volume, volumeMount := config.GenerateIgnoreFileVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
if volume, volumeMount := config.GenerateIgnorePolicyVolumeIfAvailable(trivyConfigName, workload); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

for _, container := range containersSpec {
env := []corev1.EnvVar{
Expand Down Expand Up @@ -1040,20 +1056,6 @@ func (p *plugin) getPodSpecForClientServerMode(ctx trivyoperator.PluginContext,
})
}

if volume, volumeMount := config.GenerateIgnoreFileVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
if volume, volumeMount := config.GenerateIgnorePolicyVolumeIfAvailable(trivyConfigName, workload); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

requirements, err := config.GetResourceRequirements()
if err != nil {
return corev1.PodSpec{}, nil, err
Expand Down Expand Up @@ -1330,6 +1332,7 @@ func (p *plugin) getPodSpecForStandaloneFSMode(ctx trivyoperator.PluginContext,
},
},
}

volumeMounts = append(volumeMounts, getScanResultVolumeMount())
volumes = append(volumes, getScanResultVolume())

Expand Down

0 comments on commit b1caf82

Please sign in to comment.