Skip to content

Commit

Permalink
Change upgrade to update where it makes sense
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Pickering <[email protected]>
  • Loading branch information
adamkpickering committed May 3, 2023
1 parent b970559 commit 4e4afc1
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ Electron.app.whenReady().then(async() => {

await dockerDirManager.ensureCredHelperConfigured();

// Path management strategy will need to be selected after an upgrade
// Path management strategy will need to be selected after an update
if (!os.platform().startsWith('win') && cfg.application.pathManagementStrategy === PathManagementStrategy.NotSet) {
if (!noModalDialogs) {
await window.openPathUpdate();
Expand Down
6 changes: 3 additions & 3 deletions pkg/rancher-desktop/components/UpdateStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<span v-else></span>
</template>
</card>
<card v-else-if="unsupportedUpgradeAvailable" :show-highlight-border="false">
<card v-else-if="unsupportedUpdateAvailable" :show-highlight-border="false">
<template #title>
<div class="type-title">
<h3>Latest Version Not Supported</h3>
Expand Down Expand Up @@ -158,8 +158,8 @@ class UpdateStatus extends UpdateStatusProps {
return this.applying ? 'Applying update...' : 'Restart Now';
}
get unsupportedUpgradeAvailable() {
return !this.hasUpdate && this.updateState?.info?.unsupportedUpgradeAvailable;
get unsupportedUpdateAvailable() {
return !this.hasUpdate && this.updateState?.info?.unsupportedUpdateAvailable;
}
applyUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('UpdateStatus.vue', () => {
sha512: '',
releaseDate: '',
nextUpdateTime: 12345,
unsupportedUpgradeAvailable: false,
unsupportedUpdateAvailable: false,
},
progress: {
percent: 12.34,
Expand Down
40 changes: 20 additions & 20 deletions pkg/rancher-desktop/main/update/LonghornProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const console = Logging.update;
const gCachePath = path.join(paths.cache, 'updater-longhorn.json');

/**
* If the upgrade responder doesn't have a requestIntervalInMinutes field (or if
* If Upgrade Responder doesn't have a requestIntervalInMinutes field (or if
* it's zero), use this value instead. Note that the server can still set it to
* be less than this value.
*/
Expand All @@ -30,7 +30,7 @@ const defaultUpdateIntervalInMinutes = 60;
*/
export interface LonghornProviderOptions extends CustomPublishOptions {
/**
* upgradeServer is the URL for the upgrade-responder server
* upgradeServer is the URL for the Upgrade Responder server
* @example "https://responder.example.com:8314/v1/checkupgrade"
*/
readonly upgradeServer: string;
Expand Down Expand Up @@ -63,17 +63,17 @@ export interface LonghornUpdateInfo extends UpdateInfo {
* Whether there is an unsupported version of Rancher Desktop that is
* newer than the latest supported version.
*/
unsupportedUpgradeAvailable: boolean;
unsupportedUpdateAvailable: boolean;
}

/**
* LonghornUpgraderResponse describes the response from the Longhorn upgrade
* responder service.
* LonghornUpgraderResponse describes the response from the Longhorn Upgrade
* Responder service.
*/
interface LonghornUpgraderResponse {
versions: UpgradeResponderVersion[];
/**
* The number of minutes before the next upgrade check should be performed.
* The number of minutes before the next update check should be performed.
*/
requestIntervalInMinutes: number;
}
Expand All @@ -88,7 +88,7 @@ type UpgradeResponderVersion = {
type UpgradeResponderQueryResult = {
latest: UpgradeResponderVersion;
requestIntervalInMinutes: number,
unsupportedUpgradeAvailable: boolean,
unsupportedUpdateAvailable: boolean,
};

export interface GithubReleaseAsset {
Expand Down Expand Up @@ -131,7 +131,7 @@ interface LonghornCache {
* Whether there is an unsupported version of Rancher Desktop that is
* newer than the latest supported version.
*/
unsupportedUpgradeAvailable: boolean;
unsupportedUpdateAvailable: boolean;
/** Whether the recorded release is an installable update */
isInstallable: boolean;
release: {
Expand Down Expand Up @@ -252,21 +252,21 @@ export async function queryUpgradeResponder(url: string, currentVersion: semver.
// If we are using anything on `github.io` as the update server, we're
// trying to run a simplified test. In that case, break the protocol and do
// a HTTP GET instead of the HTTP POST with data we should do for actual
// longhorn upgrade-responder servers.
// Longhorn Upgrade Responder servers.
const requestOptions = /^https?:\/\/[^/]+\.github\.io\//.test(url) ? { method: 'GET' } : {
method: 'POST',
body: JSON.stringify(requestPayload),
};

console.debug(`Checking for upgrades from ${ url }`);
console.debug(`Checking ${ url } for updates`);
const responseRaw = await fetch(url, requestOptions);
const response = await responseRaw.json() as LonghornUpgraderResponse;

console.debug(`Upgrade server response:`, util.inspect(response, true, null));
console.debug(`Upgrade Responder response:`, util.inspect(response, true, null));

const allVersions = response.versions;

// If the upgrade responder does not send the Supported field,
// If Upgrade Responder does not send the Supported field,
// assume that the version is supported.
for (const version of allVersions) {
version.Supported ??= true;
Expand All @@ -279,21 +279,21 @@ export async function queryUpgradeResponder(url: string, currentVersion: semver.
throw newError('Could not find latest version', 'ERR_UPDATER_LATEST_VERSION_NOT_FOUND');
}
const latest = supportedVersions[0];
const unsupportedUpgradeAvailable = allVersions[0].Name !== latest.Name;
const unsupportedUpdateAvailable = allVersions[0].Name !== latest.Name;

return {
latest,
requestIntervalInMinutes: response.requestIntervalInMinutes,
unsupportedUpgradeAvailable,
unsupportedUpdateAvailable,
};
}

/**
* LonghornProvider is a Provider that interacts with Longhorn's
* [Upgrade Responder](https://github.com/longhorn/upgrade-responder) server to
* locate upgrade versions. It assumes that the versions are actually published
* as GitHub releases. It also assumes that all versions have assets for all
* platforms (that is, it doesn't filter by platform on checking).
* determine which versions are available. It assumes that the versions are
* published as GitHub releases. It also assumes that all versions have assets
* for all platforms (that is, it doesn't filter by platform on checking).
*
* Note that we do internal caching to avoid issues with being double-counted in
* the stats.
Expand Down Expand Up @@ -343,7 +343,7 @@ export default class LonghornProvider extends Provider<LonghornUpdateInfo> {
}

const queryResult = await queryUpgradeResponder(this.configuration.upgradeServer, this.updater.currentVersion);
const { latest, unsupportedUpgradeAvailable } = queryResult;
const { latest, unsupportedUpdateAvailable } = queryResult;
const requestIntervalInMinutes = queryResult.requestIntervalInMinutes || defaultUpdateIntervalInMinutes;
const requestIntervalInMs = requestIntervalInMinutes * 1000 * 60;
const nextRequestTime = Date.now() + requestIntervalInMs;
Expand Down Expand Up @@ -392,7 +392,7 @@ export default class LonghornProvider extends Provider<LonghornUpdateInfo> {

const cache: LonghornCache = {
nextUpdateTime: nextRequestTime,
unsupportedUpgradeAvailable,
unsupportedUpdateAvailable,
isInstallable: false, // Always false, we'll update this later.
release: {
tag,
Expand Down Expand Up @@ -430,7 +430,7 @@ export default class LonghornProvider extends Provider<LonghornUpdateInfo> {
releaseNotes: cache.release.notes,
releaseDate: cache.release.date,
nextUpdateTime: cache.nextUpdateTime,
unsupportedUpgradeAvailable: cache.unsupportedUpgradeAvailable,
unsupportedUpdateAvailable: cache.unsupportedUpdateAvailable,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('queryUpgradeResponder', () => {
expect(result.latest.Name).toEqual('v3.2.1');
});

it('should set unsupportedUpgradeAvailable to true when a newer-than-latest version is unsupported', async() => {
it('should set unsupportedUpdateAvailable to true when a newer-than-latest version is unsupported', async() => {
(fetch as jest.Mock).mockReturnValueOnce({
json: () => Promise.resolve({
requestIntervalInMinutes: 100,
Expand Down Expand Up @@ -71,11 +71,11 @@ describe('queryUpgradeResponder', () => {
});
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3'));

expect(result.unsupportedUpgradeAvailable).toBe(true);
expect(result.unsupportedUpdateAvailable).toBe(true);
expect(result.latest.Name).toEqual('v2.1.3');
});

it('should set unsupportedUpgradeAvailable to false when no newer-than-latest versions are unsupported', async() => {
it('should set unsupportedUpdateAvailable to false when no newer-than-latest versions are unsupported', async() => {
(fetch as jest.Mock).mockReturnValueOnce({
json: () => Promise.resolve({
requestIntervalInMinutes: 100,
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('queryUpgradeResponder', () => {
});
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3'));

expect(result.unsupportedUpgradeAvailable).toBe(false);
expect(result.unsupportedUpdateAvailable).toBe(false);
expect(result.latest.Name).toEqual('v3.2.1');
});

Expand Down Expand Up @@ -163,7 +163,7 @@ describe('queryUpgradeResponder', () => {
});
const result = await queryUpgradeResponder('testurl', new semver.SemVer('v1.2.3'));

expect(result.unsupportedUpgradeAvailable).toBe(false);
expect(result.unsupportedUpdateAvailable).toBe(false);
expect(result.latest.Name).toEqual('v3.2.1');
});
});

0 comments on commit 4e4afc1

Please sign in to comment.