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

Populate receipt status on install/upgrade #555

Merged

Conversation

chriskim06
Copy link
Member

Related issue: #483

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Mar 21, 2020
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 21, 2020
}

if *manifest != "" {
plugin, err := indexscanner.ReadPluginFromFile(*manifest)
if err != nil {
return errors.Wrap(err, "failed to load plugin manifest from file")
}
install = append(install, plugin)
install = append(install, receipt.New(plugin, constants.DefaultIndexName))
Copy link
Member

Choose a reason for hiding this comment

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

I think we should not convert to Receipt until we actually installed, and we're about to write the Receipt object to disk. Thoughts @corneliusweig?

This complicates the code a bit, because nothing's installed yet, but scan index dir + convert everything to Receipt in-memory already. Looks odd in the code to me.

That's why I was imagining a small internal type, specific to this pkg that contains Plugin+indexname only.

Copy link
Member

@ahmetb ahmetb Mar 25, 2020

Choose a reason for hiding this comment

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

I have something like this in mind:

type pluginEntry {
   p plugin
   indexName string
}

it's low effort, and doesn't overload Receipt type, just because it has a field to store the indexName. :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ya I was going back and forth on that a lot when I was working on this. It felt weird to add a new type that was essentially the same as Receipt but I agree that it is weird/conceptually wrong to create the receipt before the plugin is actually installed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is definitely cleaner. Just because Receipt happens to have the field that we want to store in addition does not mean it is the right choice. Consider what happens when we add more fields to Receipt. What would happen most likely is that we would not update this instance and then we have a in invalid Receipt in our hands. So a dedicated struct is what we need here.

@@ -54,7 +54,8 @@ var (

// Install will download and install a plugin. The operation tries
// to not get the plugin dir in a bad state if it fails during the process.
func Install(p environment.Paths, plugin index.Plugin, opts InstallOpts) error {
func Install(p environment.Paths, pluginReceipt index.Receipt, opts InstallOpts) error {
Copy link
Member

Choose a reason for hiding this comment

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

this should not receive a Receipt, conceptually sounds wrong.

"sigs.k8s.io/krew/pkg/index"
)

// Store saves the given plugin receipt at the destination.
// The caller has to ensure that the destination directory exists.
func Store(plugin index.Plugin, dest string) error {
func Store(plugin index.Receipt, dest string) error {
Copy link
Member

Choose a reason for hiding this comment

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

you might wanna rename variable name to receipt as well + update godoc. :)

Comment on lines 49 to 51
if name == "" {
name = constants.DefaultIndexName
}
Copy link
Member

Choose a reason for hiding this comment

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

under what condition we specify "" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, I forgot the CanonicalPluginName function returns the default index already. I can remove this.

Copy link
Member

Choose a reason for hiding this comment

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

Even without that, this should not happen. We'll always have an index name in pkg/installation.

CanonicalPluginName should be used only for turning user input (e.g. install args) to full plugin names.

Copy link
Contributor

@corneliusweig corneliusweig Mar 25, 2020

Choose a reason for hiding this comment

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

It sounds like you are talking about the same thing. Anyway, everybody agrees that the check name == "" is unnecessary, because it is covered elsewhere.

install = append(install, plugin)
install = append(install, pluginEntry{
p: plugin,
indexName: constants.DefaultIndexName,
Copy link
Member

Choose a reason for hiding this comment

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

this is a case we did not think of.
I guess we can keep shoving them into default. thoughts @corneliusweig ?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is what happens at the moment. But we can use the opportunity to separate this better from the default index. So instead, what about setting the indexName to detached or something similar?

Copy link
Member

Choose a reason for hiding this comment

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

++ @chriskim06 do you mind making a small PR?

@ahmetb
Copy link
Member

ahmetb commented Mar 26, 2020

Right now we lack any integration tests for the changes.

Note that you're changing criticial path in this PR. So we need to make sure newly added behavior works. We can merge, but the very next PR we need would be the integration tests.

Some basic cases I'm thinking easily:

  • add index + install with its prefix
  • install plugins with default/ prefix

@chriskim06
Copy link
Member Author

I can add the integration tests here or in a separate one if that'll make it easier. Let me know which one you'd prefer.

for _, plugin := range install {
klog.V(2).Infof("Will install plugin: %s\n", plugin.Name)
for _, pluginEntry := range install {
klog.V(2).Infof("Will install plugin: %s\n", pluginEntry.p.Name)
Copy link
Member

Choose a reason for hiding this comment

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

this will omit the index name.

@ahmetb
Copy link
Member

ahmetb commented Mar 27, 2020

I can add the integration tests here or in a separate one if that'll make it easier. Let me know which one you'd prefer.

I'm curious how you tested this currently. I'm trying to get it to work locally and tried a fake local index at a directory, and wasn't able to install. So the integration tests can actually verify it works.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 27, 2020
@chriskim06
Copy link
Member Author

That's strange. I pretty much did what you mentioned and what's in the integration test: add index then install and it worked.

@ahmetb
Copy link
Member

ahmetb commented Mar 27, 2020

/lgtm
/approve

nice and small patch!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, chriskim06

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 27, 2020
@k8s-ci-robot k8s-ci-robot merged commit ba34034 into kubernetes-sigs:master Mar 27, 2020
@ahmetb
Copy link
Member

ahmetb commented Mar 27, 2020

While testing locally I noticed that if I create a fake index dir, do git init . and locally and add that, the repo is cloned but it is empty (since it has no commits).

So we need to document that while testing with local index repos, they need to commit the changes, so that the update or index add mechanism can clone the copy of the index from a commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/multi-index cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants