fix #58: Honor pod labels for identifiying a component#59
Conversation
|
The produced output when setting component filter to 'cluster-logging-operator,eventrouter,log-file-metric-exporter,vector'. It matched the pod being tested and produced results but the component name still looks off |
|
/retest |
|
Added another commit to resolve component name discrepency which produced: |
|
/rebase |
|
@jcantrill: The following test failed, say
Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
|
/retest |
smith-xyz
left a comment
There was a problem hiding this comment.
I like the pipeline added here, I think maybe we can reorganize it some and ensure that we're not short circuiting any potential labelling.
To me I'm thinking maybe it should be image first, label override second vs labels first, image fallback.
| slog.Warn("could not get component for image", "image", pod.Image, "error", err) | ||
| // Extract component from pod labels (or fall back to image parsing) | ||
| var componentName string | ||
| if pod.Pod != nil && len(pod.Pod.Spec.Containers) > 0 { |
There was a problem hiding this comment.
This unconditionally overrides the image-derived component name, but extractComponentFromPod can fall back to container.Name which may be less informative than the image name (e.g. "logfilesmetricexporter" vs "log-file-metric-exporter"). Maybe this should only override when a label actually matches?
There was a problem hiding this comment.
I'm not certain what the "correct" logic should be but assuming the image name has first priority is not accurate. This assumes the name of the image will always be the component name. As an example, the CLO image at one time (or maybe still is) "cluster-logging-operator-rhel-9-image". The more correct solution, IMO would be if we had some way of pulling a Label from the compiled image given we already add a label for most production images
This unconditionally overrides the image-derived component name
I do not believe this is relevant. The crux of the issue this PR fixes is component name consistency for scanned workloads. The intent is to match the discovered workloads to scan results and ensure the client knows what to expect. This was the mismatch I discovered where I was expecting some result and received none.
but extractComponentFromPod can fall back to container.Name which may be less informative than the image name (e.g. "logfilesmetricexporter" vs "log-file-metric-exporter"). Maybe this should only override when a label actually matches?
Maybe but this is debatable. The switch says it is for the following:
-component-filter <names> - Filter pods by component name (comma-separated, used with -all-pods)
The component name is what the person running the scanner is expecting. It probably depends who is the target audience. I'm using it in the cluster logging operator project and I have many images that need to be scanned. The component name is important to me for running it; not the interpreted image name as the component.
Whatever the logic "should be" needs to provide a consistent component and we should document what the order of precedence is
There was a problem hiding this comment.
Ahh I see what you're saying, okay maybe we can just make this the de factor answer then. Could you add a doc comment on extractComponentFromPod noting the resolution order (app label > component label > app.kubernetes.io/name > container name > image name)? That way users of -component-filter know what to expect.
this lgtm though so can get it merged after that
|
/label tide/merge-method-squash |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: jcantrill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
This PR: