Skip to content

Conversation

prady0t
Copy link
Contributor

@prady0t prady0t commented Jul 9, 2023

Signed-off-by: Pradyot Ranjan rickprimeranjan@gmail.com

Explanation

There were no log messages for API call failures. dl.logger.Error(err, "Failed to load data: ") now prints the error along with log message.

Related issue

Closes #7734
Closes #4774

Milestone of this PR

/milestone 1.10.2

What type of PR is this

Proposed Changes

Proof Manifests

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.
  • This is a feature and I have added CLI tests that are applicable.
  • My PR needs to be cherry picked to a specific release branch which is .
  • My PR contains new or altered behavior to Kyverno and
    • CLI support should be added and my PR doesn't contain that functionality.
    • I have added or changed the documentation myself in an existing PR and the link is:
    • I have raised an issue in kyverno/website to track the documentation update and the link is:

Further Comments

@welcome
Copy link

welcome bot commented Jul 9, 2023

Thanks for opening your first Pull Request here! Please check out our Contributing guidelines and confirm that you Signed off.

@prady0t prady0t force-pushed the main branch 2 times, most recently from a6bc2e5 to 1ed9fa9 Compare July 9, 2023 20:43
@chipzoller
Copy link
Contributor

chipzoller commented Jul 10, 2023

@prady0t, please show in the Proof section what this log message looks like when generated and how we can test your code to see it for ourselves. Also, please use correct closing keywords; "solves" will not automatically link to an issue. Please follow and complete the PR template as requested.

@prady0t
Copy link
Contributor Author

prady0t commented Jul 11, 2023

@chipzoller Sorry for the incomplete PR. I'll make required changes. I'm having some query regarding cli output which I asked earlier on slack. Can you please help me with that?
Discussion link -> https://kubernetes.slack.com/archives/C032MM2CH7X/p1689022298176299?thread_ts=1688386337.541699&cid=C032MM2CH7X

@realshuting
Copy link
Member

@prady0t - the changes break the builds, can you fix it?

@prady0t
Copy link
Contributor Author

prady0t commented Jul 11, 2023

@realshuting It fails because of this: not enough arguments in call to enginecontext.NewDeferredLoader Let me pass
logr.Logger{} as the argument to enginecontext.NewDeferredLoader in that way built will not fail.

@codecov
Copy link

codecov bot commented Jul 11, 2023

Codecov Report

Merging #7792 (c7f05c5) into main (5b9c13a) will decrease coverage by 0.11%.
The diff coverage is 16.01%.

❗ Current head c7f05c5 differs from pull request most recent head 6fd7739. Consider uploading reports for the commit 6fd7739 to get more accurate results

@@            Coverage Diff             @@
##             main    #7792      +/-   ##
==========================================
- Coverage   32.97%   32.87%   -0.11%     
==========================================
  Files         234      239       +5     
  Lines       22426    22515      +89     
==========================================
+ Hits         7396     7402       +6     
- Misses      14272    14354      +82     
- Partials      758      759       +1     
Impacted Files Coverage Δ
api/kyverno/v1/clusterpolicy_types.go 15.90% <0.00%> (-0.76%) ⬇️
api/kyverno/v1/policy_types.go 15.90% <0.00%> (-0.76%) ⬇️
api/kyverno/v1/spec_types.go 17.03% <0.00%> (-0.66%) ⬇️
api/kyverno/v1/zz_generated.defaults.go 0.00% <0.00%> (ø)
api/kyverno/v2alpha1/zz_generated.deepcopy.go 0.00% <0.00%> (ø)
api/kyverno/v2alpha1/zz_generated.defaults.go 0.00% <0.00%> (ø)
api/kyverno/v2beta1/clusterpolicy_types.go 18.42% <0.00%> (-1.03%) ⬇️
api/kyverno/v2beta1/policy_types.go 18.42% <0.00%> (-1.03%) ⬇️
api/kyverno/v2beta1/spec_types.go 18.34% <0.00%> (-0.89%) ⬇️
api/kyverno/v2beta1/zz_generated.deepcopy.go 0.00% <0.00%> (ø)
... and 46 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@chipzoller
Copy link
Contributor

Suspected to close #4774

Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

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

Please fix the linter issue.

