Skip to content

🐛 (applyconfiguration): applyconfiguration: add a year option to pin the copyright year in generated file headers, matching the object generator and avoiding annual diffs on regeneration. - #1379

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:add-year-backwords

Conversation

@camilamacedo86

@camilamacedo86 camilamacedo86 commented Apr 18, 2026

Copy link
Copy Markdown
Member

What

Add a year=<value> option to the applyconfiguration generator, matching the existing object generator.

Why

Today, the applyconfiguration generator passes the boilerplate header directly to the applyconfiguration-gen, which replaces YEAR with the current calendar year at generation time.

For example:

# boilerplate.go.txt
Copyright YEAR The Kubernetes Authors.

Without a year= option:

  • Jan 2024: make generateCopyright 2024
  • Jan 2025: make generate again (even with no API changes) → Copyright 2025

This results in a large, unnecessary diff every January.

The object generator already supports year=, producing deterministic output without annual copyright churn. This change brings the applyconfiguration generator to the same behavior.

Example:

  • Dec 31 — your generated files say Copyright 2024. The working tree is clean.
  • Jan 1 — a teammate (or CI) runs make generate. Nothing in the API has changed, but the generator now stamps Copyright 2025 into every generated applyconfiguration file.
  • Resultevery generated applyconfiguration file changes, producing a large, meaningless diff caused solely by the calendar rolling over. That is the problem solved here.

How

Before invoking the upstream generator, this change:

  1. Reads the boilerplate header.
  2. Replaces YEAR with the configured year= value.
  3. Writes the result to a temporary file.
  4. Passes the temporary file to the upstream generator.

Because YEAR has already been replaced, the upstream generator has nothing left
to substitute with the current calendar year, so the configured year remains
unchanged.

For example, with year=2024:

  • Jan 2024: make generateCopyright 2024
    - Jan 2025: make generate → still Copyright 2024

This pins a single year for the entire generation run, matching the behavior of the object generator. It does not preserve the existing copyright year of individual generated files.

References

Fixes: #1371

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign joelanford for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Apr 18, 2026
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 18, 2026
@camilamacedo86

Copy link
Copy Markdown
Member Author

@JoelSpeed I think this one is your baby :-)

@k8s-triage-robot

Copy link
Copy Markdown

Unknown CLA label state. Rechecking for CLA labels.

Send feedback to sig-contributor-experience at kubernetes/community.

/check-cla
/easycla

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 18, 2026

@alvaroaleman alvaroaleman 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.

/hold

For the discussion in #1371

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Apr 18, 2026
@camilamacedo86

camilamacedo86 commented Apr 19, 2026

Copy link
Copy Markdown
Member Author

Hi @alvaroaleman

Thank you for looking on this one.
But it is problematic, I added in the header and in the issue why it is problematic
The problem is in a project we can have both scenarios, with SSA and not then it does not work well.

Consistent behaviour is a key and expected.
So, I do see only 2 options here:

  • a) Fix and ensure consistency
  • b) No longer support pass the YEAR in any. (but that would be breaking change and besides k8s no longer care about the YEAR anymore, many end users and projects care so I would not go in this direction)

@camilamacedo86 camilamacedo86 changed the title 🐛 Add year option to applyconfiguration generator to ensure consistency behaviour 🐛 (applyconfiguration): Add year option to generator to ensure consistency behaviour Apr 20, 2026
@Vaishnav88sk

Copy link
Copy Markdown

I see this has a do-not-merge/hold on it, is there an open question this is blocked on, or just waiting for review? Happy to take a closer look once the hold is resolved.

@camilamacedo86

Copy link
Copy Markdown
Member Author

Hi @Vaishnav88sk

I see this has a do-not-merge/hold on it, is there an open question this is blocked on, or just waiting for review? Happy to take a closer look once the hold is resolved.

@alvaroaleman blocked it for discussion: #1379 (review)

