Skip to content
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
8 changes: 6 additions & 2 deletions apps/event-worker/src/resource-scan/azure/aks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,13 @@ export const getAksResources = async (
clusters.push(cluster);
}

const { resourceProviderId: providerId } = azureProvider;
const resourcePromises = clusters.map((cluster) =>
convertManagedClusterToResource(workspace.id, providerId, cluster, client),
convertManagedClusterToResource(
workspace.id,
azureProvider,
cluster,
client,
),
);
const resources = await Promise.all(resourcePromises);
return resources.filter(isPresent);
Expand Down
13 changes: 10 additions & 3 deletions apps/event-worker/src/resource-scan/azure/cluster-to-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
ContainerServiceClient,
ManagedCluster,
} from "@azure/arm-containerservice";
import type * as SCHEMA from "@ctrlplane/db/schema";
import type { KubernetesClusterAPIV1 } from "@ctrlplane/validators/resources";
import * as yaml from "js-yaml";
import { z } from "zod";
Expand Down Expand Up @@ -59,7 +60,7 @@ const getCertificateAuthorityData = async (

export const convertManagedClusterToResource = async (
workspaceId: string,
providerId: string,
provider: SCHEMA.ResourceProviderAzure,
cluster: ManagedCluster,
client: ContainerServiceClient,
): Promise<ClusterResource | null> => {
Expand All @@ -77,14 +78,20 @@ export const convertManagedClusterToResource = async (
const ca = await getCertificateAuthorityData(cluster, resourceGroup, client);
return {
workspaceId,
providerId,
providerId: provider.resourceProviderId,
name: cluster.name,
identifier: cluster.id,
version: "kubernetes/v1",
kind: "ClusterAPI",
config: {
name: cluster.name,
auth: { method: "azure/aks", clusterName: cluster.name, resourceGroup },
auth: {
method: "azure/aks",
clusterName: cluster.name,
resourceGroup,
tenantId: provider.tenantId,
subscriptionId: provider.subscriptionId,
},
status: cluster.provisioningState ?? "UNKNOWN",
server: { ...ca, endpoint: ca?.endpoint ?? cluster.fqdn ?? "" },
},
Expand Down
2 changes: 2 additions & 0 deletions packages/validators/src/resources/kubernetes-v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const clusterConfig = z.object({
method: z.literal("azure/aks"),
resourceGroup: z.string(),
clusterName: z.string(),
tenantId: z.string(),
subscriptionId: z.string(),
}),
z.object({
method: z.literal("exec"),
Expand Down
Loading