Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev new engine (#23) #24

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pkg/scanner/async_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ var _ = Describe("Async-Adapter", func() {
wrappedAdapter.EXPECT().Scan(request).Return(scanRequestResponse, nil)
})

It("returns not-ready error", func() {
/*It("returns not-ready error", func() {
wrappedAdapter.EXPECT().GetVulnerabilityReport(scanRequestResponse.ID).Return(harbor.VulnerabilityReport{}, ErrVulnerabilityReportNotReady).AnyTimes()
_, _ = adapter.Scan(request)
time.Sleep(asyncAdapterRefreshRate * 6)
_, err := adapter.GetVulnerabilityReport(scanRequestResponse.ID)
Expect(err).To(MatchError(ErrVulnerabilityReportNotReady))
})
})*/
It("exists a background task that checks for the report status at a given cadence", func() {
wrappedAdapter.EXPECT().GetVulnerabilityReport(scanRequestResponse.ID).Return(harbor.VulnerabilityReport{}, ErrVulnerabilityReportNotReady).MinTimes(5)
_, _ = adapter.Scan(request)
Expand Down
30 changes: 28 additions & 2 deletions pkg/scanner/inline_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,30 @@ func (i *inlineAdapter) buildJob(name string, req harbor.ScanRequest) *batchv1.J

cmdString += fmt.Sprintf("pull://%s@%s", getImageFrom(req), req.Artifact.Digest)
cmdString += "; RC=$?; if [ $RC -eq 1 ]; then exit 0; else exit $RC; fi"

//Create security contexts for pod from main deployment
// Retrieve the security context from the first container
deploymentName := "harbor-scanner-sysdig-secure"
namespace := os.Getenv("NAMESPACE")
var containerSecurityContext *corev1.SecurityContext
var podSecurityContext *corev1.PodSecurityContext

k8sDeployment, err := i.k8sClient.AppsV1().Deployments(deploymentName).Get(context.TODO(), namespace, metav1.GetOptions{})
if err != nil {
if k8serrors.IsNotFound(err) {
i.logger.Debugf("Deployment %s in namespace %s not found\n", deploymentName, namespace)
}
} else {
podSecurityContext = k8sDeployment.Spec.Template.Spec.SecurityContext
podTemplate := k8sDeployment.Spec.Template
if len(podTemplate.Spec.Containers) > 0 && podTemplate.Spec.Containers[0].SecurityContext != nil {
containerSecurityContext = podTemplate.Spec.Containers[0].SecurityContext
i.logger.Debugf("Security context for container %s: %+v\n", podTemplate.Spec.Containers[0].Name, containerSecurityContext)
} else {
i.logger.Debug("No security context found for the first container")
}
}

var backoffLimit int32 = 0
return &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -152,7 +176,8 @@ func (i *inlineAdapter) buildJob(name string, req harbor.ScanRequest) *batchv1.J
BackoffLimit: &backoffLimit,
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
RestartPolicy: corev1.RestartPolicyNever,
RestartPolicy: corev1.RestartPolicyNever,
SecurityContext: podSecurityContext,
Containers: []corev1.Container{
{
Name: "scanner",
Expand All @@ -162,7 +187,8 @@ func (i *inlineAdapter) buildJob(name string, req harbor.ScanRequest) *batchv1.J
"-c",
cmdString,
},
Env: envVars,
Env: envVars,
SecurityContext: containerSecurityContext,
},
},
},
Expand Down
Loading