Making harvester-manager load as an external extension

This commit is contained in:
Cody Jackson 2024-09-12 10:25:06 -07:00 committed by Francesco Torchia
parent aba9c167e0
commit 40432c8261
No known key found for this signature in database
GPG Key ID: E6D011B7415D4393
18 changed files with 1163 additions and 5126 deletions

View File

@ -6,24 +6,14 @@
"node": ">=20.0.0"
},
"dependencies": {
"@rancher/components": "0.3.0-alpha.1",
"@rancher/shell": "2.0.0",
"@vue/cli-plugin-babel": "5.0.8",
"@vue/cli-plugin-typescript": "5.0.8",
"@vue/cli-service": "5.0.8",
"@rancher/shell": "^3.0.0-rc.1",
"cache-loader": "^4.1.0",
"codemirror": ">=5.64.0 <6",
"codemirror-editor-vue3": "^2.7.0",
"core-js": "3.25.3",
"css-loader": "4.3.0",
"diff_match_patch": "^0.1.1",
"node-polyfill-webpack-plugin": "^3.0.0",
"yaml": "2.0.0"
"color": "4.2.3",
"ip": "2.0.1",
"node-polyfill-webpack-plugin": "^3.0.0"
},
"resolutions": {
"@vue/cli-plugin-babel": "5.0.8",
"@vue/cli-service": "5.0.8",
"@vue/cli-plugin-typescript": "5.0.8",
"@types/node": "~20.10.0",
"d3-color": "3.1.0",
"ejs": "3.1.9",
"follow-redirects": "1.15.2",
@ -45,17 +35,7 @@
"clean": "./node_modules/@rancher/shell/scripts/clean",
"build-pkg": "./node_modules/@rancher/shell/scripts/build-pkg.sh",
"serve-pkgs": "./node_modules/@rancher/shell/scripts/serve-pkgs",
"vue-migrate": "scripts/vue-migrate.js",
"publish-pkgs": "./node_modules/@rancher/shell/scripts/extension/publish",
"parse-tag-name": "./node_modules/@rancher/shell/scripts/extension/parse-tag-name",
"lint": "./node_modules/.bin/eslint --max-warnings 0 --ext .js,.ts,.vue .",
"test": "jest --watch",
"migrate": "node ./vue-migrate.js"
},
"devDependencies": {
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.5",
"@vue/vue3-jest": "^27.0.0-alpha.1",
"babel-plugin-transform-require-context": "^0.1.1"
"parse-tag-name": "./node_modules/@rancher/shell/scripts/extension/parse-tag-name"
}
}

View File

