Skip to content

Commit 54a40fb

Browse files
committed
fix: 🐛 add retro compatibility for 8.24.2
1 parent ff3011d commit 54a40fb

File tree

6 files changed

+82
-32
lines changed

6 files changed

+82
-32
lines changed

files/logo.png

1.16 KB
Loading

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@cpn-console/observability-plugin",
33
"type": "module",
4-
"version": "0.1.3",
4+
"version": "0.1.2-patch-1",
55
"description": "Loki plugin for DSO console",
66
"exports": {
77
".": {

src/function.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,19 @@ export const upsertProject: StepCall<Project> = async (payload) => {
8484
if (!environment.apis.kubernetes) {
8585
throw new Error(`no kubernetes apis on environment ${environment.name}`)
8686
}
87-
const gen = isNewNsName(await environment.apis.kubernetes.getNsName()) ? compressedUUID : project.slug
87+
const name = isNewNsName(await environment.apis.kubernetes.getNsName()) ? compressedUUID : project.slug
8888
if (environment.stage === 'prod') {
89-
tenantsToCreate[`prod-${gen}`] = tenantRbacProd
89+
tenantsToCreate[`prod-${name}`] = {
90+
groups: tenantRbacProd,
91+
name,
92+
type: 'prod',
93+
}
9094
} else {
91-
tenantsToCreate[`hprod-${gen}`] = tenantRbacHProd
95+
tenantsToCreate[`hprod-${name}`] = {
96+
groups: tenantRbacHProd,
97+
name,
98+
type: 'hprod',
99+
}
92100
}
93101
}
94102

src/infos.ts

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,45 @@ const imageData = Buffer.from((readFileSync(join(import.meta.dirname, '../files/
88

99
const infos = {
1010
name: 'observability',
11-
to: ({ project }) => [
12-
{
13-
to: `${getConfig().grafanaUrl}/prod-${compressUUID(project.id)}`,
14-
description: 'Production',
15-
},
16-
{
17-
to: `${getConfig().grafanaUrl}/prod-${project.slug}`,
18-
description: 'Production ancien',
19-
},
20-
{
21-
to: `${getConfig().grafanaUrl}/hprod-${compressUUID(project.id)}`,
22-
description: 'Hors production',
23-
},
24-
{
25-
to: `${getConfig().grafanaUrl}/hprod-${project.slug}`,
26-
description: 'Hors production ancien',
27-
},
28-
],
11+
// @ts-ignore retro compatibility
12+
to: ({ project, projectId, organization }) => {
13+
let isInfV9 = false
14+
const params = {
15+
id: '',
16+
slug: '',
17+
}
18+
const grafanaUrl = getConfig().grafanaUrl
19+
if (typeof project === 'string' && typeof organization === 'string') {
20+
params.id = projectId
21+
params.slug = `${organization}-${project}`
22+
isInfV9 = true
23+
} else {
24+
params.id = project.id
25+
params.slug = project.slug
26+
}
27+
return [
28+
{
29+
to: `${grafanaUrl}/prod-${compressUUID(String(params.id))}`,
30+
title: isInfV9 ? 'Production' : undefined,
31+
description: 'Production',
32+
},
33+
{
34+
to: `${grafanaUrl}/prod-${params.slug}`,
35+
title: isInfV9 ? 'Production ancien' : undefined,
36+
description: 'Production ancien',
37+
},
38+
{
39+
to: `${grafanaUrl}/hprod-${compressUUID(String(params.id))}`,
40+
title: isInfV9 ? 'Hors production' : undefined,
41+
description: 'Hors production',
42+
},
43+
{
44+
to: `${grafanaUrl}/hprod-${params.slug}`,
45+
title: isInfV9 ? 'Hors production ancien' : undefined,
46+
description: 'Hors production ancien',
47+
},
48+
]
49+
},
2950
title: 'Grafana',
3051
imgSrc: `data:image/png;base64,${imageData}`,
3152
description: 'Grafana est un outil de métrique et de logs',

src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,13 @@ export function getCustomK8sApi(): CustomObjectsApi {
6262

6363
export type Stage = 'prod' | 'hprod'
6464

65+
export interface TenantInfo {
66+
groups: string[]
67+
type: 'prod' | 'hprod'
68+
name: string // tenant name, short-uuid or slug
69+
}
6570
export interface TenantKeycloakMapper {
66-
[x: string]: string[]
71+
[x: string]: TenantInfo // fullName, type + (short-uuid or slug)
6772
}
6873

6974
const re = /[a-z0-9]{25}--[a-z0-9]{25}/

src/yaml.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
Project as GitlabProject,
55
Group,
66
} from './gitlab.js'
7-
import type { TenantKeycloakMapper } from './utils.js'
7+
import type { TenantInfo, TenantKeycloakMapper } from './utils.js'
88
// @ts-ignore
99
import yaml from 'js-yaml'
1010
import {
@@ -20,9 +20,11 @@ const valuesPath = 'helm/values.yaml'
2020
const valuesBranch = 'main'
2121

2222
interface ProjectLoki {
23-
name: string
23+
project: string // slug
24+
name: string // slug ou short-uuid (capture regex)
2425
groups: string[]
25-
uuid: string
26+
uuid: string // uuid du projet
27+
type: 'prod' | 'hprod'
2628
// urls: string[]
2729
}
2830

@@ -115,22 +117,36 @@ export async function upsertGitlabConfig(project: Project, gitlabApi: GitlabInte
115117

116118
for (const tenant of yamlFile.global.tenants) {
117119
if (tenant.uuid !== project.id) continue
118-
if (tenant.name in tenants) {
119-
if (tenant.groups.toString() !== tenants[tenant.name].toString()) {
120+
const fullName = `${tenant.type}-${tenant.name}`
121+
const matchingTenant = tenants[fullName] as TenantInfo | undefined
122+
if (matchingTenant) {
123+
if (tenant.groups.toString() !== tenants[tenant.name].groups.toString()) {
120124
needUpdates = true
121-
tenant.groups = structuredClone(tenants[tenant.name])
125+
tenant.groups = structuredClone(tenants[tenant.name].groups)
122126
}
123-
notFoundTenants = notFoundTenants.filter(notFoundTenant => notFoundTenant !== tenant.name)
127+
if (tenant.project !== project.slug) {
128+
needUpdates = true
129+
tenant.project = project.slug
130+
}
131+
if (tenant.name !== matchingTenant.name) {
132+
needUpdates = true
133+
tenant.name = matchingTenant.name
134+
}
135+
if (tenant.type !== matchingTenant.type) {
136+
needUpdates = true
137+
tenant.type = matchingTenant.type
138+
}
139+
notFoundTenants = notFoundTenants.filter(notFoundTenant => notFoundTenant !== fullName)
124140
} else {
125141
needUpdates = true
126142
shouldBeRemoved.push(tenant.name)
127143
}
128144
}
129145

130146
const newTenants = notFoundTenants.map((notFoundTenant): ProjectLoki => ({
131-
groups: structuredClone(tenants[notFoundTenant]),
132-
name: notFoundTenant,
147+
...structuredClone(tenants[notFoundTenant]),
133148
uuid: project.id,
149+
project: project.slug,
134150
}))
135151

136152
yamlFile = {

0 commit comments

Comments
 (0)