Skip to content

Apply the modernize embedlit fixes - #9441

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:chore/modernize-embedlit
Oct 25, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
FelixPhipps:chore/modernize-embedlit

Conversation

@FelixPhipps

@FelixPhipps FelixPhipps commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #9440, as requested by @erikgb in #9440 (review).

Go 1.27 allows omitting embedded field types from struct literals, so ObjectMeta: metav1.ObjectMeta{Name: "x"} can be written as Name: "x". #9440 disabled golangci-lint's modernize/embedlit check to keep that PR small. This PR re-enables it and applies its fixes.

With the check enabled, flattening is required: a struct literal that names an embedded field's type, like &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Name: "x"}}, now fails lint. Write it without the embedded type, or add //nolint:modernize with a reason where the nesting is worth keeping. The check only looks at literals that aren't themselves a field's value, so Spec: cmapi.IssuerSpec{IssuerConfig: cmapi.IssuerConfig{...}} still passes.

How it was generated:

  1. Removed the embedlit exclusion from .golangci.yaml
  2. Ran make VENDOR_GO=1 fix-golangci-lint
  3. Removed imports that became unused once the embedded type names were gone (mostly metav1), using the go vet errors
  4. Reflowed the literals the fixer left with two or more fields on one line, or with the closing brace on the last field's line, so they have one field per line and a trailing comma. Lines the fixer only re-indented keep their original layout, unless they are in a literal that was otherwise reflowed.

One exception: the controller.ContextOptions literal in cmd/controller/app/controller.go keeps its nested ACMEOptions, SchedulerOptions, IssuerOptions, IngressShimOptions, CertificateOptions and ConfigOptions groups, with a //nolint:modernize comment, because the group names show which options struct each field belongs to.

No behaviour change: the old and new literals are equivalent. Comments inside the rewritten literals are preserved. No generated files are touched.

Re-enabled the golangci-lint modernize/embedlit check and simplified struct literals to omit embedded field types

Go 1.27 allows omitting embedded field types from struct literals.
Re-enable golangci-lint's modernize/embedlit check, which was disabled
in cert-manager#9440, and apply its fixes with make fix-golangci-lint. Remove the
imports that became unused as a result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>
@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. area/acme Indicates a PR directly modifies the ACME Issuer code needs-kind Indicates a PR lacks a `kind/foo` label and requires one. area/acme/dns01 Indicates a PR modifies ACME DNS01 provider code area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code area/testing Issues relating to testing area/vault Indicates a PR directly modifies the Vault Issuer code size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Oct 8, 2026
@FelixPhipps

Copy link
Copy Markdown
Member Author

/kind cleanup

@cert-manager-prow cert-manager-prow Bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. labels Oct 8, 2026
@wallrj
wallrj self-requested a review October 10, 2026 06:03

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you. I checked the rewrite for behaviour changes and found none. The fixer only promotes a field when the outer type resolves it to the same object (isEmbeddedFieldLit in x/tools v0.50.0), every removed comment is re-added verbatim, and no generated file is touched. CI is green.

Two things I would like changed before merge, and some formatting debris to clean up.

Please keep the option groups in cmd/controller/app/controller.go. Flattening ContextOptions removed the six struct names that told readers which options struct each field belongs to. That nesting carried information. A //nolint:modernize on that one literal, or a comment per group, would keep it.

Please reflow the two-pair lines. The fixer deletes text without reflowing, and gofmt accepts the result, so roughly 120 literals now read Namespace: "x", Name: "y", on one line while the neighbouring literal is one pair per line. In the apply.go and controller files it also breaks gofmt alignment for the rest of the literal. A single pass now is cheaper than fixing it piecemeal in later PRs. I have marked one example of each shape inline; the rest are the same pattern.

Other sites with the same shapes

Glued closing braces, no trailing comma:

  • pkg/controller/cainjector/indexers.go lines 87, 122, 159
  • pkg/controller/certificate-shim/ingresses/controller_test.go lines 61, 75
  • pkg/controller/certificate-shim/listenerset/controller_test.go
  • internal/controller/certificates/policies/checks_test.go (Labels: nil},)

