mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Disable kubectl download mirror options when not available (#3956)
This commit is contained in:
parent
125a073007
commit
cbffb85650
@ -136,12 +136,32 @@ const allowErrorReporting: PreferenceDescription<boolean> = {
|
||||
},
|
||||
};
|
||||
|
||||
export interface DownloadMirror {
|
||||
url: string;
|
||||
label: string;
|
||||
platforms: Set<NodeJS.Platform>;
|
||||
}
|
||||
|
||||
export const defaultPackageMirror = "default";
|
||||
export const packageMirrors = new Map<string, DownloadMirror>([
|
||||
[defaultPackageMirror, {
|
||||
url: "https://storage.googleapis.com/kubernetes-release/release",
|
||||
label: "Default (Google)",
|
||||
platforms: new Set(["darwin", "win32", "linux"]),
|
||||
}],
|
||||
["china", {
|
||||
url: "https://mirror.azure.cn/kubernetes/kubectl",
|
||||
label: "China (Azure)",
|
||||
platforms: new Set(["win32", "linux"]),
|
||||
}],
|
||||
]);
|
||||
|
||||
const downloadMirror: PreferenceDescription<string> = {
|
||||
fromStore(val) {
|
||||
return val ?? "default";
|
||||
return packageMirrors.has(val) ? val : defaultPackageMirror;
|
||||
},
|
||||
toStore(val) {
|
||||
if (!val || val === "default") {
|
||||
if (!val || val === defaultPackageMirror) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ import { getBundledKubectlVersion } from "../common/utils/app-version";
|
||||
import { isDevelopment, isWindows, isTestEnv } from "../common/vars";
|
||||
import { SemVer } from "semver";
|
||||
import { getPath } from "../common/utils/getPath";
|
||||
import { defaultPackageMirror, packageMirrors } from "../common/user-store/preferences-helpers";
|
||||
|
||||
const bundledVersion = getBundledKubectlVersion();
|
||||
const kubectlMap: Map<string, string> = new Map([
|
||||
@ -51,10 +52,6 @@ const kubectlMap: Map<string, string> = new Map([
|
||||
["1.20", "1.20.8"],
|
||||
["1.21", bundledVersion]
|
||||
]);
|
||||
const packageMirrors: Map<string, string> = new Map([
|
||||
["default", "https://storage.googleapis.com/kubernetes-release/release"],
|
||||
["china", "https://mirror.azure.cn/kubernetes/kubectl"]
|
||||
]);
|
||||
let bundledPath: string;
|
||||
const initScriptVersionString = "# lens-initscript v3\n";
|
||||
|
||||
@ -389,12 +386,9 @@ export class Kubectl {
|
||||
}
|
||||
|
||||
protected getDownloadMirror() {
|
||||
const mirror = packageMirrors.get(UserStore.getInstance().downloadMirror);
|
||||
// MacOS packages are only available from default
|
||||
|
||||
if (mirror) {
|
||||
return mirror;
|
||||
}
|
||||
|
||||
return packageMirrors.get("default"); // MacOS packages are only available from default
|
||||
return packageMirrors.get(UserStore.getInstance().downloadMirror)
|
||||
?? packageMirrors.get(defaultPackageMirror);
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,17 +27,17 @@ import { observer } from "mobx-react";
|
||||
import { bundledKubectlPath } from "../../../main/kubectl";
|
||||
import { SelectOption, Select } from "../select";
|
||||
import { FormSwitch, Switcher } from "../switch";
|
||||
import { packageMirrors } from "../../../common/user-store/preferences-helpers";
|
||||
|
||||
export const KubectlBinaries = observer(() => {
|
||||
const userStore = UserStore.getInstance();
|
||||
const [downloadPath, setDownloadPath] = useState(userStore.downloadBinariesPath || "");
|
||||
const [binariesPath, setBinariesPath] = useState(userStore.kubectlBinariesPath || "");
|
||||
const pathValidator = downloadPath ? InputValidators.isPath : undefined;
|
||||
|
||||
const downloadMirrorOptions: SelectOption<string>[] = [
|
||||
{ value: "default", label: "Default (Google)" },
|
||||
{ value: "china", label: "China (Azure)" },
|
||||
];
|
||||
const downloadMirrorOptions: SelectOption<string>[] = Array.from(
|
||||
packageMirrors.entries(),
|
||||
([value, { label, platforms }]) => ({ value, label, platforms })
|
||||
);
|
||||
|
||||
const save = () => {
|
||||
userStore.downloadBinariesPath = downloadPath;
|
||||
@ -68,6 +68,7 @@ export const KubectlBinaries = observer(() => {
|
||||
value={userStore.downloadMirror}
|
||||
onChange={({ value }: SelectOption) => userStore.downloadMirror = value}
|
||||
disabled={!userStore.downloadKubectlBinaries}
|
||||
isOptionDisabled={({ platforms }) => !platforms.has(process.platform)}
|
||||
themeName="lens"
|
||||
/>
|
||||
</section>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user