-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
✨ Clusterctl version check #3484
✨ Clusterctl version check #3484
Conversation
2dbf915
to
a52ec67
Compare
/test pull-cluster-api-e2e |
@wfernandes From your example |
@vincepri Yeah...I realized that actually. I'm still looking into parsing the |
We should be able to just use semver to compare IIRC |
Yeah so for the example above: TBH IMO, it feels that |
Maybe when using pre-release version we should say something like "you're using a pre-release version" or if it's "-dirty" we should say "locally built version"? |
name: "returns message if cli version is a pre-release of the latest available release", | ||
cliVersion: func() version.Info { | ||
return version.Info{ | ||
GitVersion: "v0.3.9-alpha.0", | ||
} | ||
}, | ||
githubResponse: `{"tag_name": "v0.3.9", "html_url": "https://github.com/foo/bar/releases/v0.3.9"}`, | ||
expectErr: false, | ||
expectedOutput: ` | ||
New clusterctl version available: v0.3.9-alpha.0 -> v0.3.9 | ||
https://github.com/foo/bar/releases/v0.3.9 | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we ever had our own official pre-releases, I wanted clusterctl to be able to notify the user via the output.
name: "returns message if cli version is a pre-release and latest available release is the next pre-release", | ||
cliVersion: func() version.Info { | ||
return version.Info{ | ||
GitVersion: "v0.3.8-alpha.0", | ||
} | ||
}, | ||
githubResponse: `{"tag_name": "v0.3.8-alpha.1", "html_url": "https://github.com/foo/bar/releases/v0.3.8-alpha.1"}`, | ||
expectErr: false, | ||
expectedOutput: ` | ||
New clusterctl version available: v0.3.8-alpha.0 -> v0.3.8-alpha.1 | ||
https://github.com/foo/bar/releases/v0.3.8-alpha.1 | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. I wanted clusterctl to inform users if there were valid pre-releases available.
As long as we don't name our pre-releases in the same format as GitVersion
we should be good.
4dcb857
to
e7c1b31
Compare
// if we are using a dirty dev build, just log it out | ||
if strings.HasSuffix(cliVer.String(), "-dirty") { | ||
log.V(1).Info("Using a dirty dev build of clusterctl.", "CLIVersion", cliVer.String(), "LatestGithubRelease", release.Version) | ||
return "", nil | ||
} | ||
|
||
// if the cli version is a dev build off of the latest available release, | ||
// the just log it out as informational. | ||
if strings.HasPrefix(cliVer.String(), latestVersion.String()) && gitVersionRegEx.MatchString(cliVer.String()) { | ||
log.V(1).Info("Using a dev build of latest clusterctl release.", "CLIVersion", cliVer.String(), "LatestGithubRelease", release.Version) | ||
return "", nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose to log out here because these are cases specifically for the "developer" users.
"developer" users being folks who have manually built clusterctl.
And I didn't want to bother the developers by printing out the a warning message after every command. TBH, I feel for the majority of users, these use cases will be minimal.
I felt that this was a good balance of notifying a "developer" instead of annoying them with a constant warning message.
return "", nil | ||
} | ||
|
||
func (v *versionChecker) getLatestRelease() (*ReleaseInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (v *versionChecker) getLatestRelease() (*ReleaseInfo, error) { | |
func (v *versionChecker) getLatestRelease() (ReleaseInfo, error) { |
@wfernandes Squash? |
06f7723
to
7114511
Compare
@CecileRobertMichon @vincepri From the CAPI meeting, I can implement the strictly blocking feature separately as part of a different issue. Unless y'all wanted that to go in with this work. LMK your thoughts. Thanks. |
I vote on a separate issue, this is a good incremental change as-is. |
I can create a separate issue for that then and work on it. Thanks for the input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
/milestone v0.3.9
/assign @CecileRobertMichon @fabriziopandini
for final lgtm
if vs == nil { | ||
release, _, err := v.githubClient.Repositories.GetLatestRelease(context.TODO(), "kubernetes-sigs", "cluster-api") | ||
if err != nil { | ||
log.V(1).Info("⚠️ Unable to get latest github release for clusterctl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we avoiding v(0) to avoid printing logs in the middle of yaml output? otherwise I think it makes sense to print this as a warning on all runs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was in regards to a previous feedback comment about failing silently. So I thought putting it at a log level that's informative only when asked for. As per the logging guidelines laid out here.
Also since this check is being run after every command, I didn't want the user to be peppered with the log line all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall lgtm, a couple of minor comments on formatting and log level
- Store release info in state file Cache the release info in the state file in order to avoid excessive github requests. - Use GITHUB_TOKEN for github client if available - Handle special cases of GitVersions We want to treat pre-releases as valid. We log out if the cli version is a dev build of any kind - Do not return error if unable to get github release This can be the case for air-gapped environments. So we just log the error instead. - Prompt upgrade only within minor versions of cli
7114511
to
ef3d157
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: vincepri 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 |
/test pull-cluster-api-test |
What this PR does / why we need it:
This PR allows clusterctl to prompt the user if it detects that the version being used is different from the latest available release. If the clusterctl version being used is either older or a dev release compared to the latest available release, it will print out a message to the terminal via os.Stderr. The version check happens on any sub-command of clusterctl.
An example of the output printed is:
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #3466