@@ -85,30 +85,30 @@ func (l *contextLoader) newLoader(
if entry.ConfigMap != nil {
if l.cmResolver != nil {
l := loaders.NewConfigMapLoader(ctx, l.logger, entry, l.cmResolver, jsonContext)
return enginecontext.NewDeferredLoader(entry.Name, l)
return enginecontext.NewDeferredLoader(entry.Name, l, logr.Logger{})
Copy link
Member

Choose a reason for hiding this comment

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

There's a logger built in l, you should re-use 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.

To use l.logger which is builtin, I would have to rename l here:

l := loaders.NewConfigMapLoader(ctx, l.logger, entry, l.cmResolver, jsonContext)

Otherwise it creates conflicts here while giving l.logger as a parameter:
return enginecontext.NewDeferredLoader(entry.Name, l)

Should I rename it to something like lm everywhere?

@prady0t
Copy link
Contributor Author

prady0t commented Jul 13, 2023

Please fix the linter issue.

I'm sorry but I can't see the linter issue anymore. Can you please approve linter workflow so that I can see why it's failing? Or maybe you can suggest how to fix.

Copy link
Member

@JimBugwadia JimBugwadia 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! A few minor comments.

@@ -34,7 +37,11 @@ func (dl *deferredLoader) HasLoaded() bool {
}

func (dl *deferredLoader) LoadData() error {
return dl.loader.LoadData()
if err := dl.loader.LoadData(); err != nil {
dl.logger.Error(err, "Failed to load data: ")
Copy link
Member

Choose a reason for hiding this comment

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

Please start log messages with a lower case. It would also be helpful to add the name.

dl.logger.Errorf(err, "failed to load data for %s", dl.name)

@@ -85,30 +85,30 @@ func (l *contextLoader) newLoader(
if entry.ConfigMap != nil {
if l.cmResolver != nil {
l := loaders.NewConfigMapLoader(ctx, l.logger, entry, l.cmResolver, jsonContext)
return enginecontext.NewDeferredLoader(entry.Name, l)
return enginecontext.NewDeferredLoader(entry.Name, l, logr.Logger{})
} else {
l.logger.Info("disabled loading of ConfigMap context entry %s", entry.Name)
return nil, nil
}
} else if entry.APICall != nil {
if client != nil {
l := loaders.NewAPILoader(ctx, l.logger, entry, jsonContext, jp, client)
Copy link
Member

Choose a reason for hiding this comment

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

You can rename the l in l := loaders.NewAPILoader(... to something like ldr.

@prady0t
Copy link
Contributor Author

prady0t commented Jul 13, 2023

Sorry for similar commits. DCO test keeps on failing even with the signed-off message

@MarcelMue
Copy link
Contributor

Sorry for similar commits. DCO test keeps on failing even with the signed-off message

All commits need to be signed - so if you only sign the latest one, it won't work. I would recommend that you squash the commits in this PR and sign the single commit then.

@prady0t
Copy link
Contributor Author

prady0t commented Jul 14, 2023

Sorry for similar commits. DCO test keeps on failing even with the signed-off message

All commits need to be signed - so if you only sign the latest one, it won't work. I would recommend that you squash the commits in this PR and sign the single commit then.

@MarcelMue I think i messed up somewhere as I'm unable to do that (maybe because I keep merging remote-tracking branch into main). Should I close this PR and make a new one?

@MarcelMue
Copy link
Contributor

Sorry for similar commits. DCO test keeps on failing even with the signed-off message

All commits need to be signed - so if you only sign the latest one, it won't work. I would recommend that you squash the commits in this PR and sign the single commit then.

@MarcelMue I think i messed up somewhere as I'm unable to do that (maybe because I keep merging remote-tracking branch into main). Should I close this PR and make a new one?

What have you tried? I feel like solution like this should "just work":
https://stackoverflow.com/a/50880042

Just make sure you sign the commit in step two described on stackoverflow.

@prady0t
Copy link
Contributor Author

prady0t commented Jul 14, 2023

Sorry for similar commits. DCO test keeps on failing even with the signed-off message

All commits need to be signed - so if you only sign the latest one, it won't work. I would recommend that you squash the commits in this PR and sign the single commit then.

@MarcelMue I think i messed up somewhere as I'm unable to do that (maybe because I keep merging remote-tracking branch into main). Should I close this PR and make a new one?

What have you tried? I feel like solution like this should "just work": https://stackoverflow.com/a/50880042

Just make sure you sign the commit in step two described on stackoverflow.

Ah! this is what I was looking for. Thanks for the help

@prady0t
Copy link
Contributor Author

prady0t commented Jul 14, 2023

@MarcelMue The above method was not working so I read DCO docs and did this instead : git rebase HEAD~17 --signoff and then git push --force-with-lease origin main which produced these results🥲. What should I do?

@prady0t
Copy link
Contributor Author

prady0t commented Jul 15, 2023

I've made another PR with same changes. Please review. #7834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show APICall failures in logs improve error handling for generate policy when an apiCall does not work
6 participants