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

Deprecate klog flags and add a deprecation message #5879

Merged
merged 1 commit into from Aug 25, 2023

Conversation

maelvls
Copy link
Member

@maelvls maelvls commented Mar 21, 2023

Many klog flags have been marked as deprecated in Kubernetes 1.23 (as per KEP-2845) and will go away in Kubernetes 1.26. I propose that we follow the same path for the same reasons.

Plan:

  • cert-manager 1.12 (end of April 2023): start of the deprecation period for the flags --log_dir, --log_file, --log_flush_frequency, --logtostderr, --alsologtostderr, --one_output, --stderrthreshold, --log_file_max_size, --skip_log_headers, --add_dir_header, --skip_headers, --log_backtrace_at.
  • cert-manager 1.15 (approx 6 month afterwards, Nov 2023): removal of the flags. We do not have a planned version in which we will remove the flags.

This PR adds a warning message that shows in two places:

  • when using --help, the user will see the message DEPRECATED: this flag may be removed in the future.
  • when using one of the deprecated flags, the user will see a line warning them (unfortunately, this line isn't JSON formatted):
    $ go run ./cmd/controller --log_dir=/tmp
    Flag --log_dir has been deprecated, this flag may be removed in the future
    

Before/after:

Commands
git checkout master && go run ./cmd/controller --help | cut -c-60 >/tmp/before 
gh pr checkout 5879 && go run ./cmd/controller --help | cut -c-60 >/tmp/after
diff -u /tmp/before /tmp/after
--- /tmp/before    2023-03-23 11:54:35.830525057 +0100
+++ /tmp/after     2023-03-23 11:54:35.830525057 +0100
empty diff

Deprecated flags:

$ go run ./cmd/controller --help | grep DEPRECATED | awk '{print $1}'
--add_dir_header
--alsologtostderr
--log_backtrace_at
--log_dir
--log_file
--log_file_max_size
--logtostderr
--one_output
--skip_headers
--skip_log_headers
--stderrthreshold
A subset of the klogs flags have been deprecated and will be removed in the future.

/kind cleanup

Notes to the reviewer:

  • In order to display deprecation warnings, I swapped flag with github.com/spf13/pflag. We already import pflag, so I thought it would not be an issue.

@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 21, 2023
@jetstack-bot jetstack-bot added the area/testing Issues relating to testing label Mar 21, 2023
@SgtCoDFish
Copy link
Member

As mentioned in standup, the diff in the original doesn't have a corresponding line for this removal:

-      --log-flush-frequency duration                        Maximum number of seconds between log flushes (default 5s)

Also a couple of other things:

when using one of the deprecated flags, the user will see a line warning them (unfortunately, this line isn't JSON formatted):

question: Why is the deprecation notice not available in JSON? Is it too early to have parsed whether the user requested JSON logging or something?

cert-manager 1.15 (approx 6 month afterwards, Nov 2023): removal of the flags.

suggestion: I worry that this timeline is far too aggressive. If these flags become no-ops, then they don't provide a huge maintenance burden on us and they do no harm if the user sets them (other than the risk of a user expecting something to happen which won't happen)

I'd actually prefer to never remove these flags because it's (IMO) not a good enough reason to break people.

But if we must remove them, I think I'd rather give users (a lot) more time. That could potentially include a time.Sleep(n*5*time.Second) which runs if any of these flags were set, where n grows in each release to encourage users to remove the flags (since cert-manager will "hang" on startup if any of these flags were passed).

What do you think?

@maelvls
Copy link
Member Author

maelvls commented Mar 23, 2023

This timeline is far too aggressive.

I agree, there is no good reason to remove these flags at the moment. Klog still supports them. The only long-term reason would be that one day klog 3.0 might be released, and we might want to migrate to it (I have only heard of klog 3.0 in the KEP-2845).

For context, the reason Kubernetes is migrating away from these flags is because they want to use a Go struct to configure logging (as opposed to using e.g. flag.Set("alsologtostderr", ...)).

For now, I will remove the warning about these flags being removed in cert-manager 1.15. I changed the warning to:

Flag --log_dir has been deprecated, this flag may be removed in the future

Why is the deprecation notice not available in JSON?

It looks like pflag uses fmt.Fprintf directly for the deprecation message in flag.go:

fmt.Fprintf(f.Output(), "Flag --%s has been deprecated, %s\n", flag.Name, flag.Deprecated)

It is most probably because this message is printed while the flags are being parsed: the logger isn't configured yet and can't be used. I wish it was handled better... but it seems like it is a good enough solution

--log-flush-frequency duration removed?

Ah, my mistake. I forgot to change one reference to flag to pflag.

@SgtCoDFish
Copy link
Member

For now, I will remove the warning about these flags being removed in cert-manager 1.15

Thanks, that looks great!

It looks like pflag uses fmt.Fprintf directly for the deprecation message in flag.go...

Ah yeah... I can see why that happens. It's a shame but it's not the end of the world - especially if we don't remove the flags any time soon!

Thanks for working on this 😁

@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 5, 2023
@jetstack-bot jetstack-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 6, 2023
@maelvls
Copy link
Member Author

maelvls commented Apr 6, 2023

I propose that we go ahead with this. Would you LGTM @SgtCoDFish?

Update 14 April 2023: I need to rework this after the changes made in #5828.

@inteon inteon added this to the v1.12 milestone Apr 28, 2023
@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 4, 2023
@irbekrm irbekrm removed this from the v1.12 milestone May 23, 2023
@inteon inteon added this to the 1.13 milestone Jul 4, 2023
@inteon inteon modified the milestones: 1.13, 1.14 Aug 15, 2023
@inteon inteon self-assigned this Aug 25, 2023
Signed-off-by: Maël Valais <mael@vls.dev>
@jetstack-bot jetstack-bot removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Aug 25, 2023
@jetstack-bot jetstack-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Aug 25, 2023
@inteon
Copy link
Member

inteon commented Aug 25, 2023

I propose that we go ahead with this. Would you LGTM @SgtCoDFish?

Update 14 April 2023: I need to rework this after the changes made in #5828.

I rebased the PR.

@inteon inteon modified the milestones: 1.14, 1.13 Aug 25, 2023
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

We discussed this in the standup today (2023-08-25) and agreed this is a good improvement - thanks 😁

Only caveat from me (which doesn't directly affect this PR) is that I strongly believe we shouldn't remove these flags in any future release - cert-manager shouldn't break because of this. We should make them no-ops which just print that they're a no-op though.

(motivation: if I've been installing cert-manager with - excuse the incorrect syntax - helm install --set 'extraArgs=one_output for a while, I shouldn't see a break if I continue to use that parameter!)

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 25, 2023
@jetstack-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: maelvls, SgtCoDFish

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

@inteon
Copy link
Member

inteon commented Aug 25, 2023

/lgtm /approve

We discussed this in the standup today (2023-08-25) and agreed this is a good improvement - thanks 😁

Only caveat from me (which doesn't directly affect this PR) is that I strongly believe we shouldn't remove these flags in any future release - cert-manager shouldn't break because of this. We should make them no-ops which just print that they're a no-op though.

(motivation: if I've been installing cert-manager with - excuse the incorrect syntax - helm install --set 'extraArgs=one_output for a while, I shouldn't see a break if I continue to use that parameter!)

The message says "DEPRECATED: this flag may be removed in the future", but we might just remove the implementation and still allow setting the flag. Or just keep the functionality but hide the flags.
The main goal is to indicate that ideally you should not use the flags & that if they are removed upstream, less of our users are affected.

@SgtCoDFish
Copy link
Member

/test pull-cert-manager-master-e2e-v1-28

@jetstack-bot jetstack-bot merged commit 9ebc08c into cert-manager:master Aug 25, 2023
8 checks passed
@maelvls maelvls deleted the structured-logs-deprecate branch August 25, 2023 15:11
nrdufour added a commit to nrdufour/home-ops that referenced this pull request Sep 12, 2023
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cert-manager](https://github.com/cert-manager/cert-manager) | minor | `v1.12.4` -> `v1.13.0` |

---

### Release Notes

<details>
<summary>cert-manager/cert-manager (cert-manager)</summary>

### [`v1.13.0`](https://github.com/cert-manager/cert-manager/releases/tag/v1.13.0)

[Compare Source](cert-manager/cert-manager@v1.12.4...v1.13.0)

cert-manager is the easiest way to automatically manage certificates in Kubernetes and OpenShift clusters.

This is the 1.13 release of cert-manager!

#### Community

Welcome to these new cert-manager members (more info - cert-manager/cert-manager#6260):
[@&#8203;jsoref](https://github.com/jsoref)
[@&#8203;FlorianLiebhart](https://github.com/FlorianLiebhart)
[@&#8203;hawksight](https://github.com/hawksight)
[@&#8203;erikgb](https://github.com/erikgb)

Thanks again to all open-source contributors with commits in this release, including:
[@&#8203;AcidLeroy](https://github.com/AcidLeroy)
[@&#8203;FlorianLiebhart](https://github.com/FlorianLiebhart)
[@&#8203;lucacome](https://github.com/lucacome)
[@&#8203;cypres](https://github.com/cypres)
[@&#8203;erikgb](https://github.com/erikgb)
[@&#8203;ubergesundheit](https://github.com/ubergesundheit)
[@&#8203;jkroepke](https://github.com/jkroepke)
[@&#8203;jsoref](https://github.com/jsoref)
[@&#8203;gdvalle](https://github.com/gdvalle)
[@&#8203;rouke-broersma](https://github.com/rouke-broersma)
[@&#8203;schrodit](https://github.com/schrodit)
[@&#8203;zhangzhiqiangcs](https://github.com/zhangzhiqiangcs)
[@&#8203;arukiidou](https://github.com/arukiidou)
[@&#8203;hawksight](https://github.com/hawksight)
[@&#8203;Richardds](https://github.com/Richardds)
[@&#8203;kahirokunn](https://github.com/kahirokunn)

Thanks also to the following cert-manager maintainers for their contributions during this release:
[@&#8203;SgtCoDFish](https://github.com/SgtCoDFish)
[@&#8203;maelvls](https://github.com/maelvls)
[@&#8203;irbekrm](https://github.com/irbekrm)
[@&#8203;inteon](https://github.com/inteon)

Equally thanks to everyone who provided feedback, helped users and raised issues on Github and Slack and joined our meetings!

Special thanks to [@&#8203;AcidLeroy](https://github.com/AcidLeroy) for adding "load options from a versioned config file" support for the cert-manager controller! This has been on our wishlist for a very long time. (see cert-manager/cert-manager#5337)

Also, thanks a lot to [@&#8203;FlorianLiebhart](https://github.com/FlorianLiebhart) for adding support for DNS over HTTPS for the ACME DNS self-check. This is very useful in case all traffic must be HTTP(S) trafic, eg. when using a HTTPS_PROXY. (see cert-manager/cert-manager#5003)

Thanks also to the [CNCF](https://www.cncf.io/), which provides resources and support, and to the AWS open source team for being good community members and for their maintenance of the [PrivateCA Issuer](https://github.com/cert-manager/aws-privateca-issuer).

In addition, massive thanks to [Venafi](https://www.venafi.com/) for contributing developer time and resources towards the continued maintenance of cert-manager projects.

#### Changes since v1.12.0

##### Feature

-   Add support for logging options to webhook config file. ([#&#8203;6243](cert-manager/cert-manager#6243), [@&#8203;inteon](https://github.com/inteon))
-   Add view permissions to the well-known (Openshift) user-facing `cluster-reader` aggregated cluster role ([#&#8203;6241](cert-manager/cert-manager#6241), [@&#8203;erikgb](https://github.com/erikgb))
-   Certificate Shim: distinguish dns names and ip address in certificate ([#&#8203;6267](cert-manager/cert-manager#6267), [@&#8203;zhangzhiqiangcs](https://github.com/zhangzhiqiangcs))
-   Cmctl can now be imported by third parties. ([#&#8203;6049](cert-manager/cert-manager#6049), [@&#8203;SgtCoDFish](https://github.com/SgtCoDFish))
-   Make `enableServiceLinks` configurable for all Deployments and `startupapicheck` Job in Helm chart. ([#&#8203;6292](cert-manager/cert-manager#6292), [@&#8203;ubergesundheit](https://github.com/ubergesundheit))
-   Promoted the StableCertificateRequestName and SecretsFilteredCaching feature gates to Beta (enabled by default). ([#&#8203;6298](cert-manager/cert-manager#6298), [@&#8203;inteon](https://github.com/inteon))
-   The cert-manager controller options are now configurable using a configuration file. ([#&#8203;5337](cert-manager/cert-manager#5337), [@&#8203;AcidLeroy](https://github.com/AcidLeroy))
-   The pki CertificateTemplate functions now perform validation of the CSR blob, making sure we sign a Certificate that matches the IsCA and (Extended)KeyUsages that are defined in the CertificateRequest resource. ([#&#8203;6199](cert-manager/cert-manager#6199), [@&#8203;inteon](https://github.com/inteon))
-   \[helm] Add prometheus.servicemonitor.endpointAdditionalProperties to define additional properties on a ServiceMonitor endpoint, e.g. relabelings ([#&#8203;6110](cert-manager/cert-manager#6110), [@&#8203;jkroepke](https://github.com/jkroepke))

##### Design

-   DNS over HTTPS (DoH) is now possible for doing the self-checks during the ACME verification.
    The DNS check method to be used is controlled through the command line flag: `--dns01-recursive-nameservers-only=true` in combination with `--dns01-recursive-nameservers=https://<DoH-endpoint>` (e.g. `https://8.8.8.8/dns-query`). It keeps using DNS lookup as a default method. ([#&#8203;5003](cert-manager/cert-manager#5003), [@&#8203;FlorianLiebhart](https://github.com/FlorianLiebhart))

##### Bug or Regression

-   Allow overriding default pdb .minAvailable with .maxUnavailable without setting .minAvailable to null ([#&#8203;6087](cert-manager/cert-manager#6087), [@&#8203;rouke-broersma](https://github.com/rouke-broersma))
-   BUGFIX: `cmctl check api --wait 0` exited without output and exit code 1; we now make sure we perform the API check at least once and return with the correct error code ([#&#8203;6109](cert-manager/cert-manager#6109), [@&#8203;inteon](https://github.com/inteon))
-   BUGFIX: the issuer and certificate-name annotations on a Secret were incorrectly updated when other fields are changed. ([#&#8203;6147](cert-manager/cert-manager#6147), [@&#8203;inteon](https://github.com/inteon))
-   BUGFIX\[cainjector]: 1-character bug was causing invalid log messages and a memory leak ([#&#8203;6232](cert-manager/cert-manager#6232), [@&#8203;inteon](https://github.com/inteon))
-   Fix CloudDNS issuers stuck in propagation check, when multiple instances are issuing for the same FQDN ([#&#8203;6088](cert-manager/cert-manager#6088), [@&#8203;cypres](https://github.com/cypres))
-   Fix indentation of Webhook NetworkPolicy matchLabels in helm chart. ([#&#8203;6220](cert-manager/cert-manager#6220), [@&#8203;ubergesundheit](https://github.com/ubergesundheit))
-   Fixed Cloudflare DNS01 challenge provider race condition when validating multiple domains ([#&#8203;6191](cert-manager/cert-manager#6191), [@&#8203;Richardds](https://github.com/Richardds))
-   Fixes a bug where webhook was pulling in controller's feature gates.
    ⚠️  ⚠️ BREAKING ⚠️ ⚠️ : If you deploy cert-manager using helm and have `.featureGates` value set, the features defined there will no longer be passed to cert-manager webhook, only to cert-manager controller. Use `webhook.featureGates` field instead to define features to be enabled on webhook.
    **Potentially breaking**: If you were, for some reason, passing cert-manager controller's features to webhook's `--feature-gates` flag, this will now break (unless the webhook actually has a feature by that name). ([#&#8203;6093](cert-manager/cert-manager#6093), [@&#8203;irbekrm](https://github.com/irbekrm))
-   Fixes an issue where cert-manager would incorrectly reject two IP addresses as being unequal when they should have compared equal. This would be most noticeable when using an IPv6 address which doesn't match how Go's `net.IP.String()` function would have printed that address. ([#&#8203;6293](cert-manager/cert-manager#6293), [@&#8203;SgtCoDFish](https://github.com/SgtCoDFish))
-   We disabled the `enableServiceLinks` option for our ACME http solver pods, because the option caused the pod to be in a crash loop in a cluster with lot of services. ([#&#8203;6143](cert-manager/cert-manager#6143), [@&#8203;schrodit](https://github.com/schrodit))
-   ⚠️ possibly breaking: Webhook validation of CertificateRequest resources is stricter now: all KeyUsages and ExtendedKeyUsages must be defined directly in the CertificateRequest resource, the encoded CSR can never contain more usages that defined there. ([#&#8203;6182](cert-manager/cert-manager#6182), [@&#8203;inteon](https://github.com/inteon))

##### Other (Cleanup or Flake)

-   A subset of the klogs flags have been deprecated and will be removed in the future. ([#&#8203;5879](cert-manager/cert-manager#5879), [@&#8203;maelvls](https://github.com/maelvls))
-   All service links in helm chart deployments have been disabled. ([#&#8203;6144](cert-manager/cert-manager#6144), [@&#8203;schrodit](https://github.com/schrodit))
-   Cert-manager will now re-issue a certificate if the public key in the latest CertificateRequest resource linked to a Certificate resource does not match the public key of the key encoded in the Secret linked to that Certificate resource ([#&#8203;6168](cert-manager/cert-manager#6168), [@&#8203;inteon](https://github.com/inteon))
-   Chore: When hostNetwork is enabled, dnsPolicy is now set to ClusterFirstWithHostNet. ([#&#8203;6156](cert-manager/cert-manager#6156), [@&#8203;kahirokunn](https://github.com/kahirokunn))
-   Cleanup the controller configfile structure by introducing sub-structs. ([#&#8203;6242](cert-manager/cert-manager#6242), [@&#8203;inteon](https://github.com/inteon))
-   Don't run API Priority and Fairness controller in webhook's extension apiserver ([#&#8203;6085](cert-manager/cert-manager#6085), [@&#8203;irbekrm](https://github.com/irbekrm))
-   Helm: Add apache 2.0 license annotation ([#&#8203;6225](cert-manager/cert-manager#6225), [@&#8203;arukiidou](https://github.com/arukiidou))
-   Make apis/acme/v1/ACMEIssuer.PreferredChain optional in JSON serialization. ([#&#8203;6034](cert-manager/cert-manager#6034), [@&#8203;gdvalle](https://github.com/gdvalle))
-   The SecretPostIssuancePolicyChain now also makes sure that the `cert-manager.io/common-name`, `cert-manager.io/alt-names`, ... annotations on Secrets are kept at their correct value. ([#&#8203;6176](cert-manager/cert-manager#6176), [@&#8203;inteon](https://github.com/inteon))
-   The cmctl logging has been improved and support for json logging has been added. ([#&#8203;6247](cert-manager/cert-manager#6247), [@&#8203;inteon](https://github.com/inteon))
-   Updates Kubernetes libraries to `v0.27.2`. ([#&#8203;6077](cert-manager/cert-manager#6077), [@&#8203;lucacome](https://github.com/lucacome))
-   Updates Kubernetes libraries to `v0.27.4`. ([#&#8203;6227](cert-manager/cert-manager#6227), [@&#8203;lucacome](https://github.com/lucacome))
-   We now only check that the issuer name, kind and group annotations on a Secret match in case those annotations are set. ([#&#8203;6152](cert-manager/cert-manager#6152), [@&#8203;inteon](https://github.com/inteon))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi4yMy4yIiwidXBkYXRlZEluVmVyIjoiMzYuMjMuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Reviewed-on: https://git.home/nrdufour/home-ops/pulls/84
Co-authored-by: Renovate <renovate@ptinem.io>
Co-committed-by: Renovate <renovate@ptinem.io>
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. area/testing Issues relating to testing dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants