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

Feat/external cluster #1497

Merged
merged 1 commit into from
Jan 23, 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
9 changes: 9 additions & 0 deletions apps/client/src/components/ClusterForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const props = withDefaults(defineProps<{
clusterResources: false,
privacy: ClusterPrivacy.DEDICATED,
infos: '',
external: false,
id: '',
kubeconfig: {
cluster: {
Expand Down Expand Up @@ -289,6 +290,14 @@ const isConnectionDetailsShown = ref(true)
name="isClusterSkipTlsVerify"
:disabled="localCluster.label === inClusterLabel"
/>

<DsfrCheckbox
id="externalClusterCbx"
v-model="localCluster.external"
label="Cluster externe"
hint="La console DSO n'essaiera pas de joindre l'API de ce cluster, le ArgoCD de la zone de chargera de configurer celui-ci."
name="isExternalCluster"
/>
</template>
<h4
class="mb-1 inline-block"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "Cluster" ADD COLUMN "external" BOOLEAN NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions apps/server/src/prisma/schema/topography.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ model Cluster {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
infos String? @db.VarChar(200)
external Boolean @default(false)
zoneId String @db.Uuid
kubeconfig Kubeconfig @relation(fields: [kubeConfigId], references: [id], onDelete: Cascade)
zone Zone @relation(fields: [zoneId], references: [id])
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/resources/cluster/business.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ describe('test Cluster business logic', () => {
clusterResources: false,
kubeconfig: { cluster: { tlsServerName: faker.internet.domainName() }, user: {} },
label: faker.string.alpha(10),
external: false,
}, userId, reqId)

expect(response).not.instanceOf(ErrorResType)
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/resources/cluster/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -107,6 +108,7 @@ export function getClusterDetails(id: Cluster['id']) {
id: true,
clusterResources: true,
infos: true,
external: true,
label: true,
privacy: true,
kubeconfig: true,
Expand Down Expand Up @@ -197,6 +199,7 @@ export function listClusters(where: Prisma.ClusterWhereInput) {
clusterResources: true,
privacy: true,
infos: true,
external: true,
zoneId: true,
},
})
Expand Down
3 changes: 3 additions & 0 deletions apps/server/src/resources/cluster/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('test clusterContract', () => {
id: faker.string.uuid(),
clusterResources: true,
infos: '',
external: false,
label: faker.string.alpha(),
privacy: 'public',
stageIds: [],
Expand Down Expand Up @@ -127,6 +128,7 @@ describe('test clusterContract', () => {
id: faker.string.uuid(),
clusterResources: true,
infos: '',
external: true,
label: faker.string.alpha(),
privacy: 'public',
stageIds: [],
Expand Down Expand Up @@ -180,6 +182,7 @@ describe('test clusterContract', () => {
const cluster: Omit<ClusterDetails, 'id'> = {
clusterResources: true,
infos: '',
external: false,
label: faker.string.alpha(),
privacy: 'public',
stageIds: [],
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/resources/project/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export function getProjectInfosByIdOrThrow(projectId: Project['id']) {
id: true,
label: true,
privacy: true,
external: true,
clusterResources: true,
infos: true,
zone: true,
Expand Down Expand Up @@ -239,6 +240,7 @@ const clusterInfosSelect = {
id: true,
infos: true,
label: true,
external: true,
privacy: true,
secretName: true,
kubeconfig: true,
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/resources/repository/router.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }),
}
Expand Down
1 change: 1 addition & 0 deletions packages/hooks/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface ClusterObject {
id: string
label: string
privacy: 'public' | 'dedicated'
external: boolean
secretName: string
clusterResources: boolean
infos: string | null
Expand Down
1 change: 1 addition & 0 deletions packages/shared/src/schemas/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/utils/schemas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions packages/test-utils/src/utils/random-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion plugins/argocd/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const upsertProject: StepCall<Project> = 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
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading