Skip to content

Commit 1d794ed

Browse files
authored
bug: fix reading organization cluster id (#32)
1 parent 0998bab commit 1d794ed

File tree

8 files changed

+102
-23
lines changed

8 files changed

+102
-23
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@types/jmespath": "0.15.2",
3636
"@types/jsonpath": "^0.2.4",
3737
"@ui5/webcomponents-ngx": "^0.5.0",
38+
"kubernetes-types": "^1.30.0",
3839
"cpx2": "^8.0.0",
3940
"jest": "^29.7.0",
4041
"jest-jasmine2": "29.7.0",

projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
7070
'kcp.io/cluster': 'cluster-123',
7171
},
7272
},
73+
spec: {
74+
organization: {
75+
originClusterId: 'originClusterId',
76+
},
77+
},
7378
} as any;
7479
const mockToken = 'mock-token';
7580

@@ -81,10 +86,10 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
8186
const result = await service.createLuigiExtendedGlobalContext();
8287

8388
expect(result).toEqual({
84-
organizationId: 'cluster-123/test-org',
89+
organizationId: 'originClusterId/test-org',
8590
kcpCA: 'dW5kZWZpbmVk',
8691
organization: 'test-org',
87-
entityId: 'cluster-123/test-org',
92+
entityId: 'originClusterId/test-org',
8893
});
8994

9095
expect(mockResourceService.readAccountInfo).toHaveBeenCalledWith({

projects/lib/portal-options/services/luigi-extended-global-context-config.service.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,18 @@ export class LuigiExtendedGlobalContextConfigServiceImpl
3333
}),
3434
);
3535

36-
const resourceKcpIoClusterAnnotation =
37-
accountInfo?.metadata?.annotations?.['kcp.io/cluster'];
38-
if (!resourceKcpIoClusterAnnotation) {
39-
console.warn(
40-
`Cluster annotation (kcp.io/cluster) missing for resource: ${entityId}`,
41-
);
36+
const organizationOriginClusterId =
37+
accountInfo?.spec?.organization?.originClusterId;
38+
if (!organizationOriginClusterId) {
39+
console.error(`AccountInfo organization id missing for: ${entityId}`);
4240
return {};
4341
}
4442

4543
return {
4644
organization: entityId,
47-
organizationId: `${resourceKcpIoClusterAnnotation}/${entityId}`,
45+
organizationId: `${organizationOriginClusterId}/${entityId}`,
4846
kcpCA: btoa(accountInfo?.spec?.clusterInfo?.ca),
49-
entityId: `${resourceKcpIoClusterAnnotation}/${entityId}`, // if no entity selected the entityId is the same as the organizationId
47+
entityId: `${organizationOriginClusterId}/${entityId}`, // if no entity selected the entityId is the same as the organizationId
5048
};
5149
} catch (e) {
5250
console.error(`Failed to read entity ${entityId} from ${operation}`, e);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './resource';
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { Condition, ObjectMeta } from 'kubernetes-types/meta/v1';
2+
3+
export interface FieldDefinition {
4+
label?: string;
5+
property: string | string[];
6+
jsonPathExpression?: string;
7+
required?: boolean;
8+
values?: string[];
9+
group?: {
10+
name: string;
11+
label?: string;
12+
deliminator?: string; // default ', '
13+
};
14+
dynamicValuesDefinition?: {
15+
operation: string;
16+
gqlQuery: string;
17+
value: string;
18+
key: string;
19+
};
20+
}
21+
22+
export interface ResourceStatus {
23+
conditions: Condition[];
24+
}
25+
26+
export interface ResourceSpec extends Record<string, any> {
27+
type: string;
28+
description?: string;
29+
displayName?: string;
30+
}
31+
32+
export interface AccountInfo {
33+
metadata: ObjectMeta;
34+
spec: {
35+
clusterInfo: { ca: string };
36+
organization: { originClusterId: string };
37+
};
38+
}
39+
40+
export interface Resource extends Record<string, any> {
41+
metadata: ObjectMeta;
42+
spec?: ResourceSpec;
43+
status?: ResourceStatus;
44+
__typename?: string;
45+
}
46+
47+
export interface ResourceDefinition {
48+
group: string;
49+
plural: string;
50+
singular: string;
51+
kind: string;
52+
scope?: KubernetesScope;
53+
namespace?: string;
54+
ui?: UIDefinition;
55+
}
56+
57+
interface UiView {
58+
fields: FieldDefinition[];
59+
}
60+
61+
export interface UIDefinition {
62+
logoUrl?: string;
63+
listView?: UiView;
64+
createView?: UiView;
65+
detailView?: UiView;
66+
}
67+
68+
export type KubernetesScope = 'Cluster' | 'Namespaced';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './resource';
2+
export * from './models';

projects/lib/services/resource/resource.service.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
1+
import { AccountInfo, Resource, ResourceDefinition } from '../models';
2+
import { ApolloFactory } from './apollo-factory';
3+
import { ResourceNodeContext } from './resource-node-context';
14
import { Injectable, inject } from '@angular/core';
25
import { TypedDocumentNode } from '@apollo/client/core';
6+
import { LuigiCoreService } from '@openmfp/portal-ui-lib';
37
import {
4-
AccountInfo, LuigiCoreService, Resource,
5-
ResourceDefinition,
6-
} from '@openmfp/portal-ui-lib';
7-
import { getValueByPath, replaceDotsAndHyphensWithUnderscores } from '@platform-mesh/portal-ui-lib/utils';
8+
getValueByPath,
9+
replaceDotsAndHyphensWithUnderscores,
10+
} from '@platform-mesh/portal-ui-lib/utils';
811
import { gql } from 'apollo-angular';
912
import * as gqlBuilder from 'gql-query-builder';
1013
import { Observable, of } from 'rxjs';
1114
import { catchError, map } from 'rxjs/operators';
12-
import { ApolloFactory } from './apollo-factory';
13-
import { ResourceNodeContext } from './resource-node-context';
1415

1516
interface ResourceResponseError extends Record<string, any> {
1617
message: string;
1718
}
1819

19-
interface ResourceResponse extends Record<string, any> {
20-
data: {
21-
[key: string]: any;
22-
};
23-
errors: { message: string }[];
24-
}
25-
2620
@Injectable({
2721
providedIn: 'root',
2822
})
@@ -296,6 +290,9 @@ export class ResourceService {
296290
clusterInfo {
297291
ca
298292
}
293+
organization {
294+
originClusterId
295+
}
299296
}
300297
}
301298
}

0 commit comments

Comments
 (0)