Skip to content

Commit

Permalink
Add some comments to imageProcessor logic
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Dubois <[email protected]>
  • Loading branch information
jandubois committed Jan 27, 2025
1 parent 175259a commit db9d915
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/rancher-desktop/backend/images/imageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ export abstract class ImageProcessor extends EventEmitter {

/**
* Wrapper around the trivy command to scan the specified image.
* @param taggedImageName
* @param namespace
* @param taggedImageName - fully specified image name, including registry and tag. nginx → docker.io/library/nginx:latest
* @param namespace - the containerd namespace of the image. Ignored when using moby.
*/
abstract scanImage(taggedImageName: string, namespace: string): Promise<childResultType>;

Expand All @@ -164,6 +164,7 @@ export abstract class ImageProcessor extends EventEmitter {
* in the args, so it can be called like `CONTAINERD_NAMESPACE=k8s.io trivy image ...`.
*/
async runTrivyCommand(args: string[]): Promise<childResultType> {
// subcommandName is not used by processChildOutput() when args is defined
const subcommandName = 'image';
// must run as root to get access to the containerd socket
const child = this.executor?.spawn({ root: true }, ...args);
Expand Down Expand Up @@ -256,7 +257,9 @@ export abstract class ImageProcessor extends EventEmitter {
child.stdout?.on('data', (data: Buffer) => {
const dataString = data.toString();

// don't dump megabytes of trivy JSON output into the browser
// Don't dump megabytes of trivy JSON output into the browser.
// We can't call with sendNotifications being false because then ok:images-process-output would not be sent
// and jsonOutput would not be set (and therefore scan results would be empty).
if (sendNotifications && commandName !== 'trivy') {
this.emit('images-process-output', dataString, false);
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/rancher-desktop/backend/images/nerdctlImageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export default class NerdctlImageProcessor extends imageProcessor.ImageProcessor
}

async scanImage(taggedImageName: string, namespace: string): Promise<imageProcessor.childResultType> {
// environment variables and the trivy command name are included in the command, which may be invoked like:
// limactl shell 0 sudo CONTAINERD_ADDRESS=… trivy …
return await this.runTrivyCommand(
[
'CONTAINERD_ADDRESS=/run/k3s/containerd/containerd.sock',
Expand Down

0 comments on commit db9d915

Please sign in to comment.