As I described in #1379 (comment) IMO it is a bug and must be done or we should not support the YEAR at all.

Comment thread pkg/applyconfiguration/gen.go Outdated
Comment on lines +163 to +164
tmpFile.Close()
os.Remove(tmpFile.Name())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What if these error?

Comment thread pkg/applyconfiguration/year_test.go Outdated
Comment on lines +57 to +62
{
name: "YEAR without space not replaced",
headerContent: "CopyrightYEAR YEAR",
year: "2024",
expectedOutput: "CopyrightYEAR 2024",
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does this match what DeepCopy generator would do in the upstream code-generator repo?

@camilamacedo86 camilamacedo86 Jul 3, 2026

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.

Yes, that is the intention.
I changed the tests for use gingo.
But we are covering here the scenarios to ensure that it works like object.

Both should work at the same way.

@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign joelanford for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@camilamacedo86

Copy link
Copy Markdown
Member Author

Hi @alvaroaleman @JoelSpeed @sbueringer @felix-kaestner @liggitt,

I've updated the PR description to better explain why the YEAR placeholder is needed.

controller-tools is consumed by many projects, and the object generator already supports year=. This PR simply brings applyconfiguration in line with that existing behavior.

Supporting year= avoids the January 1 regeneration issue while remaining fully backwards compatible.

If we decide to remove the YEAR placeholder in the future, I think that should be done consistently across all generators and templates, as a separate breaking change. This PR only fixes the inconsistency in applyconfiguration.

@camilamacedo86
camilamacedo86 requested a review from JoelSpeed July 5, 2026 05:01
@JoelSpeed

Copy link
Copy Markdown
Contributor

@camilamacedo86 I'm not following how the code enables the files to retain their previous year. As far as I can see the generator has a static year which it dumps into the header file, and then the generator runs and substitutes that one file for all assets it generates

What am I missing?

@camilamacedo86 camilamacedo86 changed the title 🐛 (applyconfiguration): Add year option to generator to ensure consistency behaviour 🐛 (applyconfiguration): applyconfiguration: add a year option to pin the copyright year in generated file headers, matching the object generator and avoiding annual diffs on regeneration. Jul 8, 2026
@camilamacedo86

Copy link
Copy Markdown
Member Author

Hi @JoelSpeed

Thank you for taking the time to look into this and all your support !!

I've updated both the PR title and desc to make the intent clearer. Hopefully they're easier to follow now. AI also helped me here to wording better.

So "retain the previous year" was the wrong wording. What this PR actually does is pin a single configured year so regeneration no longer rewrites it to the current calendar year. It does not read existing generated files and preserve each file's copyright year. It make the behaviour consistent accross the project (object and apply works at the same way) and solve the Jan 1 issue.

Today, the applyconfiguration generator passes the boilerplate header directly to the applyconfiguration-gen, which replaces YEAR with the current calendar year at generation time.

For example:

# boilerplate.go.txt
Copyright YEAR The Kubernetes Authors.

Without the year= option, here's the Jan 1 problem concretely:

The applyconfiguration-gen replaces YEAR with the current calendar year every time it runs. That means the copyright year in generated files is tied to the wall clock, not to when the code actually changed.

  • Dec 31 — your generated files say Copyright 2024. The working tree is clean.
  • Jan 1 — a teammate (or CI) runs make generate. Nothing in the API has changed, but the generator now stamps Copyright 2025 into every generated applyconfiguration file.
  • Resultevery generated applyconfiguration file changes, producing a large, meaningless diff caused solely by the calendar rolling over. That is the problem solved here.

For example, with year=2024:

  • Jan 2024: make generateCopyright 2024
  • Jan 2025: make generate → still Copyright 2024

This pins a single year for the entire generation run, matching the behavior of the object generator. It does not preserve the existing copyright year of individual generated files.

The goal is simply to achieve parity with the object generator and produce deterministic output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent handling of YEAR substitution across generators

6 participants