Kube Service tests (#13183)

This commit is contained in:
Arvind Ranasaria
2020-11-03 15:46:31 -08:00
committed by GitHub
parent 7bdb7c328a
commit 3ec1f7cc2b
4 changed files with 108 additions and 28 deletions

View File

@@ -28,32 +28,33 @@ export class KubeService implements IKubeService {
}
}
export function getKubeConfigClusterContexts(configFile: string): Promise<KubeClusterContext[]> {
return fs.promises.access(configFile).catch((error) => {
export async function getKubeConfigClusterContexts(configFile: string): Promise<KubeClusterContext[]> {
try {
await fs.promises.access(configFile);
} catch (error) {
if (error && error.code === 'ENOENT') {
return [];
}
else {
throw error;
}
}).then(() => {
const config = yamljs.load(configFile);
const rawContexts = <any[]>config['contexts'];
const currentContext = <string>config['current-context'];
const contexts: KubeClusterContext[] = [];
if (currentContext && rawContexts && rawContexts.length > 0) {
rawContexts.forEach(rawContext => {
const name = <string>rawContext['name'];
if (name) {
contexts.push({
name: name,
isCurrentContext: name === currentContext
});
}
});
}
return contexts;
});
}
const config = yamljs.load(configFile);
const rawContexts = <any[]>config['contexts'];
const currentContext = <string>config['current-context'];
const contexts: KubeClusterContext[] = [];
if (currentContext && rawContexts && rawContexts.length > 0) {
rawContexts.forEach(rawContext => {
const name = <string>rawContext['name'];
if (name) {
contexts.push({
name: name,
isCurrentContext: name === currentContext
});
}
});
}
return contexts;
}
export function getDefaultKubeConfigPath(): string {

View File

@@ -234,3 +234,4 @@ export class NotebookService implements INotebookService {
});
}
}