Skip to content

Commit 192eb07

Browse files
authored
fix: add AplCatalogChartSpec to support status object (#953)
1 parent 10ef130 commit 192eb07

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/openapi/catalog.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ AplCatalogChartSpec:
3333
type: object
3434
chartsPath:
3535
type: string
36+
branch:
37+
type: string
38+
repositoryUrl:
39+
type: string
3640
required:
3741
- name
3842
- version

src/otomi-models.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export type TeamAuthz = components['schemas']['TeamAuthz']
6565
export type AplCatalog = components['schemas']['AplCatalog']
6666
export type AplCatalogRequest = components['schemas']['AplCatalogRequest']
6767
export type AplCatalogResponse = components['schemas']['AplCatalogResponse']
68+
export type AplCatalogChartResponse = components['schemas']['AplCatalogChartResponse']
6869
// Derived setting models
6970
export type Alerts = Settings['alerts']
7071
export type Cluster = Settings['cluster']
@@ -103,6 +104,7 @@ export const APL_KINDS = [
103104
'AplAlertSet',
104105
'AplCluster',
105106
'AplCatalog',
107+
'AplCatalogChart',
106108
'AplDatabase',
107109
'AplDns',
108110
'AplIngress',

src/otomi-stack.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
AplAIModelResponse,
2929
AplBuildRequest,
3030
AplBuildResponse,
31+
AplCatalogChartResponse,
3132
AplCatalogRequest,
3233
AplCatalogResponse,
3334
AplCodeRepoRequest,
@@ -867,10 +868,11 @@ export default class OtomiStack {
867868
async saveCatalog(data: AplPlatformObject): Promise<AplRecord> {
868869
debug(`Saving catalog: ${data.metadata.name}`)
869870

870-
const filePath = this.fileStore.setPlatformResource(data)
871-
await this.git.writeFile(filePath, data)
871+
const content = toPlatformObject(data.kind, data.metadata.name, data.spec)
872+
const filePath = this.fileStore.setPlatformResource(content)
873+
await this.git.writeFile(filePath, content)
872874

873-
return { filePath, content: data }
875+
return { filePath, content }
874876
}
875877

876878
async saveTeamSealedSecret(teamId: string, data: SealedSecretManifestRequest): Promise<AplRecord> {
@@ -1753,22 +1755,24 @@ export default class OtomiStack {
17531755
}
17541756
}
17551757

1756-
async getAplCatalogCharts(name: string): Promise<{ url: string; helmCharts: any; catalog: any; branch: string }> {
1758+
async getAplCatalogCharts(name: string): Promise<AplCatalogChartResponse[]> {
17571759
const catalog = this.getAplCatalog(name)
17581760
const { repositoryUrl, branch, name: catalogName, chartsPath } = catalog.spec
1759-
const charts = await this.getBYOWorkloadCatalog(
1761+
const { catalog: chartCatalog } = await this.getBYOWorkloadCatalog(
17601762
repositoryUrl,
17611763
branch,
17621764
catalogName,
17631765
chartsPath as string | undefined,
17641766
)
1765-
return { ...charts, branch }
1767+
return (chartCatalog || []).map(
1768+
(chart: any) =>
1769+
toPlatformObject('AplCatalogChart', chart.name, [
1770+
{ ...chart, chartsPath, branch, repositoryUrl },
1771+
]) as unknown as AplCatalogChartResponse,
1772+
)
17661773
}
17671774

1768-
async getAplCatalogChart(
1769-
name: string,
1770-
chartName: string,
1771-
): Promise<{ url: string; branch: string; chart: any | null; chartsPath?: string }> {
1775+
async getAplCatalogChart(name: string, chartName: string): Promise<AplCatalogChartResponse> {
17721776
const catalog = this.getAplCatalog(name)
17731777
const { repositoryUrl, branch, chartsPath } = catalog.spec
17741778
const { cluster } = this.getSettings(['cluster'])
@@ -1782,10 +1786,14 @@ export default class OtomiStack {
17821786
await fetchWorkloadCatalog(repositoryUrl, helmChartsDir, branch, cluster?.domainSuffix, undefined, chartsPath)
17831787
).catalog.find((c) => c.name === chartName) || null
17841788

1785-
return { url: repositoryUrl, branch, chart: singleChart, chartsPath }
1789+
return toPlatformObject(
1790+
'AplCatalogChart',
1791+
chartName,
1792+
singleChart ? [{ ...singleChart, chartsPath, branch, repositoryUrl }] : [],
1793+
) as unknown as AplCatalogChartResponse
17861794
} catch (error) {
17871795
debug(`Error fetching workload chart '${chartName}': ${error.message}`)
1788-
return { url: repositoryUrl, branch, chart: null, chartsPath }
1796+
return toPlatformObject('AplCatalogChart', chartName, []) as unknown as AplCatalogChartResponse
17891797
}
17901798
}
17911799

0 commit comments

Comments
 (0)