@ -122,7 +122,7 @@ export default {
</div>
<div class="mt-10">
<Tag
v-for="((tag), i) in value" :key="i" class="tag"
v-for="(tag, i) in value" :key="i" class="tag"
>
<span>
{{ tag }}
@ -155,7 +155,7 @@ export default {
>
<input
ref="addTagInput"
v-model:value="inputValue"
v-model="inputValue"
type="text"
size="small"
@blur="confirmAdd"

View File

@ -0,0 +1,114 @@
import { HCI, MANAGEMENT, CAPI } from '@shell/config/types';
import { HARVESTER, MULTI_CLUSTER } from '@shell/store/features';
import { STATE, NAME as NAME_COL, AGE, VERSION } from '@shell/config/table-headers';
import { allHash } from '@shell/utils/promise';
import { BLANK_CLUSTER } from '@shell/store/store-types.js';
export const PRODUCT_NAME = 'harvester-manager';
export const NAME = 'harvesterManager';
const MACHINE_POOLS = {
name: 'summary',
labelKey: 'tableHeaders.machines',
sort: false,
search: false,
value: 'nodes.length',
align: 'center',
width: 100,
};
const harvesterClustersLocation = {
name: 'c-cluster-product-resource',
params: {
cluster: BLANK_CLUSTER,
product: NAME,
resource: HCI.CLUSTER
}
};
export function init($plugin, store) {
const {
product,
basicType,
headers,
spoofedType,
configureType
} = $plugin.DSL(store, NAME);
product({
ifHaveType: CAPI.RANCHER_CLUSTER,
ifFeature: [MULTI_CLUSTER, HARVESTER],
inStore: 'management',
icon: 'harvester',
removable: false,
showClusterSwitcher: false,
weight: 100,
to: harvesterClustersLocation,
category: 'hci',
});
configureType(HCI.CLUSTER, { showListMasthead: false });
headers(HCI.CLUSTER, [
STATE,
NAME_COL,
{
...VERSION,
value: 'kubernetesVersion',
getValue: (row) => row.kubernetesVersion
},
MACHINE_POOLS,
AGE,
{
name: 'harvester',
label: ' ',
align: 'right',
width: 65,
},
]);
basicType([HCI.CLUSTER]);
spoofedType({
labelKey: 'harvesterManager.cluster.label',
name: HCI.CLUSTER,
type: HCI.CLUSTER,
namespaced: false,
weight: -1,
route: {
name: 'c-cluster-product-resource',
params: {
product: NAME,
resource: HCI.CLUSTER,
}
},
exact: false,
schemas: [
{
id: HCI.CLUSTER,
type: 'schema',
collectionMethods: [],
resourceFields: {},
attributes: { namespaced: true },
},
],
group: 'Root',
getInstances: async() => {
const hash = {
rancherClusters: store.dispatch('management/findAll', { type: CAPI.RANCHER_CLUSTER }),
clusters: store.dispatch('management/findAll', { type: MANAGEMENT.CLUSTER }),
};
if (store.getters['management/schemaFor'](MANAGEMENT.NODE)) {
hash.nodes = store.dispatch('management/findAll', { type: MANAGEMENT.NODE });
}
const res = await allHash(hash);
return res.rancherClusters.map((c) => {
return {
...c,
type: HCI.CLUSTER,
};
});
},
});
}

22
pkg/harvester/icon.svg Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;" xml:space="preserve">
<g id="icomoon-ignore">
</g>
<path d="M23,12.5c0,0,0-0.1,0-0.1c0,0,0,0,0,0c0-0.1,0-0.2,0-0.2c0,0,0,0,0,0c0,0,0-0.1,0-0.1c0,0,0,0,0,0c0,0,0,0,0-0.1l-2.6-4.5
c0,0,0,0,0-0.1c0,0,0,0,0,0c0,0,0-0.1-0.1-0.1c0,0,0,0,0,0c0,0-0.1,0-0.1-0.1l0,0l0,0c0,0-0.1,0-0.1,0c0,0,0,0,0,0c0,0-0.1,0-0.1,0
c0,0,0,0,0,0c0,0,0,0-0.1,0h-5.2c0,0,0,0-0.1,0c0,0,0,0,0,0c0,0-0.1,0-0.1,0c0,0,0,0,0,0c0,0-0.1,0-0.1,0l0,0l0,0c0,0-0.1,0-0.1,0.1
c0,0,0,0,0,0c0,0-0.1,0.1-0.1,0.1c0,0,0,0,0,0c0,0,0,0,0,0.1l-2.4,4.2H9.7l1.8-3.2h0.9c0.4,0,0.7-0.3,0.7-0.7c0-0.4-0.3-0.7-0.7-0.7
h-1.2c-0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z M19.7,15.4L19,14.1l0.7-1.2h1.5L19.7,15.4L19.7,15.4z
M13.1,12.9h1.5l0.7,1.2l-0.8,1.3L13.1,12.9z M14.6,9l0.8,1.3l-0.7,1.2h-1.5L14.6,9L14.6,9z M16.5,13.4l-0.7-1.2l0.7-1.2h1.4
l0.7,1.2l-0.7,1.2H16.5z M17.9,9.7h-1.4l-0.8-1.3h2.9L17.9,9.7L17.9,9.7z M16.5,14.8h1.4l0.8,1.3h-2.9L16.5,14.8L16.5,14.8z
M19.7,11.6L19,10.4L19.7,9l1.5,2.5L19.7,11.6L19.7,11.6z"/>
</svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -1,28 +1,18 @@
import { importTypes } from '@rancher/auto-import';
import { IPlugin } from '@shell/core/types';
import extensionRouting from './routing/harvester-routing';
import harvesterCommonStore from './store/harvester-common';
import harvesterStore from './store/harvester-store';
import customValidators from './validators';
import extensionRoutes from './routing/harvester-routing';
// Init the package
export default function(plugin: IPlugin): void {
export default function (plugin: IPlugin) {
// Auto-import model, detail, edit from the folders
importTypes(plugin);
// Provide plugin metadata from package.json
plugin.metadata = require('./package.json');
// Load a product
plugin.addProduct(require('./product'));
// Built-in icon
plugin.metadata.icon = require('./icon.svg');
// Add Vue Routes
plugin.addRoutes(extensionRouting);
plugin.addDashboardStore(harvesterCommonStore.config.namespace, harvesterCommonStore.specifics, harvesterCommonStore.config);
plugin.addDashboardStore(harvesterStore.config.namespace, harvesterStore.specifics, harvesterStore.config, harvesterStore.init);
plugin.validators = customValidators;
plugin.register('component', 'NavHeaderRight', () => import(/* webpackChunkName: "pkg/harvester/components" */ `./components/HarvesterUpgradeHeader.vue`));
plugin.addProduct(require('./config/harvester-manager'));
plugin.addRoutes(extensionRoutes);
}

View File

@ -1514,3 +1514,30 @@ typeLabel:
one { IP Pool }
other { IP Pools }
}
harvesterManager:
manage: Manage
cluster:
label: Harvester Clusters
none: There are no Harvester Clusters
learnMore: Learn more about Harvester from the <a target="_blank" href="https://harvesterhci.io/" rel="noopener noreferrer nofollow">Harvester Web Site</a> or read the the <a target="_blank" href="https://docs.harvesterhci.io/" rel="noopener noreferrer nofollow">Harvester Docs</a>
description: Harvester is a modern Hyperconverged infrastructure (HCI) solution built for bare metal servers using enterprise-grade open source technologies including Kubernetes, Kubevirt and Longhorn.
plugins:
loadError: Error loading harvester plugin
rke:
templateError: Incorrect template format
affinity:
thisPodNamespace: This VM's namespace
matchExpressions:
inNamespaces: "Workloads in these namespaces"
vmAffinityTitle: VM Scheduling
namespaces:
placeholder: e.g. default,system,base
label: Namespaces
addLabel: Add Workload Selector
topologyKey:
placeholder: 'topology.kubernetes.io/zone'
vGpu:
title: VGPUs
label: VGPU type
placeholder: 'Please select a VGPU'

View File

@ -0,0 +1,243 @@
<script>
import BrandImage from '@shell/components/BrandImage';
import TypeDescription from '@shell/components/TypeDescription';
import ResourceTable from '@shell/components/ResourceTable';
import Masthead from '@shell/components/ResourceList/Masthead';
import Loading from '@shell/components/Loading';
import { HARVESTER_NAME as VIRTUAL } from '@shell/config/features';
import { CAPI, HCI, MANAGEMENT } from '@shell/config/types';
import { isHarvesterCluster } from '@shell/utils/cluster';
import { allHash } from '@shell/utils/promise';
export default {
components: {
BrandImage,
ResourceTable,
Masthead,
TypeDescription,
Loading
},
props: {
schema: {
type: Object,
required: true,
},
useQueryParamsForSimpleFiltering: {
type: Boolean,
default: false
}
},
async fetch() {
console.log('dfetchttt');
const inStore = this.$store.getters['currentProduct'].inStore;
const hash = await allHash({
hciClusters: this.$store.dispatch(`${ inStore }/findAll`, { type: HCI.CLUSTER }),
mgmtClusters: this.$store.dispatch(`${ inStore }/findAll`, { type: MANAGEMENT.CLUSTER })
});
this.hciClusters = hash.hciClusters;
this.mgmtClusters = hash.mgmtClusters;
},
data() {
console.log('ddataata');
const resource = CAPI.RANCHER_CLUSTER;
return {
navigating: false,
VIRTUAL,
hciDashboard: HCI.DASHBOARD,
resource,
hResource: HCI.CLUSTER,
realSchema: this.$store.getters['management/schemaFor'](CAPI.RANCHER_CLUSTER),
hciClusters: [],
mgmtClusters: []
};
},
computed: {
importLocation() {
return {
name: 'c-cluster-product-resource-create',
params: {
product: this.$store.getters['currentProduct'].name,
resource: this.schema.id,
},
};
},
canCreateCluster() {
const schema = this.$store.getters['management/schemaFor'](CAPI.RANCHER_CLUSTER);
return !!schema?.collectionMethods.find((x) => x.toLowerCase() === 'post');
},
rows() {
return this.hciClusters.filter((c) => {
const cluster = this.mgmtClusters.find((cluster) => cluster?.metadata?.name === c?.status?.clusterName);
return isHarvesterCluster(cluster);
});
},
typeDisplay() {
return this.t(`typeLabel."${ HCI.CLUSTER }"`, { count: this.row?.length || 0 });
},
},
methods: {
async goToCluster(row) {
const timeout = setTimeout(() => {
// Don't show loading indicator for quickly fetched plugins
this.navigating = row.id;
}, 1000);
try {
await row.goToCluster();
clearTimeout(timeout);
this.navigating = false;
} catch {
// The error handling is carried out within goToCluster, but just in case something happens before the promise chain can catch it...
clearTimeout(timeout);
this.navigating = false;
}
}
}
};
</script>
<template>
<Loading v-if="$fetchState.pending" />
<div v-else>
<Masthead
:schema="realSchema"
:resource="resource"
:is-creatable="false"
:type-display="typeDisplay"
>
<template #typeDescription>
<TypeDescription :resource="hResource" />
</template>
<template
v-if="canCreateCluster"
#extraActions
>
<router-link
:to="importLocation"
class="btn role-primary"
>
{{ t('cluster.importAction') }}
</router-link>
</template>
</Masthead>
<ResourceTable
v-if="rows && rows.length"
:schema="schema"
:rows="rows"
:is-creatable="true"
:namespaced="false"
:use-query-params-for-simple-filtering="useQueryParamsForSimpleFiltering"
>
<template #col:name="{row}">
<td>
<span class="cluster-link">
<a
v-if="row.isReady"
class="link"
:disabled="navigating ? true : null"
@click="goToCluster(row)"
>{{ row.nameDisplay }}</a>
<span v-else>
{{ row.nameDisplay }}
</span>
<i
class="icon icon-spinner icon-spin ml-5"
:class="{'navigating': navigating === row.id}"
/>
</span>
</td>
</template>
<template #cell:harvester="{row}">
<router-link
class="btn btn-sm role-primary"
:to="row.detailLocation"
>
{{ t('harvesterManager.manage') }}
</router-link>
</template>
</ResourceTable>
<div v-else>
<div class="no-clusters">
{{ t('harvesterManager.cluster.none') }}
</div>
<hr class="info-section">
<div class="logo">
<BrandImage
file-name="harvester.png"
height="64"
/>
</div>
<div class="tagline">
<div>{{ t('harvesterManager.cluster.description') }}</div>
</div>
<div class="tagline sub-tagline">
<div v-clean-html="t('harvesterManager.cluster.learnMore', {}, true)" />
</div>
</div>
</div>
</template>
<style lang="scss" scoped>
.cluster-link {
display: flex;
align-items: center;
.icon {
// Use visibility to avoid the columns re-adjusting when the icon is shown
visibility: hidden;
&.navigating {
visibility: visible;
}
}
}
.no-clusters {
text-align: center;
}
.info-section {
margin-top: 60px;
}
.logo {
display: flex;
justify-content: center;
margin: 60px 0 40px 0;
}
.tagline {
display: flex;
justify-content: center;
margin-top: 30px;
> div {
font-size: 16px;
line-height: 22px;
max-width: 80%;
text-align: center;
}
}
.link {
cursor: pointer;
}
</style>

View File

@ -1,11 +1,12 @@
{
"name": "harvester",
"description": "harvester plugin",
"description": "Provides the Virtualization Management feature in Rancher Manager",
"version": "0.1.0",
"private": false,
"rancher": {
"annotations": {
"catalog.cattle.io/rancher-version": ">= v2.8.3"
"catalog.cattle.io/rancher-version": ">= v2.10.0",
"catalog.cattle.io/display-name": "Virtualization Manager"
}
},
"scripts": {

View File

@ -111,6 +111,8 @@ export function init($plugin: any, store: any) {
}
},
hideNamespaceLocation: true,
category: 'global',
icon: 'globe',
});
basicType([HCI.DASHBOARD]);

View File

@ -0,0 +1,18 @@
import { RouteRecordRaw } from 'vue-router';
import { PRODUCT_NAME } from '../config/harvester-manager';
import Root from '../pages/c/_cluster/index.vue';
import ListHarvesterMgrResource from '../pages/c/_cluster/_resource/index.vue';
import CreateHarvesterMgrResource from '../pages/c/_cluster/_resource/create.vue';
import ViewHarvesterMgrResource from '../pages/c/_cluster/_resource/_id.vue';
import ClusterListPage from '../list/harvesterhci.io.management.cluster.vue';
const routes = [
{
path: '/harvesterManager/clusters',
name: `${ PRODUCT_NAME }-c-cluster-list-page`,
component: ClusterListPage,
},
];
export default routes;

View File

@ -1,83 +0,0 @@
// eslint-disable-next-line import/named
// import { RouteRecordRaw } from 'vue-router';
import { PRODUCT_NAME } from '../config/harvester';
import Root from '../pages/c/_cluster/index.vue';
import HarvesterSupport from '../pages/c/_cluster/support/index.vue';
import HarvesterConsoleSerial from '../pages/c/_cluster/console/_uid/serial.vue';
import HarvesterConsoleVnc from '../pages/c/_cluster/console/_uid/vnc.vue';
import ListHarvesterResource from '../pages/c/_cluster/_resource/index.vue';
import HarvesterBrand from '../pages/c/_cluster/brand/index.vue';
import CreateHarvesterResource from '../pages/c/_cluster/_resource/create.vue';
import ViewHarvesterResource from '../pages/c/_cluster/_resource/_id.vue';
import ViewHarvesterNsResource from '../pages/c/_cluster/_resource/_namespace/_id.vue';
import HarvesterAirgapUpdgrade from '../pages/c/_cluster/airgapupgrade/index.vue';
import HarvesterMembers from '../pages/c/_cluster/members/index.vue';
import ProjectNamespaces from '../pages/c/_cluster/projectsnamespaces.vue';
import HarvesterAlertmanagerReceiver from '../pages/c/_cluster/alertmanagerconfig/_alertmanagerconfigid/receiver.vue';
const routes: any[] = [
{
name: `${ PRODUCT_NAME }-c-cluster-support`,
path: `/:product/c/:cluster/support`,
component: HarvesterSupport,
},
{
name: `${ PRODUCT_NAME }-c-cluster-console-uid-serial`,
path: `/:product/c/:cluster/console/:uid/serial`,
component: HarvesterConsoleSerial,
},
{
name: `${ PRODUCT_NAME }-c-cluster-console-uid-vnc`,
path: `/:product/c/:cluster/console/:uid/vnc`,
component: HarvesterConsoleVnc,
},
{
name: `${ PRODUCT_NAME }-c-cluster-airgapupgrade`,
path: `/:product/c/:cluster/airgapupgrade`,
component: HarvesterAirgapUpdgrade,
},
{
name: `${ PRODUCT_NAME }-c-cluster-brand`,
path: `/:product/c/:cluster/brand`,
component: HarvesterBrand,
},
{
name: `${ PRODUCT_NAME }-c-cluster-alertmanagerconfig-alertmanagerconfigid-receiver`,
path: `/:product/c/:cluster/alertmanagerconfig/:alertmanagerconfigid/receiver`,
component: HarvesterAlertmanagerReceiver,
},
{
name: `${ PRODUCT_NAME }-c-cluster-members`,
path: `/:product/c/:cluster/members`,
component: HarvesterMembers,
},
{
name: `${ PRODUCT_NAME }-c-cluster`,
path: `/:product/c/:cluster`,
component: Root,
}, {
name: `${ PRODUCT_NAME }-c-cluster-projectsnamespaces`,
path: `/:product/c/:cluster/projectsnamespaces`,
component: ProjectNamespaces,
}, {
name: `${ PRODUCT_NAME }-c-cluster-resource`,
path: `/:product/c/:cluster/:resource`,
component: ListHarvesterResource,
}, {
name: `${ PRODUCT_NAME }-c-cluster-resource-create`,
path: `/:product/c/:cluster/:resource/create`,
component: CreateHarvesterResource,
}, {
name: `${ PRODUCT_NAME }-c-cluster-resource-id`,
path: `/:product/c/:cluster/:resource/:id`,
component: ViewHarvesterResource,
}, {
name: `${ PRODUCT_NAME }-c-cluster-resource-namespace-id`,
path: `/:product/c/:cluster/:resource/:namespace/:id`,
component: ViewHarvesterNsResource,
},
];
export default routes;

View File

@ -30,7 +30,6 @@
"./node_modules/@rancher/shell/types"
],
"types": [
"@types/jest",
"@types/node",
"cypress",
"rancher",

5158
yarn.lock

File diff suppressed because it is too large Load Diff