From f72b3df47091a3e663ecbb3dea63977b8ded1d73 Mon Sep 17 00:00:00 2001 From: Mathieu LAUDE Date: Tue, 7 Jan 2025 12:10:58 +0100 Subject: [PATCH] feat: :sparkles: add an 'external' boolean properties on clusters --- apps/client/src/components/ClusterForm.vue | 9 +++++++++ .../prisma/migrations/20250107104749_dso/migration.sql | 2 ++ apps/server/src/prisma/schema/topography.prisma | 1 + apps/server/src/resources/cluster/business.spec.ts | 1 + apps/server/src/resources/cluster/queries.ts | 3 +++ apps/server/src/resources/cluster/router.spec.ts | 3 +++ apps/server/src/resources/project/queries.ts | 2 ++ apps/server/src/resources/repository/router.spec.ts | 2 +- packages/hooks/src/hooks/index.ts | 1 + packages/shared/src/schemas/cluster.ts | 1 + packages/shared/src/utils/schemas.spec.ts | 2 ++ packages/test-utils/src/utils/random-utils.ts | 1 + plugins/argocd/src/functions.ts | 2 +- plugins/kubernetes/src/api.ts | 2 +- 14 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/prisma/migrations/20250107104749_dso/migration.sql diff --git a/apps/client/src/components/ClusterForm.vue b/apps/client/src/components/ClusterForm.vue index 6620c519d..e0933c4f0 100644 --- a/apps/client/src/components/ClusterForm.vue +++ b/apps/client/src/components/ClusterForm.vue @@ -36,6 +36,7 @@ const props = withDefaults(defineProps<{ clusterResources: false, privacy: ClusterPrivacy.DEDICATED, infos: '', + external: false, id: '', kubeconfig: { cluster: { @@ -289,6 +290,14 @@ const isConnectionDetailsShown = ref(true) name="isClusterSkipTlsVerify" :disabled="localCluster.label === inClusterLabel" /> + +

{ clusterResources: false, kubeconfig: { cluster: { tlsServerName: faker.internet.domainName() }, user: {} }, label: faker.string.alpha(10), + external: false, }, userId, reqId) expect(response).not.instanceOf(ErrorResType) diff --git a/apps/server/src/resources/cluster/queries.ts b/apps/server/src/resources/cluster/queries.ts index dbd6aef20..26c48f40c 100644 --- a/apps/server/src/resources/cluster/queries.ts +++ b/apps/server/src/resources/cluster/queries.ts @@ -29,6 +29,7 @@ export async function getClustersAssociatedWithProject(projectId: Project['id']) id: true, infos: true, label: true, + external: true, privacy: true, secretName: true, kubeconfig: true, @@ -107,6 +108,7 @@ export function getClusterDetails(id: Cluster['id']) { id: true, clusterResources: true, infos: true, + external: true, label: true, privacy: true, kubeconfig: true, @@ -197,6 +199,7 @@ export function listClusters(where: Prisma.ClusterWhereInput) { clusterResources: true, privacy: true, infos: true, + external: true, zoneId: true, }, }) diff --git a/apps/server/src/resources/cluster/router.spec.ts b/apps/server/src/resources/cluster/router.spec.ts index 7822b5ec9..a501187ef 100644 --- a/apps/server/src/resources/cluster/router.spec.ts +++ b/apps/server/src/resources/cluster/router.spec.ts @@ -60,6 +60,7 @@ describe('test clusterContract', () => { id: faker.string.uuid(), clusterResources: true, infos: '', + external: false, label: faker.string.alpha(), privacy: 'public', stageIds: [], @@ -127,6 +128,7 @@ describe('test clusterContract', () => { id: faker.string.uuid(), clusterResources: true, infos: '', + external: true, label: faker.string.alpha(), privacy: 'public', stageIds: [], @@ -180,6 +182,7 @@ describe('test clusterContract', () => { const cluster: Omit = { clusterResources: true, infos: '', + external: false, label: faker.string.alpha(), privacy: 'public', stageIds: [], diff --git a/apps/server/src/resources/project/queries.ts b/apps/server/src/resources/project/queries.ts index 3423e2b29..2a6d4f72d 100644 --- a/apps/server/src/resources/project/queries.ts +++ b/apps/server/src/resources/project/queries.ts @@ -133,6 +133,7 @@ export function getProjectInfosByIdOrThrow(projectId: Project['id']) { id: true, label: true, privacy: true, + external: true, clusterResources: true, infos: true, zone: true, @@ -239,6 +240,7 @@ const clusterInfosSelect = { id: true, infos: true, label: true, + external: true, privacy: true, secretName: true, kubeconfig: true, diff --git a/apps/server/src/resources/repository/router.spec.ts b/apps/server/src/resources/repository/router.spec.ts index 5672253a2..ca184a5bc 100644 --- a/apps/server/src/resources/repository/router.spec.ts +++ b/apps/server/src/resources/repository/router.spec.ts @@ -27,7 +27,7 @@ describe('repositoryRouter tests', () => { externalRepoUrl: `${faker.internet.url()}.git`, isPrivate: true, externalToken: faker.string.alpha(), - externalUserName: faker.internet.userName(), + externalUserName: faker.internet.username(), isInfra: false, internalRepoName: faker.string.alpha({ length: 5, casing: 'lower' }), } diff --git a/packages/hooks/src/hooks/index.ts b/packages/hooks/src/hooks/index.ts index c6a253e10..1323504c6 100644 --- a/packages/hooks/src/hooks/index.ts +++ b/packages/hooks/src/hooks/index.ts @@ -53,6 +53,7 @@ export interface ClusterObject { id: string label: string privacy: 'public' | 'dedicated' + external: boolean secretName: string clusterResources: boolean infos: string | null diff --git a/packages/shared/src/schemas/cluster.ts b/packages/shared/src/schemas/cluster.ts index 720414eea..678999a04 100644 --- a/packages/shared/src/schemas/cluster.ts +++ b/packages/shared/src/schemas/cluster.ts @@ -13,6 +13,7 @@ export const CleanedClusterSchema = z.object({ .optional() .nullable() .transform(value => value ?? ''), + external: z.boolean(), clusterResources: z.boolean(), privacy: ClusterPrivacySchema, zoneId: z.string() diff --git a/packages/shared/src/utils/schemas.spec.ts b/packages/shared/src/utils/schemas.spec.ts index e88752428..1c5baf1cd 100644 --- a/packages/shared/src/utils/schemas.spec.ts +++ b/packages/shared/src/utils/schemas.spec.ts @@ -186,6 +186,7 @@ describe('schemas utils', () => { const toParse = { id: faker.string.uuid(), label: 'cluster', + external: false, clusterResources: true, infos: 'Infos du cluster', privacy: ClusterPrivacy.DEDICATED, @@ -209,6 +210,7 @@ describe('schemas utils', () => { const toParse = { id: faker.string.uuid(), label: 'cluster', + external: true, clusterResources: true, privacy: ClusterPrivacy.PUBLIC, zoneId: faker.string.uuid(), diff --git a/packages/test-utils/src/utils/random-utils.ts b/packages/test-utils/src/utils/random-utils.ts index dca6bd897..682de766f 100644 --- a/packages/test-utils/src/utils/random-utils.ts +++ b/packages/test-utils/src/utils/random-utils.ts @@ -55,6 +55,7 @@ export function getRandomCluster({ projectIds = repeatFn(2)(faker.string.uuid), id: faker.string.uuid(), label: faker.lorem.word(), infos: faker.lorem.sentence(8), + external: false, zoneId, projectIds: privacy === ClusterPrivacy.DEDICATED ? projectIds : [], stageIds, diff --git a/plugins/argocd/src/functions.ts b/plugins/argocd/src/functions.ts index 3dbb1bcf6..dd4f54e07 100644 --- a/plugins/argocd/src/functions.ts +++ b/plugins/argocd/src/functions.ts @@ -83,7 +83,7 @@ export const upsertProject: StepCall = async (payload) => { vaultApi, ) - if (cluster.label !== inClusterLabel && !cluster.user.keyData && !cluster.user.token) { + if (cluster.label !== inClusterLabel && cluster.external) { console.log(`Direct argocd API calls are disabled for cluster ${cluster.label}`) return undefined } diff --git a/plugins/kubernetes/src/api.ts b/plugins/kubernetes/src/api.ts index e2a329149..e2a3a7ad1 100644 --- a/plugins/kubernetes/src/api.ts +++ b/plugins/kubernetes/src/api.ts @@ -28,7 +28,7 @@ function makeClusterApi(cluster: ClusterObject): KubeConfig | undefined { kc.loadFromCluster() return kc } - if (!cluster.user.keyData && !cluster.user.token) { + if (cluster.external) { // Special case: disable direct calls to the cluster return undefined }