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

Randomly check for krew updates #494

Merged
merged 8 commits into from
Feb 7, 2020

Conversation

corneliusweig
Copy link
Contributor

Fixes #480
Related issue: #490

This is an alternate implementation of #490. The goal here is to simplify the feature. Instead of saving the timestamp of the last update check, the checks are now done at random with a probability of 40% per run. In addition, no checks are done for development builds.

As this is a convenience function, silently ignore errors if they occur.
Show notifications right before the command completes
Add env var KREW_NO_UPGRADE_CHECK as switch to disable the upgrade check.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 4, 2020
@codecov-io
Copy link

codecov-io commented Feb 4, 2020

Codecov Report

Merging #494 into master will increase coverage by 1.2%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #494     +/-   ##
=========================================
+ Coverage      57%   58.21%   +1.2%     
=========================================
  Files          21       22      +1     
  Lines         956      974     +18     
=========================================
+ Hits          545      567     +22     
+ Misses        357      351      -6     
- Partials       54       56      +2
Impacted Files Coverage Δ
cmd/krew/cmd/internal/fetch_tag.go 100% <100%> (ø)
internal/installation/util.go 50% <0%> (+50%) ⬆️

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 7ec26f6...1b24548. Read the comment docs.

const (
upgradeNotification = `A newer version of krew is available (%s -> %s).
Run "kubectl krew upgrade" to get the newest version!
`
Copy link
Member

Choose a reason for hiding this comment

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

maybe remove newline and use println?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Println is not possible due to the format string. I changed to a normal string instead.

cmd/krew/cmd/root.go Outdated Show resolved Hide resolved
cmd/krew/cmd/root.go Outdated Show resolved Hide resolved
docs/USER_GUIDE.md Outdated Show resolved Hide resolved
// See the License for the specific language governing permissions and
// limitations under the License.

package updatecheck
Copy link
Member

Choose a reason for hiding this comment

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

I don't know why you want to make a new pkg out of this tbh :)

it's like 3 short methods.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah.. true. I'll move to cmd/internal

@ahmetb
Copy link
Member

ahmetb commented Feb 4, 2020

No major issues just some nits+refactoring feedback.

@corneliusweig
Copy link
Contributor Author

Ok, I hope I got everything.

As this is a convenience function, silently ignore errors if they occur.
Show notifications right before the command completes
Add env var KREW_NO_UPGRADE_CHECK as switch to disable the upgrade check.
cmd/krew/cmd/root.go Outdated Show resolved Hide resolved
return nil
}

func showUpgradeNotification(*cobra.Command, []string) {
if latestTag == "" || latestTag == version.GitTag() {
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 I've mentioned this before: Let's parse both of these into semver, and actually do LessThan check.

Copy link
Contributor Author

@corneliusweig corneliusweig Feb 5, 2020

Choose a reason for hiding this comment

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

Yes, I also explained why I think that mere string comparison is better:

We only allow the version numbers of krew releases to advance, so that it is equivalent to check for string equality vs. semver less-than comparison.

But if you feel so strongly about it, let's change it.

Copy link
Member

Choose a reason for hiding this comment

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

I feel like we're gonna see upgrade notifications etc in CI tests.
If it's not a big deal, let's just do that. We already have the code, and we'd simply skip if it fails to parse as semver.

Use semver.Less to compare version tags
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
@ahmetb
Copy link
Member

ahmetb commented Feb 6, 2020

Added a commit PTAL.

@corneliusweig
Copy link
Contributor Author

Oh yes, make sense. Thanks!
There was a small golint problem, let's see if it is clean now.

@ahmetb ahmetb closed this Feb 7, 2020
@ahmetb ahmetb reopened this Feb 7, 2020
@ahmetb
Copy link
Member

ahmetb commented Feb 7, 2020

(Closed by mistake) 🗡

I've encountered this: On local builds, it prints

A newer version of krew is available (v0.3.3-52-gf66516f -> v0.3.3).
Run "kubectl krew upgrade" to get the newest version!

I guess this is expected, because, technically, pre-release tags are LessThan their tags. 🤦‍♂ What do we do?

@ahmetb
Copy link
Member

ahmetb commented Feb 7, 2020

I guess this problem only impact developers. I hope the devs can understand what's going on. If you have any solutions, please send follow-up PR.

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

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

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:
  • OWNERS [ahmetb,corneliusweig]

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 merged commit 20c0e20 into kubernetes-sigs:master Feb 7, 2020
@corneliusweig corneliusweig deleted the w/PATH-check-2 branch February 7, 2020 08:37
@corneliusweig
Copy link
Contributor Author

Let's see if annoying this is to us. I'd like to avoid complexity if it only solves a minor inconvenience for a few krew developers.

Btw, thanks for pushing this PR in the right direction until it became reasonably small!

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. 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.

Proposal: occassionally show available upgrades for Krew
4 participants