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

Use the controller-runtime logger in the cert-generator #2219

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

tenzen-y
Copy link
Member

What this PR does / why we need it:

Currently, we use the klog in the cert-generator and the controller-runtime logger in other controllers, such as the experiment-controller. So the manager output logs using a different format from the other controllers for the cert-generator, as shown below:

...
{"level":"info","ts":"2023-08-18T04:36:53Z","msg":"Starting server","kind":"health probe","addr":"[::]:18080"}
{"level":"info","ts":"2023-08-18T04:36:53Z","msg":"starting server","path":"/metrics","kind":"metrics","addr":"[::]:8080"}
I0818 04:36:54.087010       1 generator.go:199] Generating self-signed public certificate and private key.
{"level":"info","ts":"2023-08-18T04:36:54Z","logger":"controller-runtime.healthz","msg":"healthz check failed","statuses":[{}]}
I0818 04:36:54.334683       1 generator.go:255] Trying to patch ValidatingWebhookConfiguration adding the caBundle.
I0818 04:36:54.441560       1 generator.go:282] Trying to patch MutatingWebhookConfiguration adding the caBundle.
...

However, we should use the same format to improve the visibility of the logs in the manager.
So I replaced the cert-generator logger with the same as the other controllers one:

var (
log = logf.Log.WithName(ControllerName)
)

After applying this patch, the manager will output logs in the following:

...
{"level":"info","ts":"2023-08-18T04:38:16Z","msg":"Starting server","kind":"health probe","addr":"[::]:18080"}
{"level":"info","ts":"2023-08-18T04:38:16Z","msg":"starting server","path":"/metrics","kind":"metrics","addr":"[::]:8080"}
{"level":"info","ts":"2023-08-18T04:38:16Z","logger":"controller-runtime.healthz","msg":"healthz check failed","statuses":[{}]}
{"level":"info","ts":"2023-08-18T04:38:16Z","logger":"cert-generator","msg":"Waiting for certs to get ready."}
{"level":"info","ts":"2023-08-18T04:38:16Z","logger":"cert-generator","msg":"Succeeded to be mounted certs inside the container."}
...

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #

Checklist:

  • Docs included if any changes are user facing

@google-oss-prow
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tenzen-y

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Member

@andreyvelich andreyvelich left a comment

Choose a reason for hiding this comment

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

Thank you for the update @tenzen-y!

}
return false, nil
}
keyFile := filepath.Join(consts.CertDir, serverKeyName)
if _, err := os.Stat(keyFile); err != nil {
if outputLog {
klog.Infof("Private key file %q doesn't exist in the container yet", keyFile)
log.Info("Private key file %q doesn't exist in the container yet", "privateKeyFile", keyFile)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Info("Private key file %q doesn't exist in the container yet", "privateKeyFile", keyFile)
log.Info("Private key file doesn't exist in the container yet.", "privateKeyFile", keyFile)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, that's right.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -98,18 +100,18 @@ func ensureCertMounted(start time.Time) func(context.Context) (bool, error) {
certFile := filepath.Join(consts.CertDir, serverCertName)
if _, err := os.Stat(certFile); err != nil {
if outputLog {
klog.Infof("Public key file %q doesn't exist in the container yet", certFile)
log.Info("Public key file %q doesn't exist in the container yet.", "publicKeyFile", certFile)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Info("Public key file %q doesn't exist in the container yet.", "publicKeyFile", certFile)
log.Info("Public key file doesn't exist in the container yet.", "publicKeyFile", certFile)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

Signed-off-by: Yuki Iwai <yuki.iwai.tz@gmail.com>
@andreyvelich
Copy link
Member

Thank you @tenzen-y!
/lgtm

@google-oss-prow google-oss-prow bot added the lgtm label Aug 18, 2023
@google-oss-prow google-oss-prow bot merged commit 87a0161 into kubeflow:master Aug 18, 2023
58 checks passed
@tenzen-y tenzen-y deleted the use-the-same-logger branch August 18, 2023 17:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants