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

[codegen] Generate exported constants for group and version. #563

Merged
merged 2 commits into from
Jan 7, 2025

Conversation

IfSentient
Copy link
Contributor

Generate exported Group, Version, and GroupVersion constants for each generated kind's package (when grouping kinds by version, only one set of constants will be generated for the package). This allows for a more convenient way to reference these constants vs. using the Kind accessor method, and then getting its Group/Version, especially when kinds are grouped by version, so multiple kinds are in the same package, sharing the same constants.

This is implemented as a new generated file because it has to be generated only once per package, unlike the other kind files which exist once per kind.

Resolves #515

@IfSentient IfSentient requested review from a team as code owners January 6, 2025 17:07
@@ -60,8 +60,8 @@ func TestResourceGenerator(t *testing.T) {
files, err := ResourceGenerator(false).Generate(kinds...)
require.Nil(t, err)
// Check number of files generated
// 12 (6 -> object, spec, metadata, status, schema, codec) * 2 versions
assert.Len(t, files, 12)
// 14 (6 -> object, spec, metadata, status, schema, codec, constants) * 2 versions
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 14 (6 -> object, spec, metadata, status, schema, codec, constants) * 2 versions
// 14 (7 -> object, spec, metadata, status, schema, codec, constants) * 2 versions

@@ -70,8 +70,8 @@ func TestResourceGenerator(t *testing.T) {
files, err := ResourceGenerator(true).Generate(kinds...)
require.Nil(t, err)
// Check number of files generated
// 12 (6 -> object, spec, metadata, status, schema, codec) * 2 versions
assert.Len(t, files, 12)
// 14 (6 -> object, spec, metadata, status, schema, codec, constants) * 2 versions
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// 14 (6 -> object, spec, metadata, status, schema, codec, constants) * 2 versions
// 14 (7 -> object, spec, metadata, status, schema, codec, constants) * 2 versions

@radiohead radiohead merged commit 10d4364 into main Jan 7, 2025
10 checks passed
@radiohead radiohead deleted the generate-constants branch January 7, 2025 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GroupVersion to generated code
3 participants