Two pairs on one line, alignment broken:

  • internal/controller/{certificaterequests,certificates,issuers,orders}/apply.go
  • pkg/controller/certificates/issuing/issuing_controller.go, keymanager_controller.go, readiness_controller.go, trigger_controller.go, pkg/controller/acmeorders/sync.go
  • secret_manager_test.go, secret_test.go, approver_test.go, keymanager_controller_test.go, readiness_controller_test.go, test/integration/*, test/e2e/*

[Claude Fable 5.1]

Comment thread cmd/controller/app/controller.go Outdated

ClusterIssuerAmbientCredentials: opts.ClusterIssuerAmbientCredentials,
IssuerAmbientCredentials: opts.IssuerAmbientCredentials,
ClusterResourceNamespace: opts.ClusterResourceNamespace,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This literal used to name the six options structs (ACMEOptions, SchedulerOptions, IssuerOptions, IngressShimOptions, CertificateOptions, ConfigOptions). Now blank lines are the only separator, and the compiler accepts a field in any block, so the grouping will drift. Someone adding an option has to open pkg/controller/context.go to find which struct it belongs to.

The spec allows omitting the embedded type but does not require it. Please keep the nested form here with //nolint:modernize // embedlit: the group names document which options struct each field belongs to, or add a comment per group.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 0f88562. The ContextOptions literal is back to the nested form from master, with //nolint:modernize // embedlit: the group names document which options struct each field belongs to above it. I checked that embedlit flags the literal without the comment and passes with it.

Comment thread pkg/controller/cainjector/indexers.go Outdated
Name: metaInfo.GetName(),
Namespace: metaInfo.GetNamespace(),
}})
Namespace: metaInfo.GetNamespace()})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The fixer left the closing braces glued to the last field with no trailing comma. Same at lines 122 and 159. One field per line with a trailing comma, please, so the next field added does not have to re-break the line.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 0f88562, at lines 87, 122 and 159. Each now has one field per line, a trailing comma, and }) on its own line.

func serializeApply(req *cmapi.CertificateRequest) ([]byte, error) {
req = &cmapi.CertificateRequest{
TypeMeta: metav1.TypeMeta{Kind: cmapi.CertificateRequestKind, APIVersion: cmapi.SchemeGroupVersion.Identifier()},
Kind: cmapi.CertificateRequestKind, APIVersion: cmapi.SchemeGroupVersion.Identifier(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two problems with this literal.

Kind and APIVersion are promoted but ObjectMeta four lines down is still written out, so the reader has to know that TypeMeta is also embedded to see what is being serialised. serializeApplyStatus below promotes both, so the two functions no longer look alike. Either promote nothing here or make both read the same way.

The two pairs on one line also break gofmt alignment for the fields below. One key/value per line fixes both. Same in internal/controller/certificates/apply.go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 0f88562. Both functions now put Kind and APIVersion on their own lines, with one aligned pair per line. The same change is in internal/controller/certificates/apply.go. serializeApply still writes out ObjectMeta: *req.ObjectMeta.DeepCopy(), because that's a copied value rather than a literal, so there's nothing to promote.

ObjectMeta: metav1.ObjectMeta{Namespace: req.Namespace, Name: req.Name},
Spec: cmapi.CertificateRequestSpec{},
Status: *req.Status.DeepCopy(),
Kind: cmapi.CertificateRequestKind, APIVersion: cmapi.SchemeGroupVersion.Identifier(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here: Kind: .., APIVersion: .., and Namespace: .., Name: .., on one line each, with Spec and Status aligned to each other but not to the lines above. One pair per line, please. Same shape in the certificates, issuers and orders apply.go files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 0f88562, here and in the certificates, issuers and orders apply.go files.


return internalcertificates.ApplyStatus(ctx, c.client, c.fieldManager, &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{Namespace: crt.Namespace, Name: crt.Name},
Namespace: crt.Namespace, Name: crt.Name,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Namespace: crt.Namespace, Name: crt.Name, on one line next to a one-pair Status: line. The same shape is in keymanager_controller.go, readiness_controller.go, trigger_controller.go and acmeorders/sync.go. One pair per line, please.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 0f88562, here and in keymanager_controller.go, readiness_controller.go, trigger_controller.go and acmeorders/sync.go.

Namespace: "namespace-1", Name: "ingress-1",
}}},
existingKObjects: []runtime.Object{&networkingv1.Ingress{
Namespace: "namespace-1", Name: "ingress-1"}},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two pairs plus glued }}. Adding a label or annotation to this fixture means re-breaking the line by hand. Same at line 75 and in listenerset/controller_test.go.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 0f88562, here, at line 75 and in listenerset/controller_test.go. The same goes for gateways/controller_test.go.

"if Certificate and Secret exists, but the Secret contains no certificate or private key data, do nothing": {
cert: &cmapi.Certificate{
ObjectMeta: metav1.ObjectMeta{Namespace: "test-namespace", Name: "test-name"},
Namespace: "test-namespace", Name: "test-name",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file now has about forty of these two-pair lines because the original ObjectMeta: metav1.ObjectMeta{Namespace: .., Name: ..}, was a one-liner. It is now the dominant style here and in secret_test.go, approver_test.go, the keymanager and readiness tests, and the integration and e2e suites, while hand-written neighbours are one pair per line. gofmt will not reflow these later, so a single pass now is the cheap moment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in 0f88562, in one pass across the PR. I used a small AST script rather than editing by hand.

  • It reflowed 324 literals the fixer had reshaped across 40 files, including the integration and e2e suites. Each now has one field per line, a trailing comma and the closing brace on its own line.
  • Lines that already had several fields on master and were only re-indented keep their layout, unless their literal was reflowed anyway. Examples are CertificateName: "test", IssuerName: "ca-issuer", ... and the {Manager: ..., FieldsV1: ...} entries.
  • I checked each file's tokens are unchanged apart from commas.

Comment thread .golangci.yaml
# literals. Remove this once the codebase has been migrated in a
# separate PR (golangci-lint run --enable-only modernize --fix).
- embedlit
staticcheck:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Removing the exclusion makes nesting a lint failure rather than a style choice. A contributor who writes IssuerSpec{IssuerConfig: cmapi.IssuerConfig{CA: ...}} because it mirrors the API docs will have to flatten or add //nolint:modernize. That is fine, but the PR description should say that flattening is now mandatory, so the policy is recorded somewhere searchable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've added this to the PR description. One detail: embedlit only checks literals that aren't themselves a field's value (runEmbedLit in x/tools v0.50.0 skips edge.KeyValueExpr_Value). So Spec: cmapi.IssuerSpec{IssuerConfig: cmapi.IssuerConfig{...}} still passes; there are a few of those in the tree. The description uses &corev1.Secret{ObjectMeta: metav1.ObjectMeta{...}} as the example instead.

Address review comments:

- Keep the nested options groups in the controller.ContextOptions
  literal, with a nolint:modernize comment, because the group names
  show which options struct each field belongs to.
- Reflow the struct literals the embedlit fixer left with several
  fields on one line, or with the closing brace on the last field's
  line, so they have one field per line and a trailing comma.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Felix Phipps <[email protected]>
@erikgb

erikgb commented Oct 22, 2026

Copy link
Copy Markdown
Member

This PR was discussed in our weekly dev meeting today, and no one objected to merging it after a review.
For a huge technical PR like this one, I think an AI review is sufficient, and hope that @wallrj can make his agent re-review the PR.

/approve

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 22, 2026

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you, all my comments are addressed in 0f88562.

I compared every one of the 41 reflowed Go files against the fixer output by AST with positions stripped. 40 are identical, so the reflow changed layout only. The one difference is cmd/controller/app/controller.go, which is now master plus the single //nolint:modernize line. The PR description now records that flattening is mandatory and what the check does not catch.

/lgtm

[Claude Fable 5.1]

@cert-manager-prow cert-manager-prow Bot added the lgtm Indicates that a PR is ready to be merged. label Oct 25, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: erikgb, wallrj

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

The pull request process is described here

Details 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

@cert-manager-prow
cert-manager-prow Bot merged commit 8165925 into cert-manager:master Oct 25, 2026
6 checks passed
wallrj added a commit to wallrj/cert-manager that referenced this pull request Nov 4, 2026
The embedlit modernize check added by cert-manager#9441 rejects the explicit
metav1.ObjectMeta literal. Match the promoted-field form used
throughout the file.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
wallrj added a commit to wallrj/cert-manager that referenced this pull request Nov 22, 2026
The embedlit modernize check added by cert-manager#9441 rejects the explicit
metav1.ObjectMeta literal. Match the promoted-field form used
throughout the file.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
Abhaysiri pushed a commit to Abhaysiri/cert-manager that referenced this pull request Nov 26, 2026
The embedlit modernize check added by cert-manager#9441 rejects the explicit
metav1.ObjectMeta literal. Match the promoted-field form used
throughout the file.

Co-Authored-By: Claude Fable 5 <[email protected]>
Signed-off-by: Richard Wall <[email protected]>
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/acme/dns01 Indicates a PR modifies ACME DNS01 provider code area/acme/http01 Indicates a PR modifies ACME HTTP01 provider code area/acme Indicates a PR directly modifies the ACME Issuer code area/testing Issues relating to testing area/vault Indicates a PR directly modifies the Vault Issuer code 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/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants