Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add link buttons from dashboard deployment to epinio app #276

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can only link from a deployment, pod, or a workload if it is a deployment or pod.

we might be able to do service as well, which goes to a service instance

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will disable services for the moment, even if we could put the link from a service bounded to an application to the application view on Epinio.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'batch.job' can be removed as well

'batch.job',
'pod',
// 'service',
'workload'
]
},
{
labelKey: 'epinio.applications.actions.goToEpinio.label',
icon: 'icon-epinio',
enabled(ctx: any) {
const isUserNamespace = ctx.metadata.namespace !== 'epinio';
richard-cox marked this conversation as resolved.
Show resolved Hide resolved

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't spot this before. This should be labelled Epinio App, possibly Epinio Details? Either way, think it should be clearer where the user ends up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of Epinio App. Epinio Details i think is too long.

wm:
containerName: 'Instance: {label}'
noData: There are no log entries to show.
Expand Down
1 change: 1 addition & 0 deletions dashboard/pkg/epinio/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export interface EpinioHelmRepoResource {
export interface EpinioCatalogServiceResource {
id: string,
description: string,
shortId: string,
short_description: string, // eslint-disable-line camelcase
chart: string,
chartVersion: string,
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
Loading