Add aks category connectivity detector (#177)

This commit is contained in:
Tatsinnit 2022-11-30 09:35:45 +05:30 коммит произвёл GitHub
Родитель 1193f10f11
Коммит 8a79bad483
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 98 добавлений и 2 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -4,3 +4,4 @@ node_modules
vsix
.vscode-test/
*.vsix
.DS_Store

Просмотреть файл

@ -44,7 +44,8 @@
"onCommand:aks.aksKubectlGetAPIResourcesCommands",
"onCommand:aks.aksKubectlGetNodeCommands",
"onCommand:aks.aksKubectlDescribeServicesCommands",
"onCommand:aks.aksKubectlGetEventsCommands"
"onCommand:aks.aksKubectlGetEventsCommands",
"onCommand:aks.aksCategoryConnectivity"
],
"main": "./dist/extension",
"contributes": {
@ -108,6 +109,10 @@
"command": "aks.aksCRUDDiagnostics",
"title": "Create, Upgrade, Delete and Scale"
},
{
"command": "aks.aksCategoryConnectivity",
"title": "Network Connectivity Issues"
},
{
"command": "aks.aksBestPracticesDiagnostics",
"title": "Best Practices"
@ -245,6 +250,10 @@
{
"command": "aks.aksKnownIssuesAvailabilityPerformanceDiagnostics",
"group": "navigation"
},
{
"command": "aks.aksCategoryConnectivity",
"group": "navigation"
}
],
"aks.ghWorkflowSubMenu": [

Просмотреть файл

@ -0,0 +1,75 @@
import * as vscode from 'vscode';
import * as k8s from 'vscode-kubernetes-tools-api';
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { getAksClusterTreeItem } from '../utils/clusters';
import { getExtensionPath, longRunning } from '../utils/host';
import { AppLensARMResponse, getDetectorInfo, getDetectorListData, getPortalUrl } from '../utils/detectors';
import { failed } from '../utils/errorable';
import AksClusterTreeItem from '../../tree/aksClusterTreeItem';
import { createWebView, getRenderedContent, getResourceUri } from '../utils/webviews';
export default async function aksCategoryConnectivity(
_context: IActionContext,
target: any
): Promise<void> {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
const cluster = getAksClusterTreeItem(target, cloudExplorer);
if (failed(cluster)) {
vscode.window.showErrorMessage(cluster.error);
return;
}
const extensionPath = getExtensionPath();
if (failed(extensionPath)) {
vscode.window.showErrorMessage(extensionPath.error);
return;
}
await loadDetector(cluster.result, extensionPath.result);
}
async function loadDetector(
cloudTarget: AksClusterTreeItem,
extensionPath: string) {
const clustername = cloudTarget.name;
await longRunning(`Loading ${clustername} diagnostics.`,
async () => {
const detectorInfo = await getDetectorInfo(cloudTarget, "aks-category-connectivity");
if (failed(detectorInfo)) {
vscode.window.showErrorMessage(detectorInfo.error);
return;
}
const detectorMap = await getDetectorListData(cloudTarget, detectorInfo.result);
if (failed(detectorMap)) {
vscode.window.showErrorMessage(detectorMap.error);
return;
}
const webview = createWebView('AKS Diagnostics', `AKS diagnostics view for: ${clustername}`).webview;
webview.html = getWebviewContent(detectorInfo.result, detectorMap.result, extensionPath, webview);
}
);
}
function getWebviewContent(
clusterdata: AppLensARMResponse,
detectorMap: Map<string, AppLensARMResponse>,
vscodeExtensionPath: string,
webview: vscode.Webview
): string {
const webviewClusterData = clusterdata?.properties;
const styleUri = getResourceUri(webview, vscodeExtensionPath, 'common', 'detector.css');
const templateUri = getResourceUri(webview, vscodeExtensionPath, 'common', 'detector.html');
const data = {
cssuri: styleUri,
name: webviewClusterData.metadata.name,
description: webviewClusterData.metadata.description,
portalUrl: getPortalUrl(clusterdata),
detectorData: detectorMap
};
return getRenderedContent(templateUri, data);
}

Просмотреть файл

@ -29,7 +29,16 @@ htmlhandlers.registerHelper('markdownHelper', (htmltext: string) => {
htmlhandlers.registerHelper('eachProperty', (context, options) => {
let ret = "";
context.forEach((element: any) => {
ret = ret + options.fn({ property: element.properties.dataset[0].table.rows, value: element.properties.metadata.name });
// Rather than using the first dataset, we use the first dataset that has 'type 7' in its rendering properties.
// This appears to correspond to the 'summary' dataset, which we previously thought was always the first one,
// but isn't always (as in snat-usage).
const summaryDatasets = element.properties.dataset.filter((d: any) => d.renderingProperties.type === 7);
if (summaryDatasets.length === 0) {
vscode.window.showErrorMessage(`No data set of type 7 for detector entity ${element.properties.metadata.name}`);
return;
}
ret = ret + options.fn({ property: summaryDatasets[0].table.rows, value: element.properties.metadata.name });
});
return ret;
});

Просмотреть файл

@ -22,6 +22,7 @@ import aksClusterProperties from './commands/aksClusterProperties/aksClusterProp
import aksCreateClusterNavToAzurePortal from './commands/aksCreateClusterNavToAzurePortal/aksCreateClusterNavToAzurePortal';
import { registerAzureUtilsExtensionVariables } from '@microsoft/vscode-azext-azureutils';
import { aksKubectlGetPodsCommands, aksKubectlGetClusterInfoCommands, aksKubectlGetAPIResourcesCommands, aksKubectlGetNodeCommands, aksKubectlDescribeServicesCommands, aksKubectlGetEventsCommands } from './commands/aksKubectlCommands/aksKubectlCommands';
import aksCategoryConnectivity from './commands/aksCategoryConnectivity/aksCategoryConnectivity';
export async function activate(context: vscode.ExtensionContext) {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
@ -62,6 +63,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerCommandWithTelemetry('aks.aksKubectlGetNodeCommands', aksKubectlGetNodeCommands);
registerCommandWithTelemetry('aks.aksKubectlDescribeServicesCommands', aksKubectlDescribeServicesCommands);
registerCommandWithTelemetry('aks.aksKubectlGetEventsCommands', aksKubectlGetEventsCommands);
registerCommandWithTelemetry('aks.aksCategoryConnectivity', aksCategoryConnectivity);
await registerAzureServiceNodes(context);