Skip to content

Fix logging of cascading scan name#923

Merged
J12934 merged 2 commits into
mainfrom
fix/cascading-scan-logs
Jan 11, 2022
Merged

Fix logging of cascading scan name#923
J12934 merged 2 commits into
mainfrom
fix/cascading-scan-logs

Conversation

@malexmave

Copy link
Copy Markdown
Member

The cascading hook had a problem with logging the name of the cascaded scan (it was using a key that was undefined at the time it was used). This PR switches it to use the metadata.generateName key. The disadvantage of this approach is that it does not show the suffix that Kubernetes generates for the scan name - it will only log the combined scan name from parent and cascaded scan, but not the four-letter suffixes that are appended automatically. If there is a way to get these into the name as well, let me know, but I don't think there is (and, judging from the Git history, this was also the behavior before it broke).

Closes #921.

Checklist

  • Test your changes as thoroughly as possible before you commit them. Preferably, automate your test by unit/integration tests.
  • Make sure npm test runs for the whole project.
  • Make codeclimate checks happy

Signed-off-by: Max Maass <max.maass@iteratec.com>
@malexmave malexmave added the bug Bugs label Jan 11, 2022
@malexmave malexmave self-assigned this Jan 11, 2022
@EndPositive

Copy link
Copy Markdown
Contributor

@malexmave createNamespacedCustomObject returns the created object, so you should be able to retrieve the final name from it.

@malexmave

Copy link
Copy Markdown
Member Author

Thanks for the info - but it is only called after the first relevant logging statement, and the second log is only printed if the call failed, so I am not sure if that is a good approach 😅 - or am I misunderstanding something somewhere?

@EndPositive

EndPositive commented Jan 11, 2022

Copy link
Copy Markdown
Contributor

Yeah it wouldn't work with the current logs, but you could do something like

  console.log(`Creating Scan ${scan.metadata.generateName}...`);

  try {
    // Submitting the Scan to the kubernetes api
    const scan = await k8sApiCRD.createNamespacedCustomObject(
      "execution.securecodebox.io",
      "v1",
      namespace,
      "scans",
      scan,
      "false"
    );
    console.log(`-> Created scan ${scan.metadata.name}`)
  } catch (error) {
    console.error(`Failed to create Scan ${scan.metadata.generateName}`);
    console.error(error);
  }

Signed-off-by: Max Maass <max.maass@iteratec.com>
@malexmave

Copy link
Copy Markdown
Member Author

Ah, I see. Okay, I implemented this change, with a small change because the IDE did not believe me that the object would have the expected format, so I had to use the bracket syntax instead of the dot syntax. Thank you again for the proposal.

@EndPositive EndPositive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cascading Scan hook logs "undefined" scan name

3 participants