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

Persist original ARM API version for use by generic controller #1606

Merged
merged 53 commits into from
Jul 7, 2021

Conversation

theunrepentantgeek
Copy link
Member

@theunrepentantgeek theunrepentantgeek commented Jun 26, 2021

What this PR does / why we need it:

Adds OriginalVersion() function to API Spec types to return the actual ARM API version requested by users.
Adds OriginalVersion property to Storage Spec types to store that version for later use.
Adds OriginalGVK() function to Storage Resource types to return the GVK of the original version.
Removes StorageTypeFactory in favour of separate pipeline sections

Also includes

  • Unit tests for OriginalVersion() function generation
  • Unit tests for OriginalGVK() function generation
  • Fix bug in prerequisite checks for pipeline stages
  • Fix bug in ErroredType where WriteDebugDescription() would crash if there was no wrapped type

How does this PR make you feel:
gif

If applicable:

  • this PR contains tests

@theunrepentantgeek theunrepentantgeek self-assigned this Jun 26, 2021
@theunrepentantgeek theunrepentantgeek added this to the codegen-alpha-1 milestone Jun 26, 2021
@theunrepentantgeek theunrepentantgeek changed the title Feature/persist apiversions Persist original ARM API version for use by generic controller Jun 26, 2021
@theunrepentantgeek theunrepentantgeek force-pushed the feature/persist-apiversions branch from 5e16ac9 to 3f62792 Compare June 27, 2021 00:13
@codecov-commenter
Copy link

codecov-commenter commented Jun 27, 2021

Codecov Report

Merging #1606 (8ebde28) into master (1e458b2) will increase coverage by 1.89%.
The diff coverage is 80.25%.

❗ Current head 8ebde28 differs from pull request most recent head 393d2a7. Consider uploading reports for the commit 393d2a7 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1606      +/-   ##
==========================================
+ Coverage   62.92%   64.82%   +1.89%     
==========================================
  Files         187      200      +13     
  Lines       12359    12542     +183     
==========================================
+ Hits         7777     8130     +353     
+ Misses       3897     3702     -195     
- Partials      685      710      +25     
Impacted Files Coverage Δ
hack/generator/pkg/astmodel/resource_type.go 79.02% <0.00%> (+5.44%) ⬆️
hack/generator/pkg/astmodel/type_walker.go 67.53% <ø> (ø)
hack/generator/pkg/astmodel/types.go 59.37% <ø> (+2.08%) ⬆️
...enerator/pkg/codegen/storage/property_converter.go 57.81% <ø> (+57.81%) ⬆️
...g/testcases/object_type_serialization_test_case.go 2.06% <0.00%> (-0.04%) ⬇️
hack/generator/pkg/astmodel/errored_type.go 33.33% <50.00%> (ø)
...n/pipeline/inject_property_assignment_functions.go 66.66% <66.66%> (ø)
...ck/generator/pkg/codegen/storage/type_converter.go 69.81% <66.66%> (+69.81%) ⬆️
hack/generator/pkg/astmodel/function_container.go 71.42% <71.42%> (ø)
hack/generator/pkg/astmodel/property_container.go 71.42% <71.42%> (ø)
... and 48 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1e458b2...393d2a7. Read the comment docs.

Copy link
Member

@matthchr matthchr left a comment

Choose a reason for hiding this comment

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

Not done yet but posting what I have

hack/generator/pkg/astbuilder/composite_literals.go Outdated Show resolved Hide resolved
hack/generator/pkg/astmodel/object_type.go Show resolved Hide resolved
hack/generator/pkg/codegen/storage/storage_type_factory.go Outdated Show resolved Hide resolved
hack/generator/pkg/codegen/storage/storage_type_factory.go Outdated Show resolved Hide resolved
hack/generator/pkg/codegen/storage/storage_type_factory.go Outdated Show resolved Hide resolved
hack/generator/pkg/codegen/storage/storage_type_factory.go Outdated Show resolved Hide resolved
hack/generator/pkg/codegen/storage/storage_type_factory.go Outdated Show resolved Hide resolved
babbageclunk
babbageclunk previously approved these changes Jun 29, 2021
Copy link
Member

@babbageclunk babbageclunk left a comment

Choose a reason for hiding this comment

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

This looks great, although I think the change you discussed of breaking StorageTypeFactory into a set of pipeline stages will be nicer.

@theunrepentantgeek theunrepentantgeek force-pushed the feature/persist-apiversions branch from f36dd42 to d2da249 Compare June 30, 2021 08:16
@theunrepentantgeek theunrepentantgeek dismissed stale reviews from babbageclunk and matthchr June 30, 2021 08:18

I've majorly restructured the PR, so this approval is stale.

@theunrepentantgeek theunrepentantgeek force-pushed the feature/persist-apiversions branch 2 times, most recently from 746553c to 0bc3f8a Compare July 5, 2021 05:39
Copy link
Member

@matthchr matthchr left a comment

Choose a reason for hiding this comment

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

LGTM - Left a bunch of nits and one comment about golden test file structure.

@@ -151,7 +156,14 @@ func createAllPipelineStages(idFactory astmodel.IdentifierFactory, configuration
pipeline.AddCrossplaneEmbeddedResourceSpec(idFactory).UsedFor(pipeline.CrossplaneTarget),
pipeline.AddCrossplaneEmbeddedResourceStatus(idFactory).UsedFor(pipeline.CrossplaneTarget),

pipeline.CreateStorageTypes(idFactory).UsedFor(pipeline.ARMTarget), // TODO: For now only used for ARM
// Create Storage types
//TODO: For now only used for ARM
Copy link
Member

Choose a reason for hiding this comment

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

extra mega minor:

Suggested change
//TODO: For now only used for ARM
// TODO: For now only used for ARM

hack/generator/pkg/codegen/storage/property_injector.go Outdated Show resolved Hide resolved
type OriginalVersionKind string

const (
ReadProperty = OriginalVersionKind("property")
Copy link
Member

Choose a reason for hiding this comment

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

I hate that go doesn't have first class enum support, and the solution of consts kinda works but if the consts don't have the enum name in them it's sometimes hard to pick out which values belong to which type.

I know in some places we do something like OriginalVersionKindReadProperty (which is sorta how you'd do it in C, I think?), but we don't have that consistently and it is awkwardly long.

Does this bug other folks too? What do people prefer?

Copy link
Member Author

Choose a reason for hiding this comment

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

I used very simple names here to optimize the API when consuming; adding a unique suffix would make that clunky.

Having first class enum support would be preferable - but I guess Go is designed to push people towards many simpler packages.

hack/generator/pkg/test/asserts.go Show resolved Hide resolved
@theunrepentantgeek theunrepentantgeek force-pushed the feature/persist-apiversions branch from 74e3f6f to 3be33df Compare July 7, 2021 01:42
@theunrepentantgeek theunrepentantgeek merged commit 2e113ed into master Jul 7, 2021
@theunrepentantgeek theunrepentantgeek deleted the feature/persist-apiversions branch July 7, 2021 01:59
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.

4 participants