kubernetes-sigs / kubernetes-sigs/controller-tools

Inconsistent handling of YEAR substitution across generators

Open
#1,371 18 comments 1 reaction 1 assignee Claimed by @camilamacedo86 View on GitHub
Dominant language
Go
Stars
868
Forks
482
Avg merge
1d 11h
Merged PRs (30d)
8

Description

### Background

https://github.com/kubernetes-sigs/controller-tools/pull/544 added a `year` option to generator commands (`object`, `crd`, `rbac`, and `webhook`), allowing callers to substitute a `YEAR` placeholder in boilerplate header files with a specific value.

### Problem

The `applyconfiguration` generator is missing the `year` option and unconditionally replaces `YEAR` using `time.Now().UTC().Year()`, leading to inconsistent behaviour.

The full call chain is:

1. [`controller-tools/pkg/applyconfiguration/gen.go#L215`](https://github.com/kubernetes-sigs/controller-tools/blob/fbbff17babfacd1ebbbb7a7842bb5378179dadf5/pkg/applyconfiguration/gen.go#L215)
2. [`controller-tools/pkg/applyconfiguration/gen.go#L293`](https://github.com/kubernetes-sigs/controller-tools/blob/fbbff17babfacd1ebbbb7a7842bb5378179dadf5/pkg/applyconfiguration/gen.go#L293)
3. [`code-generator/cmd/applyconfiguration-gen/generators/targets.go#L60`](https://github.com/kubernetes/code-generator/blob/v0.35.0/cmd/applyconfiguration-gen/generators/targets.go#L60)
4. [`gengo/v2/execute.go#L59`](https://github.com/kubernetes/gengo/blob/5ee0d033ba5bcb073f0e69c32057520b82d75ccb/v2/execute.go#L59)

### Proposed Solution

Add a optional `year` option to the `applyconfiguration` generator, which when set, will take precedence. This change would be backwards compatible, as if the option is not specified, the current logic stays as it currently is.

Additionally, the other generators could have same logic, of defaulting to the current year as a subsitution for the string "YEAR" if not overridden by the option.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.