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

Refactor migration logic for recorded app #501

Merged
merged 1 commit into from
May 4, 2022
Merged

Conversation

praveenrewar
Copy link
Member

@praveenrewar praveenrewar commented Apr 30, 2022

Here's an attempt at making the migration logic a bit more readable and simple.

I realised that I we were trying to avoid updating the createOrUpdate with the migration logic and in doing so it resulted in createOrUpdate being used only for create operations and not for updates, and this led me to make these changes.

  • Created new private methods find and create.
  • The above methods are then used in CreateOrUpdate, RenamePrevApp, Exists, Rename, setMeta, etc,. to make them more simple.
  • Removed createOrUpdate
  • Set isMigrated at relevant places.

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

Just a few nits!
Will take a closer look on my local.
Love how this makes it legible <3

pkg/kapp/app/recorded_app.go Show resolved Hide resolved
pkg/kapp/app/recorded_app.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sethiyash sethiyash left a comment

Choose a reason for hiding this comment

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

Looks really good to me.

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

Changes look good!
Thanks for making this one. LGTM!

Copy link
Contributor

@neil-hickey neil-hickey left a comment

Choose a reason for hiding this comment

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

LGTM.

This new pattern of doXANDY() felt odd, but I think it does make it more readable. I was trying to find a way to keep the flow of doX() if x { return y() } instead of the doXandY() style this introduces, but I couldn't see a nice way. I don't want to block the refactor as I think it's a step in a more readable direction, but if it's valuable I can go through and see if what I am trying to describe provides the value I am hoping it does...

foundMigratedApp, err := a.findAndUpdate(a.fqName(), labels)
if err != nil {
	return err
}

if foundMigratedApp {
	a.isMigrated = true	
	return nil
}

would love if this could remain something like: (only because I am a fan on functions doing one thing only - the pattern of AND or even OR I find confusing)

if exists, err := a.find(a.fqName()); err != nil {
    return err
}

if exists {
  a.isMigrated = true	
  return a.updateApp(labels)
}

@praveenrewar
Copy link
Member Author

only because I am a fan on functions doing one thing only

Yeah, that sounds good. I will give this a shot. The only reason I didn't do it was because of the RenamePrevApp (it would become too lengthy)

@praveenrewar praveenrewar force-pushed the app-suffix branch 3 times, most recently from 62ddfa7 to fd26c9f Compare May 2, 2022 17:07
@praveenrewar
Copy link
Member Author

@neil-hickey Thanks a lot for your suggestions, I have made the relevant changes. Let me know your thoughts on it 😄

@neil-hickey
Copy link
Contributor

neil-hickey commented May 2, 2022

@neil-hickey Thanks a lot for your suggestions, I have made the relevant changes. Let me know your thoughts on it 😄

I prefer this pattern, it's more explicit what is going on. For example:

foundMigratedApp, err := a.findAndUpdate(a.fqName(), labels)
if err != nil {
	return err
}

if foundMigratedApp {
	a.isMigrated = true	
	return nil
}

vs (now)

app, foundMigratedApp, err := a.find(a.fqName())
if err != nil {
	return err
}

if foundMigratedApp {
	a.isMigrated = true
	return a.updateApp(app, labels)
}

You can see that they are effectively the same even with the old refactor of update into the findAndUpdate function. To me, now it's really clear what's happening if the app is found.. we update it, whereas before it was kinda hidden. Curious to see what others think!

@praveenrewar
Copy link
Member Author

I myself like the new changes more than previous one.

Copy link
Contributor

@100mik 100mik left a comment

Choose a reason for hiding this comment

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

Still looking good to me 🚀

@praveenrewar praveenrewar merged commit c464deb into develop May 4, 2022
@praveenrewar praveenrewar deleted the app-suffix branch June 8, 2022 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants