From 7495c7ff9a2e26acd1920da3cdee33a4b37c6083 Mon Sep 17 00:00:00 2001 From: reggie Date: Sat, 23 Dec 2023 10:48:49 +0200 Subject: [PATCH] ResourceStatus for resource tree changes Signed-off-by: reggie --- .../application-details.tsx | 5 +++- .../application-resource-tree.tsx | 11 ++++++-- ui/src/app/applications/components/utils.tsx | 25 +++++++++++-------- ui/src/app/shared/models.ts | 1 + .../shared/services/applications-service.ts | 20 ++++++++------- 5 files changed, 39 insertions(+), 23 deletions(-) diff --git a/ui/src/app/applications/components/application-details/application-details.tsx b/ui/src/app/applications/components/application-details/application-details.tsx index 2575403cee653..14f128e690d02 100644 --- a/ui/src/app/applications/components/application-details/application-details.tsx +++ b/ui/src/app/applications/components/application-details/application-details.tsx @@ -956,10 +956,13 @@ export class ApplicationDetails extends React.Component { const fallbackTree = { - nodes: isApp(app) ? (app as models.Application).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})) : [], + nodes: isApp(app) + ? (app as models.Application).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})) + : (app as models.ApplicationSet).status.resources.map(res => ({...res, parentRefs: [], info: [], resourceVersion: '', uid: ''})), orphanedNodes: [], hosts: [] } as appModels.AbstractApplicationTree; + // console.log('*** loadAppInfo' + (app as models.ApplicationSet).status.resources[0].kind); return combineLatest( merge( from([app]), diff --git a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx index 3afbf2a687a7b..bf4b2a30afb0f 100644 --- a/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx +++ b/ui/src/app/applications/components/application-resource-tree/application-resource-tree.tsx @@ -30,7 +30,7 @@ import {NodeUpdateAnimation} from './node-update-animation'; import {PodGroup} from '../application-pod-view/pod-view'; import './application-resource-tree.scss'; import {ArrowConnector} from './arrow-connector'; -import {Application, ApplicationTree} from '../../../shared/models'; +import {Application, ApplicationSet, ApplicationTree} from '../../../shared/models'; function treeNodeKey(node: NodeId & {uid?: string}) { return node.uid || nodeKey(node); @@ -920,6 +920,9 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr const statusByKey = new Map(); if (isApp(props.app)) { (props.app as models.Application).status.resources.forEach(res => statusByKey.set(nodeKey(res), res)); + } else { + // Assuming AppSet. Revisit this if a third type of an AbstractApp is born. + (props.app as models.ApplicationSet).status.resources.forEach(res => statusByKey.set(nodeKey(res), res)); } const nodeByKey = new Map(); props.tree.nodes @@ -1090,7 +1093,11 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr } } else { // Tree view - const managedKeys = isApp(props.app) ? new Set((props.app as Application).status.resources.map(nodeKey)) : new Set(); + + const managedKeys = isApp(props.app) + ? new Set((props.app as Application).status.resources.map(nodeKey)) + : new Set((props.app as ApplicationSet).status.resources.map(nodeKey)); + const orphanedKeys = isApp(props.app) ? new Set((props.tree as ApplicationTree).orphanedNodes?.map(nodeKey)) : new Set(); const orphans: ResourceTreeNode[] = []; let allChildNodes: ResourceTreeNode[] = []; diff --git a/ui/src/app/applications/components/utils.tsx b/ui/src/app/applications/components/utils.tsx index 76b0f8cc4de60..ad6afb7402907 100644 --- a/ui/src/app/applications/components/utils.tsx +++ b/ui/src/app/applications/components/utils.tsx @@ -13,7 +13,7 @@ import {ResourceTreeNode} from './application-resource-tree/application-resource import {CheckboxField, COLORS, ErrorNotification, Revision} from '../../shared/components'; import * as appModels from '../../shared/models'; import {services} from '../../shared/services'; -import {ApplicationSetConditionStatus, ApplicationSetStatus} from '../../shared/models'; +import {ApplicationSetConditionStatus, ApplicationSetStatus, ApplicationTree} from '../../shared/models'; import {History} from 'history'; @@ -32,6 +32,7 @@ export interface NodeId { type ActionMenuItem = MenuItem & {disabled?: boolean; tooltip?: string}; export function nodeKey(node: NodeId) { + console.log('nodeKEy ' + [node.group, node.kind, node.namespace, node.name].join('/')); return [node.group, node.kind, node.namespace, node.name].join('/'); } @@ -437,8 +438,8 @@ function getResourceActionsMenuItems(resource: ResourceTreeNode, metadata: model function getActionItems( resource: ResourceTreeNode, - application: appModels.Application, - tree: appModels.ApplicationTree, + application: appModels.AbstractApplication, + tree: appModels.AbstractApplicationTree, apis: ContextApis, history: History, appChanged: BehaviorSubject, @@ -470,12 +471,14 @@ function getActionItems( }); } - if (findChildPod(resource, tree)) { - items.push({ - title: 'Logs', - iconClassName: 'fa fa-fw fa-align-left', - action: () => apis.navigation.goto('.', {node: nodeKey(resource), tab: 'logs'}, {replace: true}) - }); + if (isApp(application)) { + if (findChildPod(resource, tree as ApplicationTree)) { + items.push({ + title: 'Logs', + iconClassName: 'fa fa-fw fa-align-left', + action: () => apis.navigation.goto('.', {node: nodeKey(resource), tab: 'logs'}, {replace: true}) + }); + } } if (isQuickStart) { @@ -526,8 +529,8 @@ function getActionItems( export function renderResourceMenu( resource: ResourceTreeNode, - application: appModels.Application, - tree: appModels.ApplicationTree, + application: appModels.AbstractApplication, + tree: appModels.AbstractApplicationTree, apis: ContextApis, history: History, appChanged: BehaviorSubject, diff --git a/ui/src/app/shared/models.ts b/ui/src/app/shared/models.ts index a5f039b50c640..0278eb211f7be 100644 --- a/ui/src/app/shared/models.ts +++ b/ui/src/app/shared/models.ts @@ -337,6 +337,7 @@ export interface ApplicationPreservedFields { export interface ApplicationSetStatus { conditions?: ApplicationSetCondition[]; applicationStatus: ApplicationSetApplicationStatus[]; + resources: ResourceStatus[]; } export interface ApplicationSetCondition { diff --git a/ui/src/app/shared/services/applications-service.ts b/ui/src/app/shared/services/applications-service.ts index e2e7a5388c50f..5e7f5668624a2 100644 --- a/ui/src/app/shared/services/applications-service.ts +++ b/ui/src/app/shared/services/applications-service.ts @@ -95,14 +95,11 @@ export class ApplicationsService { } public resourceTree(name: string, appNamespace: string, pathname: string): Promise { - // const isFromApps = isInvokedFromAppsPath(pathname); - return ( - requests - .get(`${getRootPathByPath(pathname)}/${name}/resource-tree`) - .query({appNamespace}) - // .then(isFromApps ? res => res.body as models.ApplicationTree : res => res.body as models.ApplicationSetTree); - .then(res => res.body as models.AbstractApplicationTree) - ); + return requests + .get(`${getRootPathByPath(pathname)}/${name}/resource-tree`) + .query({appNamespace}) + + .then(res => res.body as models.AbstractApplicationTree); } public watchResourceTree(name: string, appNamespace: string, pathname: string): Observable { @@ -554,10 +551,15 @@ export class ApplicationsService { data = deepMerge( { apiVersion: 'argoproj.io/v1alpha1', - kind: 'ApplicationSet' + kind: 'ApplicationSet', + status: { + resources: [] + } }, data ); + (data as models.ApplicationSet).status.resources[0].kind = 'Application'; + (data as models.ApplicationSet).status.resources[0].group = 'argoproj.io'; return data as models.ApplicationSet; } }