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

kpt alpha rpkg update --discover: option to find downstream packages that can be updated from an upstream package #3443

Merged
merged 5 commits into from Aug 8, 2022

Conversation

natasha41575
Copy link
Contributor

@natasha41575 natasha41575 commented Aug 4, 2022

Related to #3202

Trying to tackle the second bullet point - finding out which downstream packages need an update based on the provided upstream package.

This PR does the following:

What is currently supported by kpt alpha rpkg update --discover will change to kpt alpha rpkg update --discover=upstream:

$ kpt alpha rpkg update --discover=upstream
PACKAGE REVISION                                            UPSTREAM REPOSITORY   UPSTREAM UPDATES
kpt-samples-47e4436a7490df604f57e75a9d995c2ca7ba0a88                              No update available
kpt-samples-6b14817885cbbaa1144d5b19df3378144cc24551                              No update available
test-deployments-2f36052b298673c231e8debcdd1a4553200b45c7   kpt-samples           v1, v2
test-deployments-bfcd0186c8528d13068e6d71b73329bac504f30b   kpt-samples           v2
test-deployments-f21b3faa487feec5cd231c3aa8698bbd8c2dd88d   kpt-samples           v2

This PR adds another option --discover=downstream to tackle the reverse question. If a package revision has multiple downstream packages that need to be updated, those entries in the output table will be grouped together (like the middle two in the following output):

$ kpt alpha rpkg update --discover=downstream
PACKAGE REVISION                                       DOWNSTREAM PACKAGE                                          DOWNSTREAM UPDATE
kpt-samples-dc223acc4eeba1e3a41a90e9756b00872a51855d   test-deployments-2f36052b298673c231e8debcdd1a4553200b45c7   v0->v2
kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc28   test-deployments-bfcd0186c8528d13068e6d71b73329bac504f30b   v1->v2
kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc28   test-deployments-f21b3faa487feec5cd231c3aa8698bbd8c2dd88d   v1->v2
kpt-samples-ec01f2365a60ce92d9217225dc447da8e1e722c1   test-deployments-2f36052b298673c231e8debcdd1a4553200b45c7   v0->v1

You can optionally provide package revisions as arguments if you only want to look at specific ones:

$ kpt alpha rpkg update --discover=downstream kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc28
PACKAGE REVISION                                       DOWNSTREAM PACKAGE                                          DOWNSTREAM UPDATE
kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc28   test-deployments-bfcd0186c8528d13068e6d71b73329bac504f30b   v1->v2
kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc28   test-deployments-f21b3faa487feec5cd231c3aa8698bbd8c2dd88d   v1->v2

If there is nothing to output, we just print that all downstream packages are up to date:

$ kpt alpha rpkg update --discover=downstream kpt-samples-414c1509c368a46650e4a1098487096ed5c05d81
All downstream packages are up to date.

return err
}
} else {
if _, err := fmt.Fprintln(w, "UPSTREAM PACKAGE\tUPSTREAM REVISION\tDOWNSTREAM PACKAGE\tDOWNSTREAM REVISION"); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The last column "DOWNSTREAM REVISION" isn't actually the package revision number of the downstream revision, it's the upstream revision number that the downstream package revision is based on - but I was struggling to think of a clear, concise way to specify that in the column name. It'll probably be good to document it somewhere what these column names actually mean.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree the terminology is a bit difficult here.

When the user specifies --discovery=upstream, we currently list packages (using just "PACKAGE" as the column heading). I think maybe we should just use the heading "PACKAGE" in the --discovery=downstream case as well, since having columns named both "UPSTREAM PACKAGE" and "DOWNSTREAM PACKAGE" becomes a bit confusing.

For the "DOWNSTREAM REVISION" column, could we maybe name it something like "FROM VERSION" or "INCLUDES VERSION" to make it clearer that this is the version of the upstream that is included in the downstream package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the user specifies --discovery=upstream, we currently list packages (using just "PACKAGE" as the column heading). I think maybe we should just use the heading "PACKAGE" in the --discovery=downstream case as well, since having columns named both "UPSTREAM PACKAGE" and "DOWNSTREAM PACKAGE" becomes a bit confusing.

👍 I will make it consistent with --upstream

For the "DOWNSTREAM REVISION" column, could we maybe name it something like "FROM VERSION" or "INCLUDES VERSION" to make it clearer that this is the version of the upstream that is included in the downstream package.

I like "FROM VERSION". Taking that idea a bit further, maybe we could combine the revision columns:

$ kpt alpha rpkg update --discover=downstream
PACKAGE REVISION                                    DOWNSTREAM PACKAGE                                          DOWNSTREAM UPDATE
kpt-samples-b2d61a19750d212c61a1c64b0a1cf1ce0efddc2 test-deployments-2f36052b298673c231e8debcdd1a4553200b45c7   v1->v2

My most recent commit does this. WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, I like that idea.

@natasha41575 natasha41575 changed the title kpt alpha rpkg update --discover: option to find downstream packages that can be updated from an upstream package WIP: kpt alpha rpkg update --discover: option to find downstream packages that can be updated from an upstream package Aug 4, 2022
@natasha41575 natasha41575 changed the title WIP: kpt alpha rpkg update --discover: option to find downstream packages that can be updated from an upstream package kpt alpha rpkg update --discover: option to find downstream packages that can be updated from an upstream package Aug 4, 2022
var updates [][]string
var upstreamUpdates [][]string
downstreamUpdatesMap := make(map[string][]porchapi.PackageRevision) // map from the upstream package revision to a list of its downstream package revisions

Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be easier to just create separate functions for the upstream and downstream cases here? The switch statement inside the loop will always have the same value for every iteration. I think it would also remove the need for two separate switch statements (finding updates and printing the results).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done! Thanks for the suggestion, the code is a lot cleaner this way.

return err
}
} else {
if _, err := fmt.Fprintln(w, "UPSTREAM PACKAGE\tUPSTREAM REVISION\tDOWNSTREAM PACKAGE\tDOWNSTREAM REVISION"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I agree the terminology is a bit difficult here.

When the user specifies --discovery=upstream, we currently list packages (using just "PACKAGE" as the column heading). I think maybe we should just use the heading "PACKAGE" in the --discovery=downstream case as well, since having columns named both "UPSTREAM PACKAGE" and "DOWNSTREAM PACKAGE" becomes a bit confusing.

For the "DOWNSTREAM REVISION" column, could we maybe name it something like "FROM VERSION" or "INCLUDES VERSION" to make it clearer that this is the version of the upstream that is included in the downstream package.

@natasha41575 natasha41575 merged commit 655377b into kptdev:main Aug 8, 2022
@natasha41575 natasha41575 deleted the discover branch August 8, 2022 21:41
chunglu-chou pushed a commit to chunglu-chou/kpt that referenced this pull request Aug 20, 2022
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.

None yet

2 participants