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

🐛 Show vanished resources as unscored #131

Merged
merged 8 commits into from
Oct 24, 2022

Conversation

czunker
Copy link
Contributor

@czunker czunker commented Oct 19, 2022

We now check for a specific error type, to check whether a k8s resource vanished.

Signed-off-by: Christian Zunker [email protected]

@@ -315,6 +318,16 @@ func (nodeData *ReportingQueryNodeData) score() *policy.Score {
break
}

if cur.Data.Error != nil && strings.HasSuffix(cur.Data.Error.Error(), "not found") {
Copy link
Contributor

Choose a reason for hiding this comment

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

i feel like it would be possible for a lot of different errors to have a "not found" error that doesn't mean the asset went away

Copy link
Contributor

Choose a reason for hiding this comment

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

perhaps we can define some common errors and check for those. If the asset is disconnected, the provider should return that error type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've changed the error message where it is created to be more precise: mondoohq/cnquery#361

I think, now that I have the point where the message is created, I could also create a specific error type out of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@@ -347,7 +360,16 @@ func (nodeData *ReportingQueryNodeData) score() *policy.Score {
}

if allFound {
if foundError {
if assetVanishedDuringScan {
Copy link
Contributor

Choose a reason for hiding this comment

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

In general, a suggestion:
I feel like we should be able to mark assets themselves as ephemeral (can tie either with asset type or provider type maybe?) and act accordingly.
I think a better way to fix this would be when starting the scan: if the asset does not exist then, we should be able to report accordingly upstream.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we should be able to mark assets themselves as ephemeral

That sound like a much bigger topic

I think a better way to fix this would be when starting the scan: if the asset does not exist then, we should be able to report accordingly upstream.

I'm not sure I understand your point completely. Would changing mondoohq/cnquery#361 into a specific error type be what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I totally agree it's a bigger topic, for sure not something that can be done quickly.

I was thinking more along the lines of having a specific error type that can be thrown if the resource does not exist rather than relying on the message inside the error

Copy link
Contributor Author

@czunker czunker Oct 24, 2022

Choose a reason for hiding this comment

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

I implemented a k8s specific error type in cnquery and check for it: mondoohq/cnquery#361

@czunker czunker changed the title WIP: 🐛 Show vanished resources as unscored 🐛 Show vanished resources as unscored Oct 24, 2022
@czunker czunker marked this pull request as ready for review October 24, 2022 04:31
@czunker
Copy link
Contributor Author

czunker commented Oct 24, 2022

Tests will only pass when mondoohq/cnquery#361 is merged and updated here.

@czunker czunker force-pushed the christian/fix_vanished_resources branch from 883b02c to 5675d11 Compare October 24, 2022 12:23
DO NOT MERGE!

This is work in progress!

Signed-off-by: Christian Zunker <[email protected]>
Signed-off-by: Christian Zunker <[email protected]>
Signed-off-by: Christian Zunker <[email protected]>
Signed-off-by: Christian Zunker <[email protected]>
@czunker czunker force-pushed the christian/fix_vanished_resources branch from 5675d11 to 2964577 Compare October 24, 2022 12:27
@@ -316,8 +320,13 @@ func (nodeData *ReportingQueryNodeData) score() *policy.Score {
}

if cur.Data.Error != nil {
allSkipped = false
foundError = true
var k8sNotFoundErr *k8s_common.K8sResourceNotFound
Copy link
Contributor

Choose a reason for hiding this comment

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

we should avoid making this code dependent on k8s specific logic. Can we create an error of type asset disconnected or something like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR to include the new cnquery. Now I check for the general error.

Signed-off-by: Christian Zunker <[email protected]>
Signed-off-by: Christian Zunker <[email protected]>
@czunker czunker merged commit 36a13b8 into main Oct 24, 2022
@czunker czunker deleted the christian/fix_vanished_resources branch October 24, 2022 17:35
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants