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

Implement a LateInitializer struct for use by providers #266

Merged
merged 2 commits into from
May 31, 2021

Conversation

muvaf
Copy link
Member

@muvaf muvaf commented May 30, 2021

Description of your changes

LateInitializer will help providers figure out whether a change has been made and spec update is needed after the late initialization without using DeepCopy of the original and changed objects.

I wanted to include only the bare minimum I need for generated ACK resources where the source and target field types are the same to be conservative about what we expose. We can add more as needed.

Example usage:

func lateInitialize(cr *svcapitypes.Table, resp *svcsdk.DescribeTableOutput) bool {
  li := awsclients.NewLateInitializer()
  cr.Spec.ForProvider.Property = li.LateInitializeStringPtr(cr.Spec.ForProvider.Property, resp.Table.Property)
  // .. many calls using the same li object ...
  return li.IsChanged()
}

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Unit tests.

@muvaf muvaf requested review from hasheddan, negz and ulucinar May 30, 2021 19:07
Copy link
Member

@hasheddan hasheddan left a comment

Choose a reason for hiding this comment

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

@muvaf this looks good to me! One thing I was considering is whether we should add a SetChanged() method in case someone is using this with an unsupported type, but don't want to track if any changes happen in a separate variable, any thoughts on that?

muvaf added 2 commits May 31, 2021 14:20
in order to track whether late initialization had any change on the CR.

Signed-off-by: Muvaffak Onus <me@muvaf.com>
…ded by providers as needed

Signed-off-by: Muvaffak Onus <me@muvaf.com>
@muvaf
Copy link
Member Author

muvaf commented May 31, 2021

@hasheddan sounds good. I started with having a lot of LateInitialize* functions and then reduced to these few, thinking providers could extend it if they want non-conventional late initialize functions but missed the fact that they can't access changed field. Thanks!

@muvaf muvaf merged commit ded1778 into crossplane:master May 31, 2021
@muvaf muvaf deleted the lateinit-bookkeeping branch May 31, 2021 12:29
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.

2 participants