Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quick Refactor: Moving DiagnosticSetting function to common place Cluster.ts. #1295

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/commands/periscope/helpers/periscopehelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,9 @@ import { ContainerServiceClient } from "@azure/arm-containerservice";
import { getWindowsNodePoolKubernetesVersions } from "../../utils/clusters";
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
import { dirSync } from "tmp";
import { getMonitorClient, getStorageManagementClient } from "../../utils/arm";
import { getStorageManagementClient } from "../../utils/arm";
import { ReadyAzureSessionProvider } from "../../../auth/types";

export async function getClusterDiagnosticSettings(
sessionProvider: ReadyAzureSessionProvider,
clusterNode: AksClusterTreeNode,
): Promise<DiagnosticSettingsResourceCollection | undefined> {
try {
// Get diagnostic setting via diagnostic monitor
const client = getMonitorClient(sessionProvider, clusterNode.subscriptionId);
const diagnosticSettings = await client.diagnosticSettings.list(clusterNode.armId);

return diagnosticSettings;
} catch (e) {
vscode.window.showErrorMessage(`Error fetching cluster diagnostic monitor: ${e}`);
return undefined;
}
}

export async function chooseStorageAccount(
diagnosticSettings: DiagnosticSettingsResourceCollection,
): Promise<string | void> {
Expand Down
8 changes: 6 additions & 2 deletions src/commands/periscope/periscope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import * as vscode from "vscode";
import * as k8s from "vscode-kubernetes-tools-api";
import { IActionContext } from "@microsoft/vscode-azext-utils";
import * as tmpfile from "../utils/tempfile";
import { getAksClusterTreeNode, getKubeconfigYaml, getManagedCluster } from "../utils/clusters";
import {
getAksClusterTreeNode,
getClusterDiagnosticSettings,
getKubeconfigYaml,
getManagedCluster,
} from "../utils/clusters";
import { getKustomizeConfig } from "../utils/config";
import { getExtension, longRunning } from "../utils/host";
import {
getClusterDiagnosticSettings,
chooseStorageAccount,
getStorageInfo,
prepareAKSPeriscopeKustomizeOverlay,
Expand Down
20 changes: 19 additions & 1 deletion src/commands/utils/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as yaml from "js-yaml";
import * as path from "path";
import { dirSync } from "tmp";
import { AuthenticationSession, QuickPickItem, authentication, window } from "vscode";
import * as vscode from "vscode";
import {
API,
APIAvailable,
Expand All @@ -17,14 +18,15 @@ import { getTokenInfo } from "../../auth/azureAuth";
import { ReadyAzureSessionProvider, TokenInfo } from "../../auth/types";
import { AksClusterTreeNode } from "../../tree/aksClusterTreeItem";
import { SubscriptionTreeNode, isSubscriptionTreeNode } from "../../tree/subscriptionTreeItem";
import { getAksClient } from "./arm";
import { getAksClient, getMonitorClient } from "./arm";
import { Errorable, map as errmap, failed, getErrorMessage, succeeded } from "./errorable";
import { getKubeloginBinaryPath } from "./helper/kubeloginDownload";
import { longRunning } from "./host";
import { invokeKubectlCommand } from "./kubectl";
import { withOptionalTempFile } from "./tempfile";
import { getResources } from "./azureResources";
import { ClusterFilter } from "./config";
import { DiagnosticSettingsResourceCollection } from "@azure/arm-monitor";

export interface KubernetesClusterInfo {
readonly name: string;
Expand Down Expand Up @@ -678,3 +680,19 @@ export async function getClusters(
};
});
}

export async function getClusterDiagnosticSettings(
sessionProvider: ReadyAzureSessionProvider,
clusterNode: AksClusterTreeNode,
): Promise<DiagnosticSettingsResourceCollection | undefined> {
try {
// Get diagnostic setting via diagnostic monitor
const client = getMonitorClient(sessionProvider, clusterNode.subscriptionId);
const diagnosticSettings = await client.diagnosticSettings.list(clusterNode.armId);

return diagnosticSettings;
} catch (e) {
vscode.window.showErrorMessage(`Error fetching cluster diagnostic settings: ${e}`);
return undefined;
}
}