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

fix: add workload labels to the podTemplate in the scan Job #83

Merged
merged 1 commit into from
Jan 17, 2023
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
2 changes: 2 additions & 0 deletions controllers/containerimagescan_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ var _ = Describe("ContainerImageScan controller", func() {
job.Spec.Template.Labels[k] = "<CONTROLLER-UID>"
case "job-name":
job.Spec.Template.Labels[k] = "<JOB-NAME>"
case stasv1alpha1.LabelStatnettControllerUID:
job.Spec.Template.Labels[k] = "<CIS-UID>"
}

}
Expand Down
5 changes: 5 additions & 0 deletions controllers/testdata/scan-job/expected-scan-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ spec:
app.kubernetes.io/name: trivy
controller-uid: <CONTROLLER-UID>
job-name: <JOB-NAME>
controller.statnett.no/namespace: replica-set
controller.statnett.no/uid: <CIS-UID>
workload.statnett.no/kind: Pod
workload.statnett.no/name: echo
workload.statnett.no/namespace: replica-set
spec:
affinity:
nodeAffinity:
Expand Down
5 changes: 1 addition & 4 deletions internal/trivy/scan_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func (f *filesystemScanJobBuilder) ForCIS(cis *stasv1alpha1.ContainerImageScan)
stasv1alpha1.LabelStatnettWorkloadName: truncateString(cis.Spec.Workload.Name, KubernetesLabelValueMaxLength),
stasv1alpha1.LabelStatnettWorkloadNamespace: cis.Namespace,
}
job.Spec.Template.Labels = job.Labels

return job, nil
}
Expand Down Expand Up @@ -113,10 +114,6 @@ func (f *filesystemScanJobBuilder) newImageScanJob(spec stasv1alpha1.ContainerIm
return nil, err
}

job.Spec.Template.Labels = map[string]string{
stasv1alpha1.LabelK8sAppName: stasv1alpha1.AppNameTrivy,
stasv1alpha1.LabelK8SAppManagedBy: stasv1alpha1.AppNameImageScanner,
}
job.Spec.Template.Spec.InitContainers = []corev1.Container{f.initContainer()}
job.Spec.Template.Spec.Containers = []corev1.Container{container}
job.Spec.Template.Spec.Volumes = []corev1.Volume{
Expand Down