Repository navigation
refactor(cluster): migrate module from server #2495
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
Open
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
0bdbb5a
refactor(cluster): migrate module from server
shikanime 70ec0ce
fix(server-nestjs): register AdminTokenModule for downstream stacks
shikanime 0261a15
refactor(cluster): reuse shared cluster body type aliases in controller
shikanime c57102b
fix(server-nestjs): drop AdminTokenModule registration, owned by stac…
shikanime 8c56224
refactor(cluster): upstream named body schemas and apply review fixes
shikanime c262f5b
refactor(cluster): use shared ClusterUsage type and plain string ids
shikanime 6377b16
fix(cluster): wire missing module imports
shikanime 7bfc3c8
fix(server-nestjs): provide EventEmitter2 to ClusterModule
shikanime a9cd258
test(cluster): lock controller permission matrix
shikanime a520733
fix(server-nestjs): wire ClusterModule provider imports
shikanime 7f071e1
fix(cluster): drop invalid guard metadata specs
shikanime f76bcb4
refactor(events): move plugin-failure throws into AppEventsService
shikanime 796e1dd
fix(argocd): align vault secret-id helper with renamed ensure method
shikanime a6352f9
refactor(events): return failed-event handling to calling services
shikanime ebd0f99
refactor(cluster): drop Query import aliases for query utils
shikanime bddd915
refactor(cluster): drop Kubeconfig import alias
shikanime 2c86e1a
refactor(cluster): move syncClusterStageLinks to queries utils
shikanime 29e6b92
refactor(cluster): restore local plugin-failure throws per zone pattern
shikanime f2d463c
fix(server-nestjs): restore legacy argocd cluster config parity
shikanime 575bbf5
refactor(server-nestjs): move cluster project-link sync to cluster-qu…
shikanime 8bdda44
fix(cluster): keep makeCluster factory module-local
shikanime dc44375
fix(cluster): port argocd handlers onto the renamed client methods
shikanime 1a244ca
fix(server-nestjs): keep AdminTokenModule registered alongside Cluste…
shikanime a877d9d
fix(cluster): validate the PUT clusterId and preserve dedicated proje…
shikanime 1e06cca
fix(argocd): restore legacy cluster-sync parity on delete and secret …
shikanime b6a8add
fix(cluster): serve the contract 204 status on cluster deletion
shikanime 6033fcb
fix(argocd): fail cluster sync when zone vault credentials are unavai…
shikanime 83bdc69
style(events): drop extra blank line in app-events.service
shikanime d60a3b6
refactor(argocd,cluster): dedupe factory, inline privacy enum, compos…
shikanime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
apps/server-nestjs/src/modules/argocd/argocd-datastore.service.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import type { TestingModule } from '@nestjs/testing' | ||
| import type { DeepMockProxy } from 'vitest-mock-extended' | ||
| import { Test } from '@nestjs/testing' | ||
| import { beforeEach, describe, expect, it } from 'vitest' | ||
| import { mockDeep } from 'vitest-mock-extended' | ||
| import { PrismaService } from '../infrastructure/database/prisma.service' | ||
| import { makeZone } from '../zone/zone-testing.utils' | ||
| import { ArgoCDDatastoreService } from './argocd-datastore.service' | ||
|
|
||
| function makeZoneWithClusters(labels: string[]) { | ||
| return { ...makeZone(), clusters: labels.map(label => ({ label })) } | ||
| } | ||
|
|
||
| describe('argoCDDatastoreService', () => { | ||
| let service: ArgoCDDatastoreService | ||
| let prisma: DeepMockProxy<PrismaService> | ||
|
|
||
| beforeEach(async () => { | ||
| prisma = mockDeep<PrismaService>() | ||
|
|
||
| const module: TestingModule = await Test.createTestingModule({ | ||
| providers: [ | ||
| ArgoCDDatastoreService, | ||
| { provide: PrismaService, useValue: prisma }, | ||
| ], | ||
| }).compile() | ||
|
|
||
| service = module.get(ArgoCDDatastoreService) | ||
| }) | ||
|
|
||
| describe('getZoneClusterNames', () => { | ||
| it('queries the zone by slug', async () => { | ||
| prisma.zone.findUnique.mockResolvedValue(makeZoneWithClusters(['review-cluster'])) | ||
|
|
||
| await service.getZoneClusterNames('zone-review') | ||
|
|
||
| expect(prisma.zone.findUnique).toHaveBeenCalledWith({ | ||
| where: { slug: 'zone-review' }, | ||
| select: { clusters: { select: { label: true } } }, | ||
| }) | ||
| }) | ||
|
|
||
| it('excludes the deleted cluster label', async () => { | ||
| prisma.zone.findUnique.mockResolvedValue(makeZoneWithClusters(['review-cluster', 'other-cluster'])) | ||
|
|
||
| await expect(service.getZoneClusterNames('zone-review', 'review-cluster')).resolves.toEqual(['other-cluster']) | ||
| }) | ||
|
|
||
| it('returns no names when the zone is unknown', async () => { | ||
| prisma.zone.findUnique.mockResolvedValue(null) | ||
|
|
||
| await expect(service.getZoneClusterNames('missing-zone')).resolves.toEqual([]) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 12 additions & 2 deletions
14
apps/server-nestjs/src/modules/argocd/argocd-testing.utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { Kubeconfig } from '@cpn-console/shared' | ||
|
|
||
| export function generateClusterTlsClientConfig(kubeconfig: Kubeconfig) { | ||
| return { | ||
| ...kubeconfig.user.username && { username: kubeconfig.user.username }, | ||
| ...kubeconfig.user.password && { password: kubeconfig.user.password }, | ||
| ...kubeconfig.user.token && { bearerToken: kubeconfig.user.token }, | ||
| tlsClientConfig: { | ||
| ...kubeconfig.user.keyData && { keyData: kubeconfig.user.keyData }, | ||
| ...kubeconfig.user.certData && { certData: kubeconfig.user.certData }, | ||
| ...kubeconfig.cluster.caData && !kubeconfig.cluster.skipTLSVerify && { caData: kubeconfig.cluster.caData }, | ||
| ...kubeconfig.cluster.skipTLSVerify && { insecure: kubeconfig.cluster.skipTLSVerify }, | ||
| serverName: kubeconfig.cluster.tlsServerName, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| export function generateZoneVaultValues(vaultUrl: string, zoneSlug: string, roleId: string | undefined, secretId: string | undefined) { | ||
| return { | ||
| url: vaultUrl, | ||
| kvName: `zone-${zoneSlug}`, | ||
| roleId: roleId ?? 'none', | ||
| secretId: secretId ?? 'none', | ||
| } | ||
| } | ||
|
|
||
| export function generateClusterSecretData(cluster: { label: string, clusterResources: boolean }, kubeconfig: Kubeconfig) { | ||
| return { | ||
| name: cluster.label, | ||
| clusterResources: String(cluster.clusterResources), | ||
| server: kubeconfig.cluster.server, | ||
| config: JSON.stringify(generateClusterTlsClientConfig(kubeconfig)), | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.