Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ describe('LuigiExtendedGlobalContextConfigServiceImpl', () => {
'kcp.io/cluster': 'cluster-123',
},
},
spec: {
organization: {
originClusterId: 'originClusterId',
},
},
} as any;
const mockToken = 'mock-token';

Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions projects/lib/services/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './resource';
68 changes: 68 additions & 0 deletions projects/lib/services/models/resource.ts
Original file line number Diff line number Diff line change
@@ -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<string, any> {
type: string;
description?: string;
displayName?: string;
}

export interface AccountInfo {
metadata: ObjectMeta;
spec: {
clusterInfo: { ca: string };
organization: { originClusterId: string };
};
}

export interface Resource extends Record<string, any> {
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';
1 change: 1 addition & 0 deletions projects/lib/services/public-api.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './resource';
export * from './models';
23 changes: 10 additions & 13 deletions projects/lib/services/resource/resource.service.ts
Original file line number Diff line number Diff line change
@@ -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<string, any> {
message: string;
}

interface ResourceResponse extends Record<string, any> {
data: {
[key: string]: any;
};
errors: { message: string }[];
}

@Injectable({
providedIn: 'root',
})
Expand Down Expand Up @@ -296,6 +290,9 @@ export class ResourceService {
clusterInfo {
ca
}
organization {
originClusterId
}
}
}
}
Expand Down