Skip to content

Commit

Permalink
Add link on pods and Jobs, from Epinio clusters in Rancher dashboard …
Browse files Browse the repository at this point in the history
…to Epinio dashboard

Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed Aug 10, 2023
1 parent 3b67ca8 commit 8203ca1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
49 changes: 48 additions & 1 deletion dashboard/pkg/epinio/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { importTypes } from '@rancher/auto-import';
import { IPlugin, OnNavAwayFromPackage, OnNavToPackage } from '@shell/core/types';
import {
ActionLocation, ActionOpts, IPlugin, OnNavAwayFromPackage, OnNavToPackage
} from '@shell/core/types';
import { EPINIO_TYPES } from './types';
import epinioRoutes from './routing/epinio-routing';
import epinioMgmtStore from './store/epinio-mgmt-store';
import epinioStore from './store/epinio-store';
import { createEpinioRoute } from './utils/custom-routing';

const epinioObjAnnotations = [
'epinio.io/app-container',
'epinio.io/created-by'
];

const isPodFromEpinio = (a: string) => epinioObjAnnotations.includes(a);

const onEnter: OnNavToPackage = async({ getters, dispatch }, config) => {
await dispatch(`${ epinioMgmtStore.config.namespace }/loadManagement`);
Expand Down Expand Up @@ -41,4 +52,40 @@ export default function(plugin: IPlugin) {

// Add hooks to Vue navigation world
plugin.addNavHooks(onEnter, onLeave);

// Add action button in the menu of each object belonging to Epinio's applications
plugin.addAction(
ActionLocation.TABLE,
{
resource: [
'apps.deployment',
'batch.job',
'pod',
// 'service',
'workload'
]
},
{
labelKey: 'epinio.applications.actions.goToEpinio.label',
icon: 'icon-epinio',
enabled(ctx: any) {
const isUserNamespace = ctx.metadata.namespace !== 'epinio';

return isUserNamespace && !!Object.keys(ctx.metadata.annotations || []).find((annotation) => isPodFromEpinio(annotation));
},
invoke(_: ActionOpts, values: any[]) {
const obj = values[0];
const $router = obj.$rootState.$router;

const epinioNamespace = obj.labels['app.kubernetes.io/part-of'];
const epinioAppName = obj.labels['app.kubernetes.io/name'];

$router.replace(createEpinioRoute(`c-cluster-resource-id`, {
cluster: obj.$rootGetters['clusterId'],
resource: EPINIO_TYPES.APP,
id: `${ epinioNamespace }/${ epinioAppName }`
}));
}
}
);
}
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 @@ -284,6 +284,8 @@ epinio:
label: Download Manifest
editFromCommit:
label: Redeploy
goToEpinio:
label: App Details
wm:
containerName: 'Instance: {label}'
noData: There are no log entries to show.
Expand Down
6 changes: 5 additions & 1 deletion dashboard/pkg/epinio/utils/epinio-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { ingressFullPath } from '@shell/models/networking.k8s.io.ingress';
import { allHash } from '@shell/utils/promise';

export default {
ingressUrl(clusterId: string) {
return `/k8s/clusters/${ clusterId }/v1/networking.k8s.io.ingresses/epinio/epinio`;
},

async discover(store: any) {
const allClusters = await store.dispatch('management/findAll', { type: MANAGEMENT.CLUSTER }, { root: true });
const epinioClusters = [];

for (const c of allClusters.filter((c: any) => c.isReady)) {
try {
// Get the url first, if it has this it's highly likely it's an epinio cluster
const epinioIngress = await store.dispatch(`cluster/request`, { url: `/k8s/clusters/${ c.id }/v1/networking.k8s.io.ingresses/epinio/epinio` }, { root: true });
const epinioIngress = await store.dispatch(`cluster/request`, { url: this.ingressUrl(c.id) }, { root: true });
const url = ingressFullPath(epinioIngress, epinioIngress.spec.rules?.[0]);

let username;
Expand Down

0 comments on commit 8203ca1

Please sign in to comment.