Skip to content

Commit

Permalink
bug: add exec check to avoid API calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutosh16 committed Oct 30, 2023
1 parent d429013 commit 6a613e0
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
tabs: Tab[],
execEnabled: boolean,
execAllowed: boolean,
logsAllowed: boolean
logsAllowed: boolean,
) => {
if (!node || node === undefined) {
return [];
Expand All @@ -66,22 +66,22 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
<div className='application-resource-events'>
<EventsList events={events} />
</div>
)
),
});
}
if (podState && podState.metadata && podState.spec) {
const containerGroups = [
{
offset: 0,
title: 'CONTAINERS',
containers: podState.spec.containers || []
}
containers: podState.spec.containers || [],
},
];
if (podState.spec.initContainers?.length > 0) {
containerGroups.push({
offset: (podState.spec.containers || []).length,
title: 'INIT CONTAINERS',
containers: podState.spec.initContainers || []
containers: podState.spec.initContainers || [],
});
}

Expand Down Expand Up @@ -111,8 +111,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
onClickContainer={onClickContainer}
/>
</div>
)
}
),
},
]);
}
if (selectedNode.kind === 'Pod' && execEnabled && execAllowed) {
Expand All @@ -131,8 +131,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
containerName={AppUtils.getContainerName(podState, activeContainer)}
onClickContainer={onClickContainer}
/>
)
}
),
},
]);
}
}
Expand All @@ -146,7 +146,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
<tabExtensions.component tree={tree} resource={state} application={application} />
</ErrorBoundary>
),
icon: tabExtensions.icon
icon: tabExtensions.icon,
});
});
}
Expand All @@ -158,7 +158,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
{
title: 'SUMMARY',
key: 'summary',
content: <ApplicationSummary app={application} updateApp={(app, query: {validate?: boolean}) => updateApp(app, query)} />
content: <ApplicationSummary app={application} updateApp={(app, query: {validate?: boolean}) => updateApp(app, query)} />,
},
{
title: 'PARAMETERS',
Expand All @@ -170,7 +170,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
load={app =>
services.repos.appDetails(AppUtils.getAppDefaultSource(app), app.metadata.name, app.spec.project).catch(() => ({
type: 'Directory' as AppSourceType,
path: AppUtils.getAppDefaultSource(app).path
path: AppUtils.getAppDefaultSource(app).path,
}))
}>
{(details: RepoAppDetails) => (
Expand All @@ -181,7 +181,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
/>
)}
</DataLoader>
)
),
},
{
title: 'MANIFEST',
Expand All @@ -195,8 +195,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
return services.applications.updateSpec(application.metadata.name, application.metadata.namespace, jsonMergePatch.apply(spec, JSON.parse(patch)));
}}
/>
)
}
),
},
];

if (application.status.sync.status !== SyncStatuses.Synced) {
Expand All @@ -209,26 +209,26 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
key='diff'
load={async () =>
await services.applications.managedResources(application.metadata.name, application.metadata.namespace, {
fields: ['items.normalizedLiveState', 'items.predictedLiveState', 'items.group', 'items.kind', 'items.namespace', 'items.name']
fields: ['items.normalizedLiveState', 'items.predictedLiveState', 'items.group', 'items.kind', 'items.namespace', 'items.name'],
})
}>
{managedResources => <ApplicationResourcesDiff states={managedResources} />}
</DataLoader>
)
),
});
}

tabs.push({
title: 'EVENTS',
key: 'event',
content: <ApplicationResourceEvents applicationName={application.metadata.name} applicationNamespace={application.metadata.namespace} />
content: <ApplicationResourceEvents applicationName={application.metadata.name} applicationNamespace={application.metadata.namespace} />,
});

const extensionTabs = services.extensions.getResourceTabs('argoproj.io', 'Application').map((ext, i) => ({
title: ext.title,
key: `extension-${i}`,
content: <ext.component resource={application} tree={tree} application={application} />,
icon: ext.icon
icon: ext.icon,
}));

return tabs.concat(extensionTabs);
Expand All @@ -248,8 +248,8 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
name: selectedNode.name,
namespace: selectedNode.namespace,
kind: selectedNode.kind,
group: selectedNode.group
}
group: selectedNode.group,
},
});
const controlled = managedResources.find(item => AppUtils.isSameNode(selectedNode, item));
const summary = application.status.resources.find(item => AppUtils.isSameNode(selectedNode, item));
Expand All @@ -264,7 +264,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
(await services.applications.resourceEvents(application.metadata.name, application.metadata.namespace, {
name: liveState.metadata.name,
namespace: liveState.metadata.namespace,
uid: liveState.metadata.uid
uid: liveState.metadata.uid,
}))) ||
[];
let podState: State;
Expand All @@ -280,7 +280,7 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
const settings = await services.authService.settings();
const execEnabled = settings.execEnabled;
const logsAllowed = await services.accounts.canI('logs', 'get', application.spec.project + '/' + application.metadata.name);
const execAllowed = await services.accounts.canI('exec', 'create', application.spec.project + '/' + application.metadata.name);
const execAllowed = settings.execEnabled && (await services.accounts.canI('exec', 'create', application.spec.project + '/' + application.metadata.name));
const links = await services.applications.getResourceLinks(application.metadata.name, application.metadata.namespace, selectedNode).catch(() => null);
return {controlledState, liveState, events, podState, execEnabled, execAllowed, logsAllowed, links};
}}>
Expand Down Expand Up @@ -343,12 +343,12 @@ export const ResourceDetails = (props: ResourceDetailsProps) => {
node={selectedNode}
links={data.links}
/>
)
}
),
},
],
data.execEnabled,
data.execAllowed,
data.logsAllowed
data.logsAllowed,
)}
selectedTabKey={props.tab}
onTabSelected={selected => appContext.navigation.goto('.', {tab: selected}, {replace: true})}
Expand Down
Loading

0 comments on commit 6a613e0

Please sign in to comment.