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

Access check & logging framework refactor & update code-gen version #750

Merged
merged 13 commits into from
Mar 26, 2020

Conversation

shivdudhani
Copy link
Contributor

@shivdudhani shivdudhani commented Mar 18, 2020

pkg/engine/policyContext.go Outdated Show resolved Hide resolved
pkg/auth/auth.go Outdated Show resolved Hide resolved
pkg/engine/variables/common.go Outdated Show resolved Hide resolved
@shivdudhani
Copy link
Contributor Author

Added instructions to run code-generator at https://github.com/nirmata/kyverno/wiki/Building

@shivdudhani
Copy link
Contributor Author

Pending: Add instructions to change the verbosity of logs as a command-line argument.

@shivdudhani shivdudhani changed the title [WIP]Access check & logging framework refactor & update code-gen version Access check & logging framework refactor & update code-gen version Mar 20, 2020
@realshuting
Copy link
Member

It's a huge PR, gonna need help from @shravanshetty1 to review :)

@realshuting
Copy link
Member

Pending: Add instructions to change the verbosity of logs as a command-line argument.

Is this going to be added to this PR?

@shivdudhani
Copy link
Contributor Author

The documentation for setting in a part of Wiki, so will not be in this PR.

  • I just need to add some documentation and examples for logging in Wiki.

@realshuting
Copy link
Member

@shivdudhani Can you please add the link to Wiki once you have it?

@shivdudhani
Copy link
Contributor Author

@shravanshetty1
Copy link
Contributor

fixes #649

pkg/config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@shravanshetty1 shravanshetty1 left a comment

Choose a reason for hiding this comment

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

@shivdudhani @realshuting
I feel like instead of injecting loggers into each and every function - we should have a logger global variable for each package. Loggers are generally used this way.

We are still able to say who generated the logs since each package will have a log with unique name.

@shivdudhani
Copy link
Contributor Author

@shivdudhani @realshuting
I feel like instead of injecting loggers into each and every function - we should have a logger global variable for each package. Loggers are generally used this way.

We are still able to say who generated the logs since each package will have a log with unique name.

In this PR we are just moving to a new framework for logging. The previous implementation was not modified. Previously we didn't have options to provide context for debugging, but with this we do.

Log provides withName to give context for the logs, and the reason for passing them from root to bottom function is to provide a complete stack trace for the error log.
The logs are not defined per package but per component.

Instead of using global variables in a package, it would be better to have each struct manage its own to logs. If the logs are not to be passed, then the generic/base implementation of the log can be used.

The pkg sigs.k8s.io/controller-runtime/pkg/log exposes a variable Log which refers to the base logger implementation.

@shravanshetty1
Copy link
Contributor

shravanshetty1 commented Mar 26, 2020

@shivdudhani @realshuting
I feel like instead of injecting loggers into each and every function - we should have a logger global variable for each package. Loggers are generally used this way.
We are still able to say who generated the logs since each package will have a log with unique name.

In this PR we are just moving to a new framework for logging. The previous implementation was not modified. Previously we didn't have options to provide context for debugging, but with this we do.

Log provides withName to give context for the logs, and the reason for passing them from root to bottom function is to provide a complete stack trace for the error log.
The logs are not defined per package but per component.

Instead of using global variables in a package, it would be better to have each struct manage its own to logs. If the logs are not to be passed, then the generic/base implementation of the log can be used.

The pkg sigs.k8s.io/controller-runtime/pkg/log exposes a variable Log which refers to the base logger implementation.

That makes sense.
If we are going with the current implementation, i feel we should use base log for all functions and we should only use injected logs for methods. If we NEED to inject logs to a function we should make it a method. Pointer receiver methods have no overhead over calling a function directly.

We could make this an ongoing change like godoc comments - this has to be documented in the contributor docs though.

@shivdudhani
Copy link
Contributor Author

@shivdudhani @realshuting
I feel like instead of injecting loggers into each and every function - we should have a logger global variable for each package. Loggers are generally used this way.
We are still able to say who generated the logs since each package will have a log with unique name.

In this PR we are just moving to a new framework for logging. The previous implementation was not modified. Previously we didn't have options to provide context for debugging, but with this we do.
Log provides withName to give context for the logs, and the reason for passing them from root to bottom function is to provide a complete stack trace for the error log.
The logs are not defined per package but per component.
Instead of using global variables in a package, it would be better to have each struct manage its own to logs. If the logs are not to be passed, then the generic/base implementation of the log can be used.
The pkg sigs.k8s.io/controller-runtime/pkg/log exposes a variable Log which refers to the base logger implementation.

That makes sense.
If we are going with the current implementation, i feel we should use base log for all functions and we should only use injected logs for methods. If we NEED to inject logs to a function we should make it a method. Pointer receiver methods have no overhead over calling a function directly.

We could make this an ongoing change like godoc comments - this has to be documented in the contributor docs though.

I didn't understand the comment injected logs for methods, Can you explain with an example?

A developer can use the logging framework they want, as long as the logs provides details for debugging. Storing the logger interface as a variable in a struct or passed as a function parameter is up to the design.

The idea of building context is based on the kubebuilder controller-runtime patterns.

@shravanshetty1
Copy link
Contributor

@shivdudhani @realshuting
I feel like instead of injecting loggers into each and every function - we should have a logger global variable for each package. Loggers are generally used this way.
We are still able to say who generated the logs since each package will have a log with unique name.

In this PR we are just moving to a new framework for logging. The previous implementation was not modified. Previously we didn't have options to provide context for debugging, but with this we do.
Log provides withName to give context for the logs, and the reason for passing them from root to bottom function is to provide a complete stack trace for the error log.
The logs are not defined per package but per component.
Instead of using global variables in a package, it would be better to have each struct manage its own to logs. If the logs are not to be passed, then the generic/base implementation of the log can be used.
The pkg sigs.k8s.io/controller-runtime/pkg/log exposes a variable Log which refers to the base logger implementation.

That makes sense.
If we are going with the current implementation, i feel we should use base log for all functions and we should only use injected logs for methods. If we NEED to inject logs to a function we should make it a method. Pointer receiver methods have no overhead over calling a function directly.
We could make this an ongoing change like godoc comments - this has to be documented in the contributor docs though.

I didn't understand the comment injected logs for methods, Can you explain with an example?

A developer can use the logging framework they want, as long as the logs provides details for debugging. Storing the logger interface as a variable in a struct or passed as a function parameter is up to the design.

The idea of building context is based on the kubebuilder controller-runtime patterns.

we can add logger in reciever of methods (functions with reciever arguments). However for normal function (no reciever arguments) we should use base logs.

@realshuting realshuting merged commit 589f8ec into master Mar 26, 2020
@realshuting realshuting deleted the access_check branch March 26, 2020 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants