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 logging of cascading scan name #923

Merged
merged 2 commits into from
Jan 11, 2022
Merged

Fix logging of cascading scan name #923

merged 2 commits into from
Jan 11, 2022

Conversation

malexmave
Copy link
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 added this to In progress in secureCodeBox v3 via automation Jan 11, 2022
@malexmave malexmave self-assigned this Jan 11, 2022
@malexmave malexmave moved this from In progress to To Review in secureCodeBox v3 Jan 11, 2022
@EndPositive
Copy link
Contributor

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

@malexmave
Copy link
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
Copy link
Contributor

EndPositive commented Jan 11, 2022

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
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.

Copy link
Contributor

@EndPositive EndPositive left a comment

Choose a reason for hiding this comment

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

Looks good to me 😄

secureCodeBox v3 automation moved this from To Review to Reviewer approved Jan 11, 2022
@J12934 J12934 merged commit 85c7a96 into main Jan 11, 2022
secureCodeBox v3 automation moved this from Reviewer approved to Done Jan 11, 2022
@J12934 J12934 deleted the fix/cascading-scan-logs branch January 11, 2022 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Cascading Scan hook logs "undefined" scan name
3 participants