Skip to content

Commit ec8bb95

Browse files
authored
Fix duplicated repo name ids (#495)
* Fix filter by helm chart source - To reproduce add bitnami helm repo endpoint named `bitnami`, add helm hub , try to filter by helm repo endpoint and nothing changes - the helm repo bitnami charts were being overwritten by the helm hub bitnami charts as they were keyed the same in the store - Fix is to ensure charts are keyed with their source * Display helm hub label in chart summary view
1 parent 8173e37 commit ec8bb95

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

src/frontend/packages/suse-extensions/src/custom/helm/helm-entity-factory.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import { Schema, schema } from 'normalizr';
22

33
import { EntitySchema } from '../../../../store/src/helpers/entity-schema';
4+
import { stratosMonocularEndpointGuid } from './monocular/stratos-monocular.helper';
45
import { HelmVersion, MonocularChart } from './store/helm.types';
56

67
export const helmVersionsEntityType = 'helmVersions';
78
export const monocularChartsEntityType = 'monocularCharts';
89
export const monocularChartVersionsEntityType = 'monocularChartVersions';
910

10-
export const getMonocularChartId = (entity: MonocularChart) => entity.id;
11-
export const getHelmVersionId = (entity: HelmVersion) => entity.endpointId;
12-
1311
export const HELM_ENDPOINT_TYPE = 'helm';
1412
export const HELM_REPO_ENDPOINT_TYPE = 'repo';
1513
export const HELM_HUB_ENDPOINT_TYPE = 'hub';
@@ -39,19 +37,24 @@ export class HelmEntitySchema extends EntitySchema {
3937
entityCache[monocularChartsEntityType] = new HelmEntitySchema(
4038
monocularChartsEntityType,
4139
{},
42-
{ idAttribute: getMonocularChartId }
40+
{
41+
idAttribute: (entity: MonocularChart) => {
42+
const monocularPrefix = entity.monocularEndpointId || stratosMonocularEndpointGuid;
43+
return monocularPrefix + '/' + entity.id;
44+
}
45+
}
4346
);
4447

4548
entityCache[helmVersionsEntityType] = new HelmEntitySchema(
4649
helmVersionsEntityType,
4750
{},
48-
{ idAttribute: getHelmVersionId }
51+
{ idAttribute: (entity: HelmVersion) => entity.endpointId }
4952
);
5053

5154
entityCache[monocularChartVersionsEntityType] = new HelmEntitySchema(
5255
monocularChartVersionsEntityType,
5356
{},
54-
{ idAttribute: getMonocularChartId }
57+
{ idAttribute: (entity: MonocularChart) => entity.id }
5558
);
5659

5760
export function helmEntityFactory(key: string): EntitySchema {

src/frontend/packages/suse-extensions/src/custom/helm/monocular/chart-details/chart-details.component.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ <h2>Sorry, we couldn't find the chart</h2>
55
<app-loader [loading]="loading">
66
<div class="chart-details__wrapper">
77
<app-entity-summary-title class="summary-title" *ngIf="chart" [title]="chart.attributes.name"
8-
subTitle="{{ chart.attributes.repo.name }}"
9-
[subText]="chart.attributes.description" [imagePath]="iconUrl">
8+
[subTitle]="chartSubTitle" [subText]="chart.attributes.description" [imagePath]="iconUrl">
109
<div class="chart-details__content">
1110
<article class="chart-details__content__docs">
1211
<app-chart-details-readme [currentVersion]=currentVersion></app-chart-details-readme>

src/frontend/packages/suse-extensions/src/custom/helm/monocular/chart-details/chart-details.component.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Chart } from '../shared/models/chart';
66
import { ChartVersion } from '../shared/models/chart-version';
77
import { ChartsService } from '../shared/services/charts.service';
88
import { ConfigService } from '../shared/services/config.service';
9-
import { getMonocularEndpoint } from '../stratos-monocular.helper';
9+
import { getMonocularEndpoint, stratosMonocularEndpointGuid } from '../stratos-monocular.helper';
1010

1111
@Component({
1212
selector: 'app-chart-details',
@@ -21,6 +21,7 @@ export class ChartDetailsComponent implements OnInit {
2121
currentVersion: ChartVersion;
2222
iconUrl: string;
2323
titleVersion: string;
24+
chartSubTitle: string;
2425

2526
loadingDelay: any;
2627

@@ -43,6 +44,10 @@ export class ChartDetailsComponent implements OnInit {
4344
this.loading = false;
4445
this.initing = false;
4546
this.chart = chart;
47+
this.chartSubTitle = chart.attributes.repo.name;
48+
if (getMonocularEndpoint(this.route, chart) !== stratosMonocularEndpointGuid) {
49+
this.chartSubTitle = 'Helm Hub - ' + this.chartSubTitle;
50+
}
4651
const version = params.version || this.chart.relationships.latestChartVersion.data.version;
4752
this.chartsService.getVersion(repo, chartName, version).pipe(first())
4853
.subscribe(chartVersion => {

src/frontend/packages/suse-extensions/src/custom/helm/store/helm.effects.ts

+17-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
import { ClearPaginationOfType, ResetPaginationOfType } from '../../../../../store/src/actions/pagination.actions';
1919
import { AppState } from '../../../../../store/src/app-state';
2020
import { entityCatalog } from '../../../../../store/src/entity-catalog/entity-catalog';
21+
import { EntitySchema } from '../../../../../store/src/helpers/entity-schema';
2122
import { isJetstreamError } from '../../../../../store/src/jetstream';
2223
import { ApiRequestTypes } from '../../../../../store/src/reducers/api-request-reducer/request-helpers';
2324
import { endpointOfTypeSelector } from '../../../../../store/src/selectors/endpoint.selectors';
@@ -31,13 +32,7 @@ import {
3132
WrapperRequestActionSuccess,
3233
} from '../../../../../store/src/types/request.types';
3334
import { helmEntityCatalog } from '../helm-entity-catalog';
34-
import {
35-
getHelmVersionId,
36-
getMonocularChartId,
37-
HELM_ENDPOINT_TYPE,
38-
HELM_HUB_ENDPOINT_TYPE,
39-
HELM_REPO_ENDPOINT_TYPE,
40-
} from '../helm-entity-factory';
35+
import { HELM_ENDPOINT_TYPE, HELM_HUB_ENDPOINT_TYPE, HELM_REPO_ENDPOINT_TYPE } from '../helm-entity-factory';
4136
import { Chart } from '../monocular/shared/models/chart';
4237
import { stratosMonocularEndpointGuid } from '../monocular/stratos-monocular.helper';
4338
import {
@@ -58,15 +53,19 @@ type MonocularChartsResponse = {
5853
data: Chart[];
5954
};
6055

61-
const mapMonocularChartResponse = (entityKey: string, response: MonocularChartsResponse): NormalizedResponse => {
56+
const mapMonocularChartResponse = (
57+
entityKey: string,
58+
response: MonocularChartsResponse,
59+
schema: EntitySchema
60+
): NormalizedResponse => {
6261
const base: NormalizedResponse = {
6362
entities: { [entityKey]: {} },
6463
result: []
6564
};
6665

6766
const items = response.data as Array<any>;
6867
const processedData: NormalizedResponse = items.reduce((res, data) => {
69-
const id = getMonocularChartId(data);
68+
const id = schema.getId(data);
7069
res.entities[entityKey][id] = data;
7170
// Promote the name to the top-level object for simplicity
7271
data.name = data.attributes.name;
@@ -76,12 +75,16 @@ const mapMonocularChartResponse = (entityKey: string, response: MonocularChartsR
7675
return processedData;
7776
};
7877

79-
const mergeMonocularChartResponses = (entityKey: string, responses: MonocularChartsResponse[]): NormalizedResponse => {
78+
const mergeMonocularChartResponses = (
79+
entityKey: string,
80+
responses: MonocularChartsResponse[],
81+
schema: EntitySchema
82+
): NormalizedResponse => {
8083
const combined = responses.reduce((res, response) => {
8184
res.data = res.data.concat(response.data);
8285
return res;
8386
}, { data: [] });
84-
return mapMonocularChartResponse(entityKey, combined);
87+
return mapMonocularChartResponse(entityKey, combined, schema);
8588
};
8689

8790
const addMonocularId = (endpointId: string, response: MonocularChartsResponse): MonocularChartsResponse => {
@@ -155,7 +158,7 @@ export class HelmEffects {
155158
this.createHelmRepoRequest(helmEndpoints),
156159
this.createHelmHubRequest(helmHubEndpoint)
157160
]).pipe(
158-
map(res => mergeMonocularChartResponses(entityKey, res)),
161+
map(res => mergeMonocularChartResponses(entityKey, res, action.entity[0])),
159162
mergeMap((response: NormalizedResponse) => [new WrapperRequestActionSuccess(response, action)]),
160163
catchError(error => {
161164
const { status, message } = HelmEffects.createHelmError(error);
@@ -199,7 +202,7 @@ export class HelmEffects {
199202
endpointId: endpoint,
200203
...endpointData
201204
};
202-
processedData.entities[entityKey][getHelmVersionId(version)] = version;
205+
processedData.entities[entityKey][action.entity[0].getId(version)] = version;
203206
processedData.result.push(endpoint);
204207
});
205208
return processedData;
@@ -221,7 +224,7 @@ export class HelmEffects {
221224

222225
const items = response.data as Array<any>;
223226
const processedData = items.reduce((res, data) => {
224-
const id = getMonocularChartId(data);
227+
const id = action.entity[0].getId(data);
225228
res.entities[entityKey][id] = data;
226229
// Promote the name to the top-level object for simplicity
227230
data.name = data.attributes.name;

0 commit comments

Comments
 (0)