Skip to content

Commit

Permalink
Show Application action to take user to it's explorer deployment deta…
Browse files Browse the repository at this point in the history
…il page
  • Loading branch information
richard-cox committed Nov 20, 2023
1 parent 5276c4e commit 64c9f1d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 14 deletions.
2 changes: 2 additions & 0 deletions dashboard/pkg/epinio/l10n/en-us.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ epinio:
label: Redeploy
goToEpinio:
label: Epinio App
viewDeployment:
label: View In Kube Cluster
wm:
containerName: 'Instance: {label}'
noData: There are no log entries to show.
Expand Down
70 changes: 63 additions & 7 deletions dashboard/pkg/epinio/models/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
import { createEpinioRoute } from '../utils/custom-routing';
import EpinioNamespacedResource, { bulkRemove } from './epinio-namespaced-resource';
import { AppUtils } from '../utils/application';
import { WORKLOAD_TYPES } from '@shell/config/types';
import { NAME as EXPLORER } from '@shell/config/product/explorer';

// See https://github.com/epinio/epinio/blob/00684bc36780a37ab90091498e5c700337015a96/pkg/api/core/v1/models/app.go#L11
const STATES = {
Expand Down Expand Up @@ -106,7 +108,7 @@ export default class EpinioApplicationModel extends EpinioNamespacedResource {
res.push({
action: 'showAppShell',
label: this.t('epinio.applications.actions.shell.label'),
icon: 'icon icon-fw icon-chevron-right',
icon: 'icon icon-fw icon-terminal',
enabled: showAppShell,
});
}
Expand All @@ -125,10 +127,6 @@ export default class EpinioApplicationModel extends EpinioNamespacedResource {
},
);

if (showAppShell || showAppLog || showStagingLog) {
res.push({ divider: true });
}

res.push( {
action: 'restage',
label: this.t('epinio.applications.actions.restage.label'),
Expand All @@ -141,16 +139,28 @@ export default class EpinioApplicationModel extends EpinioNamespacedResource {
icon: 'icon icon-fw icon-refresh',
enabled: isRunning
},
{ divider: true },
{
action: 'exportApp',
label: this.t('epinio.applications.export.label'),
icon: 'icon icon-fw icon-download',
enabled: isRunning
},
{ divider: true },
);

...super._availableActions);
if (this.canViewDeployment) {
res.push({
action: 'viewDeployment',
label: this.t('epinio.applications.actions.viewDeployment.label'),
icon: 'icon icon-fw icon-chevron-right',
},
{ divider: true },
);
}

res.push(
...super._availableActions
);

return res;
}
Expand Down Expand Up @@ -448,6 +458,52 @@ export default class EpinioApplicationModel extends EpinioNamespacedResource {
return 'export';
}

get canViewDeployment() {
return !this.$rootGetters['isSingleProduct'] && !!this.$getters[`schemaFor`](WORKLOAD_TYPES.DEPLOYMENT);
}

/**
* Attempt to view the deployment for this namespace in Rancher's UI
*
* If we can't find the deployment, just go to the deployment list with the name in the filter
*/
viewDeployment() {
const clusterId = this.$rootGetters['clusterId'];
const namespace = this.metadata.namespace;
const appName = this.metadata.name;
const url = `/k8s/clusters/${ clusterId }/v1/apps.deployments/${ namespace }?labelSelector=app.kubernetes.io/component%3Dapplication,app.kubernetes.io/name%3D${ appName }`;

const deploymentList = {
name: `c-cluster-product-resource`,
params: {
product: EXPLORER,
cluster: clusterId,
resource: WORKLOAD_TYPES.DEPLOYMENT,
},
query: { q: this.metadata.name }
};

this.$dispatch(`cluster/request`, { url }, { root: true })
.then((deployments) => {
if (deployments?.data?.length === 1) {
const deployment = deployments.data[0];

this.currentRouter().push({
name: `c-cluster-product-resource-namespace-id`,
params: {
...deploymentList.params,
namespace: deployment.metadata.namespace,
id: deployment.metadata.name,
}
});
} else {
this.currentRouter().push(deploymentList);
}
}).catch(() => {
this.currentRouter().push(deploymentList);
});
}

// ------------------------------------------------------------------
// Change/handle changes of the app

Expand Down
20 changes: 13 additions & 7 deletions dashboard/pkg/epinio/store/epinio-store/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { METRIC, SCHEMA } from '@shell/config/types';
import { METRIC, SCHEMA, WORKLOAD, WORKLOAD_TYPES } from '@shell/config/types';

Check warning on line 1 in dashboard/pkg/epinio/store/epinio-store/actions.ts

View workflow job for this annotation

GitHub Actions / lint

'WORKLOAD' is defined but never used
import { handleSpoofedRequest } from '@shell/plugins/dashboard-store/actions';
import { classify } from '@shell/plugins/dashboard-store/classify';
import { normalizeType } from '@shell/plugins/dashboard-store/normalize';
Expand All @@ -12,6 +12,7 @@ import {
} from '../../types';
import EpinioCluster from '../../models/cluster';
import { RedirectToError } from '@shell/utils/error';
import { allHash, allHashSettled } from '@shell/utils/promise';

Check warning on line 15 in dashboard/pkg/epinio/store/epinio-store/actions.ts

View workflow job for this annotation

GitHub Actions / lint

'allHash' is defined but never used

const createId = (schema: any, resource: any) => {
const name = resource.meta?.name || resource.name;
Expand Down Expand Up @@ -243,13 +244,18 @@ export default {

if (!isSingleProduct) {
try {
const nodeMetricsSchema = await dispatch(`cluster/request`, { url: `/k8s/clusters/${ clusterId }/v1/schemas/${ METRIC.NODE }` }, { root: true });

if (nodeMetricsSchema) {
data.push(nodeMetricsSchema);
}
const schemas = await allHashSettled({
nodeMetrics: dispatch(`cluster/request`, { url: `/k8s/clusters/${ clusterId }/v1/schemas/${ METRIC.NODE }` }, { root: true }),
deployments: dispatch(`cluster/request`, { url: `/k8s/clusters/${ clusterId }/v1/schemas/${ WORKLOAD_TYPES.DEPLOYMENT }` }, { root: true })
});

Object.values(schemas).forEach((res: any ) => {
if (res.value) {
data.push(res.value);
}
});
} catch (e) {
console.warn(`Unable to fetch Node metrics schema for epinio cluster: ${ clusterId }`);// eslint-disable-line no-console
console.debug(`Unable to fetch schema/s for epinio cluster: ${ clusterId }`, e);// eslint-disable-line no-console
}
}

Expand Down

0 comments on commit 64c9f1d

Please sign in to comment.