Skip to content

Commit

Permalink
ResourceStatus for resource tree changes
Browse files Browse the repository at this point in the history
Signed-off-by: reggie <[email protected]>
  • Loading branch information
reggie-k committed Dec 23, 2023
1 parent b3984e5 commit 7495c7f
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,13 @@ export class ApplicationDetails extends React.Component<RouteComponentProps<{app
.pipe(
mergeMap(app => {
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]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -920,6 +920,9 @@ export const ApplicationResourceTree = (props: AbstractApplicationResourceTreePr
const statusByKey = new Map<string, models.ResourceStatus>();
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<string, ResourceTreeNode>();
props.tree.nodes
Expand Down Expand Up @@ -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[] = [];
Expand Down
25 changes: 14 additions & 11 deletions ui/src/app/applications/components/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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('/');
}

Expand Down Expand Up @@ -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<unknown>,
appChanged: BehaviorSubject<appModels.AbstractApplication>,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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<unknown>,
appChanged: BehaviorSubject<appModels.AbstractApplication>,
Expand Down
1 change: 1 addition & 0 deletions ui/src/app/shared/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ export interface ApplicationPreservedFields {
export interface ApplicationSetStatus {
conditions?: ApplicationSetCondition[];
applicationStatus: ApplicationSetApplicationStatus[];
resources: ResourceStatus[];
}

export interface ApplicationSetCondition {
Expand Down
20 changes: 11 additions & 9 deletions ui/src/app/shared/services/applications-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,11 @@ export class ApplicationsService {
}

public resourceTree(name: string, appNamespace: string, pathname: string): Promise<models.AbstractApplicationTree> {
// 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<models.ApplicationTree> {
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 7495c7f

Please sign in to comment.