diff --git a/package-lock.json b/package-lock.json index c24c281..6cb2c78 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,6 +31,7 @@ "jest-junit": "16.0.0", "jest-mock-extended": "3.0.7", "jmespath": "0.16.0", + "kubernetes-types": "^1.30.0", "mkdirp": "^3.0.1", "move-cli": "^2.0.0", "ng-packagr": "^20.2.0", @@ -17309,6 +17310,13 @@ "node": ">=6" } }, + "node_modules/kubernetes-types": { + "version": "1.30.0", + "resolved": "https://registry.npmjs.org/kubernetes-types/-/kubernetes-types-1.30.0.tgz", + "integrity": "sha512-Dew1okvhM/SQcIa2rcgujNndZwU8VnSapDgdxlYoB84ZlpAD43U6KLAFqYo17ykSFGHNPrg0qry0bP+GJd9v7Q==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/launch-editor": { "version": "2.11.1", "resolved": "https://registry.npmjs.org/launch-editor/-/launch-editor-2.11.1.tgz", diff --git a/package.json b/package.json index 6d7bbef..da7e986 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "@types/jmespath": "0.15.2", "@types/jsonpath": "^0.2.4", "@ui5/webcomponents-ngx": "^0.5.0", + "kubernetes-types": "^1.30.0", "cpx2": "^8.0.0", "jest": "^29.7.0", "jest-jasmine2": "29.7.0", diff --git a/projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts b/projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts index e9980f3..e75670c 100644 --- a/projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts +++ b/projects/lib/portal-options/services/luigi-extended-global-context-config.service.spec.ts @@ -70,6 +70,11 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => { 'kcp.io/cluster': 'cluster-123', }, }, + spec: { + organization: { + originClusterId: 'originClusterId', + }, + }, } as any; const mockToken = 'mock-token'; @@ -81,10 +86,10 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => { const result = await service.createLuigiExtendedGlobalContext(); expect(result).toEqual({ - organizationId: 'cluster-123/test-org', + organizationId: 'originClusterId/test-org', kcpCA: 'dW5kZWZpbmVk', organization: 'test-org', - entityId: 'cluster-123/test-org', + entityId: 'originClusterId/test-org', }); expect(mockResourceService.readAccountInfo).toHaveBeenCalledWith({ diff --git a/projects/lib/portal-options/services/luigi-extended-global-context-config.service.ts b/projects/lib/portal-options/services/luigi-extended-global-context-config.service.ts index 5bccf0f..766815c 100644 --- a/projects/lib/portal-options/services/luigi-extended-global-context-config.service.ts +++ b/projects/lib/portal-options/services/luigi-extended-global-context-config.service.ts @@ -33,20 +33,18 @@ export class LuigiExtendedGlobalContextConfigServiceImpl }), ); - const resourceKcpIoClusterAnnotation = - accountInfo?.metadata?.annotations?.['kcp.io/cluster']; - if (!resourceKcpIoClusterAnnotation) { - console.warn( - `Cluster annotation (kcp.io/cluster) missing for resource: ${entityId}`, - ); + const organizationOriginClusterId = + accountInfo?.spec?.organization?.originClusterId; + if (!organizationOriginClusterId) { + console.error(`AccountInfo organization id missing for: ${entityId}`); return {}; } return { organization: entityId, - organizationId: `${resourceKcpIoClusterAnnotation}/${entityId}`, + organizationId: `${organizationOriginClusterId}/${entityId}`, kcpCA: btoa(accountInfo?.spec?.clusterInfo?.ca), - entityId: `${resourceKcpIoClusterAnnotation}/${entityId}`, // if no entity selected the entityId is the same as the organizationId + entityId: `${organizationOriginClusterId}/${entityId}`, // if no entity selected the entityId is the same as the organizationId }; } catch (e) { console.error(`Failed to read entity ${entityId} from ${operation}`, e); diff --git a/projects/lib/services/models/index.ts b/projects/lib/services/models/index.ts new file mode 100644 index 0000000..c1cb5de --- /dev/null +++ b/projects/lib/services/models/index.ts @@ -0,0 +1 @@ +export * from './resource'; diff --git a/projects/lib/services/models/resource.ts b/projects/lib/services/models/resource.ts new file mode 100644 index 0000000..2fbc166 --- /dev/null +++ b/projects/lib/services/models/resource.ts @@ -0,0 +1,68 @@ +import { Condition, ObjectMeta } from 'kubernetes-types/meta/v1'; + +export interface FieldDefinition { + label?: string; + property: string | string[]; + jsonPathExpression?: string; + required?: boolean; + values?: string[]; + group?: { + name: string; + label?: string; + deliminator?: string; // default ', ' + }; + dynamicValuesDefinition?: { + operation: string; + gqlQuery: string; + value: string; + key: string; + }; +} + +export interface ResourceStatus { + conditions: Condition[]; +} + +export interface ResourceSpec extends Record { + type: string; + description?: string; + displayName?: string; +} + +export interface AccountInfo { + metadata: ObjectMeta; + spec: { + clusterInfo: { ca: string }; + organization: { originClusterId: string }; + }; +} + +export interface Resource extends Record { + metadata: ObjectMeta; + spec?: ResourceSpec; + status?: ResourceStatus; + __typename?: string; +} + +export interface ResourceDefinition { + group: string; + plural: string; + singular: string; + kind: string; + scope?: KubernetesScope; + namespace?: string; + ui?: UIDefinition; +} + +interface UiView { + fields: FieldDefinition[]; +} + +export interface UIDefinition { + logoUrl?: string; + listView?: UiView; + createView?: UiView; + detailView?: UiView; +} + +export type KubernetesScope = 'Cluster' | 'Namespaced'; diff --git a/projects/lib/services/public-api.ts b/projects/lib/services/public-api.ts index c1cb5de..d2bba87 100644 --- a/projects/lib/services/public-api.ts +++ b/projects/lib/services/public-api.ts @@ -1 +1,2 @@ export * from './resource'; +export * from './models'; diff --git a/projects/lib/services/resource/resource.service.ts b/projects/lib/services/resource/resource.service.ts index eb2b82c..ef42143 100644 --- a/projects/lib/services/resource/resource.service.ts +++ b/projects/lib/services/resource/resource.service.ts @@ -1,28 +1,22 @@ +import { AccountInfo, Resource, ResourceDefinition } from '../models'; +import { ApolloFactory } from './apollo-factory'; +import { ResourceNodeContext } from './resource-node-context'; import { Injectable, inject } from '@angular/core'; import { TypedDocumentNode } from '@apollo/client/core'; +import { LuigiCoreService } from '@openmfp/portal-ui-lib'; import { - AccountInfo, LuigiCoreService, Resource, - ResourceDefinition, -} from '@openmfp/portal-ui-lib'; -import { getValueByPath, replaceDotsAndHyphensWithUnderscores } from '@platform-mesh/portal-ui-lib/utils'; + getValueByPath, + replaceDotsAndHyphensWithUnderscores, +} from '@platform-mesh/portal-ui-lib/utils'; import { gql } from 'apollo-angular'; import * as gqlBuilder from 'gql-query-builder'; import { Observable, of } from 'rxjs'; import { catchError, map } from 'rxjs/operators'; -import { ApolloFactory } from './apollo-factory'; -import { ResourceNodeContext } from './resource-node-context'; interface ResourceResponseError extends Record { message: string; } -interface ResourceResponse extends Record { - data: { - [key: string]: any; - }; - errors: { message: string }[]; -} - @Injectable({ providedIn: 'root', }) @@ -296,6 +290,9 @@ export class ResourceService { clusterInfo { ca } + organization { + originClusterId + } } } }