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

Adds a log warning when falling back to default fake cert #3947

Conversation

vncntvandriessche
Copy link
Contributor

What this PR does / why we need it:
Adds a warning to the controller's log messages if a custom default certificate was passed but the controller falls back for #reason (err)

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

Special notes for your reviewer:

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 29, 2019
@@ -868,6 +868,7 @@ func (n *NGINXController) createServers(data []*ingress.Ingress,
// read custom default SSL certificate, fall back to generated default certificate
defaultCertificate, err := n.store.GetLocalSSLCert(n.cfg.DefaultSSLCertificate)
if err == nil {
klog.Warningf("Err loading custom default certificate, falling back to generated default:\n%v", err)
Copy link
Member

Choose a reason for hiding this comment

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

err is nil here

Copy link
Member

Choose a reason for hiding this comment

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

Also, please use "Error loading...."

Copy link
Contributor Author

@vncntvandriessche vncntvandriessche Mar 29, 2019

Choose a reason for hiding this comment

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

😅 Fixed!

@vncntvandriessche vncntvandriessche force-pushed the bug/silent-custom-default-certificate-failure branch from 3438dda to 907646e Compare March 29, 2019 16:21
@aledbf
Copy link
Member

aledbf commented Mar 29, 2019

@vncntvandriessche please change the code to something like

    // read custom default SSL certificate, fall back to generated default certificate
    if n.cfg.DefaultSSLCertificate != ""{
        defaultCertificate, err := n.store.GetLocalSSLCert(n.cfg.DefaultSSLCertificate)
        if err == nil {
            defaultPemFileName = defaultCertificate.PemFileName
            defaultPemSHA = defaultCertificate.PemSHA
        } else {
            klog.Warningf("Error loading custom default certificate, falling back to generated default:\n%v", err)
        }
    }

or the warning will flood the log

@vncntvandriessche vncntvandriessche force-pushed the bug/silent-custom-default-certificate-failure branch from 907646e to 2390205 Compare March 29, 2019 16:30
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 29, 2019
@vncntvandriessche
Copy link
Contributor Author

vncntvandriessche commented Mar 29, 2019

@aledbf I applied the changes as you suggested: 1 thing scares me:

defaultCertificate, err := n.store.GetLocalSSLCert(n.cfg.DefaultSSLCertificate)

before my change that was an action that always happened, but would fail due to the value of n.cfg.DefaultSSLCertificate being an empty string.

I'm wondering if it would be more future-proof to write it like so:

[...]
// original block
	if err == nil {
		defaultPemFileName = defaultCertificate.PemFileName
		defaultPemSHA = defaultCertificate.PemSHA
	}

// Addition
	if err != nil && n.cfg.DefaultSSLCertificate != "" {
		klog.Warningf("Error loading custom default certificate, falling back to generated default:\n%v", err)
	}
[...]

TL;DR: Just add the if-block at "Addition" under the original code instead of adding the else.

@aledbf
Copy link
Member

aledbf commented Mar 29, 2019

before my change that was an action that always happened, but would fail due to the value of n.cfg.DefaultSSLCertificate being an empty string.

The current code is fine. We should have a check for n.cfg.DefaultSSLCertificate not being empty in the previous version.

@vncntvandriessche
Copy link
Contributor Author

Alright! Thanks for the guidance.

@aledbf
Copy link
Member

aledbf commented Mar 31, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 31, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aledbf, vncntvandriessche

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 31, 2019
@k8s-ci-robot k8s-ci-robot merged commit 4bee401 into kubernetes:master Mar 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: --default-ssl-certificate does not raise an error if the certificate is not found
3 participants