mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-21 20:30:29 -04:00
cluster deploy extension: Add localization support and fix " to ' strings (#4332)
* Add localization support and fix " to ' strings
* Fix ${ usage
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from "vscode";
|
||||
import { Kubectl } from "./kubectl";
|
||||
import { failed, ClusterType } from "../interfaces";
|
||||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
import { Kubectl } from './kubectl';
|
||||
import { failed, ClusterType } from '../interfaces';
|
||||
|
||||
export interface KubectlContext {
|
||||
readonly clusterName: string;
|
||||
@@ -47,7 +50,7 @@ export interface ClusterConfig {
|
||||
|
||||
|
||||
async function getKubeconfig(kubectl: Kubectl): Promise<Kubeconfig | null> {
|
||||
const shellResult = await kubectl.asJson<any>("config view -o json");
|
||||
const shellResult = await kubectl.asJson<any>('config view -o json');
|
||||
if (failed(shellResult)) {
|
||||
vscode.window.showErrorMessage(shellResult.error[0]);
|
||||
return null;
|
||||
@@ -60,11 +63,11 @@ export async function getCurrentClusterConfig(kubectl: Kubectl): Promise<Cluster
|
||||
if (!kubeConfig || !kubeConfig.clusters || !kubeConfig.contexts) {
|
||||
return undefined;
|
||||
}
|
||||
const contextConfig = kubeConfig.contexts.find((context) => context.name === kubeConfig["current-context"])!;
|
||||
const contextConfig = kubeConfig.contexts.find((context) => context.name === kubeConfig['current-context'])!;
|
||||
const clusterConfig = kubeConfig.clusters.find((cluster) => cluster.name === contextConfig.context.cluster)!;
|
||||
return {
|
||||
server: clusterConfig.cluster.server,
|
||||
certificateAuthority: clusterConfig.cluster["certificate-authority"]
|
||||
certificateAuthority: clusterConfig.cluster['certificate-authority']
|
||||
};
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ export async function getContexts(kubectl: Kubectl): Promise<KubectlContext[]> {
|
||||
if (!kubectlConfig) {
|
||||
return [];
|
||||
}
|
||||
const currentContext = kubectlConfig["current-context"];
|
||||
const currentContext = kubectlConfig['current-context'];
|
||||
const contexts = kubectlConfig.contexts || [];
|
||||
return contexts.map((c) => {
|
||||
return {
|
||||
@@ -87,14 +90,15 @@ export async function getContexts(kubectl: Kubectl): Promise<KubectlContext[]> {
|
||||
|
||||
export async function setContext(kubectl: Kubectl, targetContext: string): Promise<void> {
|
||||
const shellResult = await kubectl.invokeAsync(`config use-context ${targetContext}`);
|
||||
if (!shellResult || shellResult.code != 0) {
|
||||
if (!shellResult || shellResult.code !== 0) {
|
||||
// TODO: Update error handling for now.
|
||||
vscode.window.showErrorMessage(`Failed to set '${targetContext}' as current cluster: ${shellResult ? shellResult.stderr : "Unable to run kubectl"}`);
|
||||
let errMsg = shellResult ? shellResult.stderr : localize('runKubectlFailed', 'Unable to run kubectl');
|
||||
vscode.window.showErrorMessage(localize('setClusterFailed', 'Failed to set \'{0}\' as current cluster: {1}', targetContext, errMsg));
|
||||
}
|
||||
}
|
||||
|
||||
export async function inferCurrentClusterType(kubectl: Kubectl): Promise<ClusterType> {
|
||||
let latestContextName = "";
|
||||
let latestContextName = '';
|
||||
|
||||
const ctxsr = await kubectl.invokeAsync('config current-context');
|
||||
if (ctxsr && ctxsr.code === 0) {
|
||||
|
||||
Reference in New Issue
Block a user