From 675c45f77bb4d3af7de20f56048d73465a4741c4 Mon Sep 17 00:00:00 2001 From: Francesco Torchia Date: Mon, 29 Apr 2024 20:50:16 +0200 Subject: [PATCH] Add types Signed-off-by: Francesco Torchia --- pkg/harvester/config/harvester-map.js | 63 ++++++++++++++++ pkg/harvester/config/harvester.ts | 2 + pkg/harvester/config/labels-annotations.js | 49 ++++++++++++ pkg/harvester/config/query-params.js | 1 + pkg/harvester/config/settings.js | 88 ++++++++++++++++++++++ pkg/harvester/config/table-headers.js | 36 +++++++++ pkg/harvester/config/types.ts | 51 +++++++++++++ pkg/harvester/product.ts | 22 ++++-- pkg/harvester/routing/extension-routing.js | 6 +- vue.config.js | 2 +- 10 files changed, 307 insertions(+), 13 deletions(-) create mode 100644 pkg/harvester/config/harvester-map.js create mode 100644 pkg/harvester/config/harvester.ts create mode 100644 pkg/harvester/config/labels-annotations.js create mode 100644 pkg/harvester/config/query-params.js create mode 100644 pkg/harvester/config/settings.js create mode 100644 pkg/harvester/config/table-headers.js create mode 100644 pkg/harvester/config/types.ts diff --git a/pkg/harvester/config/harvester-map.js b/pkg/harvester/config/harvester-map.js new file mode 100644 index 00000000..86a4c3aa --- /dev/null +++ b/pkg/harvester/config/harvester-map.js @@ -0,0 +1,63 @@ +export const MemoryUnit = [{ + label: 'Mi', + value: 'Mi' +}, { + label: 'Gi', + value: 'Gi' +}, +{ + label: 'TiB', + value: 'Ti' +}]; + +export const InterfaceOption = [{ + label: 'VirtIO', + value: 'virtio' +}, { + label: 'SATA', + value: 'sata' +}, { + label: 'SCSI', + value: 'scsi' +}]; + +export const SOURCE_TYPE = { + NEW: 'New', + IMAGE: 'VM Image', + ATTACH_VOLUME: 'Existing Volume', + CONTAINER: 'Container' +}; + +export const VOLUME_TYPE = [{ + label: 'disk', + value: 'disk' +}, { + label: 'cd-rom', + value: 'cd-rom' +}]; + +export const ACCESS_CREDENTIALS = { + RESET_PWD: 'userPassword', + INJECT_SSH: 'sshPublicKey' +}; + +export const RunStrategys = ['Always', 'RerunOnFailure', 'Manual', 'Halted']; + +export const VOLUME_DATA_SOURCE_KIND = { + VolumeSnapshot: 'VolumeSnapshot', + PersistentVolumeClaim: 'Volume' +}; + +export const FLOW_TYPE = { + LOGGING: 'Logging', + AUDIT: 'Audit', + EVENT: 'Event' +}; + +export const ADD_ONS = { + HARVESTER_SEEDER: 'harvester-seeder', + PCI_DEVICE_CONTROLLER: 'pci-device-controller', + RANCHER_LOGGING: 'rancher-logging', + RANCHER_MONITORING: 'rancher-monitoring', + VM_IMPORT_CONTROLLER: 'vm-import-controller', +}; diff --git a/pkg/harvester/config/harvester.ts b/pkg/harvester/config/harvester.ts new file mode 100644 index 00000000..5127c2dc --- /dev/null +++ b/pkg/harvester/config/harvester.ts @@ -0,0 +1,2 @@ +export const PRODUCT_NAME = 'harvester'; +export const BLANK_CLUSTER = '_'; diff --git a/pkg/harvester/config/labels-annotations.js b/pkg/harvester/config/labels-annotations.js new file mode 100644 index 00000000..29226994 --- /dev/null +++ b/pkg/harvester/config/labels-annotations.js @@ -0,0 +1,49 @@ +export const HCI = { + CLOUD_INIT: 'harvesterhci.io/cloud-init-template', + CURRENT_IP: 'rke2.io/internal-ip', + OWNED_BY: 'harvesterhci.io/owned-by', + IMAGE_ID: 'harvesterhci.io/imageId', + SSH_NAMES: 'harvesterhci.io/sshNames', + NETWORK_IPS: 'network.harvesterhci.io/ips', + TEMPLATE_VERSION_CUSTOM_NAME: 'template-version.harvesterhci.io/customName', + CREATOR: 'harvesterhci.io/creator', + OS: 'harvesterhci.io/os', + NETWORK_TYPE: 'network.harvesterhci.io/type', + VM_NAME: 'harvesterhci.io/vmName', + VM_NAME_PREFIX: 'harvesterhci.io/vmNamePrefix', + VM_RESERVED_MEMORY: 'harvesterhci.io/reservedMemory', + MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status', + HOST_CUSTOM_NAME: 'harvesterhci.io/host-custom-name', + HOST_CONSOLE_URL: 'harvesterhci.io/host-console-url', + RESTORE_NAME: 'restore.harvesterhci.io/name', + NODE_ROLE_MASTER: 'node-role.kubernetes.io/master', + NODE_ROLE_CONTROL_PLANE: 'node-role.kubernetes.io/control-plane', + PROMOTE_STATUS: 'harvesterhci.io/promote-status', + MIGRATION_STATE: 'harvesterhci.io/migrationState', + VOLUME_CLAIM_TEMPLATE: 'harvesterhci.io/volumeClaimTemplates', + IMAGE_NAME: 'harvesterhci.io/image-name', + INIT_IP: 'etcd.rke2.cattle.io/node-address', + NODE_SCHEDULABLE: 'kubevirt.io/schedulable', + NETWORK_ROUTE: 'network.harvesterhci.io/route', + OS_UPGRADE_IMAGE: 'harvesterhci.io/os-upgrade-image', + LATEST_UPGRADE: 'harvesterhci.io/latestUpgrade', + UPGRADE_STATE: 'harvesterhci.io/upgradeState', + REAY_MESSAGE: 'harvesterhci.io/read-message', + DYNAMIC_SSHKEYS_NAMES: 'harvesterhci.io/dynamic-ssh-key-names', + DYNAMIC_SSHKEYS_USERS: 'harvesterhci.io/dynamic-ssh-key-users', + IMAGE_SUFFIX: 'harvesterhci.io/image-type', + OS_TYPE: 'harvesterhci.io/os-type', + HOST_REQUEST: 'management.cattle.io/pod-requests', + STORAGE_CLASS: 'harvesterhci.io/storageClassName', + STORAGE_NETWORK: 'storage-network.settings.harvesterhci.io', + ADDON_EXPERIMENTAL: 'addon.harvesterhci.io/experimental', + VOLUME_ERROR: 'longhorn.io/volume-scheduling-error', + KVM_AMD_CPU: 'cpu-feature.node.kubevirt.io/svm', + KVM_INTEL_CPU: 'cpu-feature.node.kubevirt.io/vmx', + NODE_MANUFACTURER: 'manufacturer', + NODE_MODEL: 'model', + NODE_SERIAL_NUMBER: 'serialNumber', + VM_INSUFFICIENT: 'harvesterhci.io/insufficient-resource-quota', + NODE_NTP_SYNC_STATUS: 'node.harvesterhci.io/ntp-service', + PARENT_SRIOV: 'harvesterhci.io/parent-sriov-network-device', +}; diff --git a/pkg/harvester/config/query-params.js b/pkg/harvester/config/query-params.js new file mode 100644 index 00000000..6c56a44c --- /dev/null +++ b/pkg/harvester/config/query-params.js @@ -0,0 +1 @@ +export const CLUSTER_NETWORK = 'clusterNetwork'; diff --git a/pkg/harvester/config/settings.js b/pkg/harvester/config/settings.js new file mode 100644 index 00000000..9984938e --- /dev/null +++ b/pkg/harvester/config/settings.js @@ -0,0 +1,88 @@ +export const HCI_SETTING = { + BACKUP_TARGET: 'backup-target', + CONTAINERD_REGISTRY: 'containerd-registry', + LOG_LEVEL: 'log-level', + SERVER_VERSION: 'server-version', + UI_INDEX: 'ui-index', + UI_PLUGIN_INDEX: 'ui-plugin-index', + UPGRADE_CHECKER_ENABLED: 'upgrade-checker-enabled', + UPGRADE_CHECKER_URL: 'upgrade-checker-url', + VLAN: 'vlan', + UI_SOURCE: 'ui-source', + UI_PL: 'ui-pl', + HTTP_PROXY: 'http-proxy', + ADDITIONAL_CA: 'additional-ca', + OVERCOMMIT_CONFIG: 'overcommit-config', + CLUSTER_REGISTRATION_URL: 'cluster-registration-url', + DEFAULT_STORAGE_CLASS: 'default-storage-class', + SUPPORT_BUNDLE_TIMEOUT: 'support-bundle-timeout', + SUPPORT_BUNDLE_IMAGE: 'support-bundle-image', + STORAGE_NETWORK: 'storage-network', + VM_FORCE_RESET_POLICY: 'vm-force-reset-policy', + SSL_CERTIFICATES: 'ssl-certificates', + SSL_PARAMETERS: 'ssl-parameters', + SUPPORT_BUNDLE_NAMESPACES: 'support-bundle-namespaces', + AUTO_DISK_PROVISION_PATHS: 'auto-disk-provision-paths', + RELEASE_DOWNLOAD_URL: 'release-download-url', + CCM_CSI_VERSION: 'harvester-csi-ccm-versions', + CSI_DRIVER_CONFIG: 'csi-driver-config', + VM_TERMINATION_PERIOD: 'default-vm-termination-grace-period-seconds', + NTP_SERVERS: 'ntp-servers', +}; + +export const HCI_ALLOWED_SETTINGS = { + [HCI_SETTING.BACKUP_TARGET]: { + kind: 'json', from: 'import', canReset: true + }, + [HCI_SETTING.LOG_LEVEL]: { + kind: 'enum', + options: ['info', 'debug', 'trace'] + }, + [HCI_SETTING.VLAN]: { + kind: 'custom', from: 'import', alias: 'vlan' + }, + [HCI_SETTING.CSI_DRIVER_CONFIG]: { kind: 'json', from: 'import' }, + [HCI_SETTING.SERVER_VERSION]: { readOnly: true }, + [HCI_SETTING.UPGRADE_CHECKER_ENABLED]: { kind: 'boolean' }, + [HCI_SETTING.UPGRADE_CHECKER_URL]: { kind: 'url' }, + [HCI_SETTING.HTTP_PROXY]: { kind: 'json', from: 'import' }, + [HCI_SETTING.ADDITIONAL_CA]: { + kind: 'multiline', canReset: true, from: 'import' + }, + [HCI_SETTING.OVERCOMMIT_CONFIG]: { kind: 'json', from: 'import' }, + [HCI_SETTING.SUPPORT_BUNDLE_TIMEOUT]: {}, + [HCI_SETTING.SUPPORT_BUNDLE_IMAGE]: { kind: 'json', from: 'import' }, + [HCI_SETTING.STORAGE_NETWORK]: { kind: 'custom', from: 'import' }, + [HCI_SETTING.VM_FORCE_RESET_POLICY]: { kind: 'json', from: 'import' }, + [HCI_SETTING.RANCHER_MANAGER_SUPPORT]: { kind: 'boolean' }, + [HCI_SETTING.SSL_CERTIFICATES]: { kind: 'json', from: 'import' }, + [HCI_SETTING.SSL_PARAMETERS]: { + kind: 'json', from: 'import', canReset: true + }, + [HCI_SETTING.SUPPORT_BUNDLE_NAMESPACES]: { from: 'import', canReset: true }, + [HCI_SETTING.AUTO_DISK_PROVISION_PATHS]: { canReset: true }, + [HCI_SETTING.RELEASE_DOWNLOAD_URL]: { kind: 'url' }, + [HCI_SETTING.UI_PLUGIN_INDEX]: { kind: 'url' }, + [HCI_SETTING.CONTAINERD_REGISTRY]: { + kind: 'json', from: 'import', canReset: true + }, + [HCI_SETTING.UI_SOURCE]: { + kind: 'enum', + options: ['auto', 'external', 'bundled'] + }, + [HCI_SETTING.UI_INDEX]: { kind: 'url' }, + [HCI_SETTING.VM_TERMINATION_PERIOD]: { kind: 'string', from: 'import' }, + [HCI_SETTING.NTP_SERVERS]: { + kind: 'json', from: 'import', canReset: true + }, +}; + +export const HCI_SINGLE_CLUSTER_ALLOWED_SETTING = { + [HCI_SETTING.CLUSTER_REGISTRATION_URL]: { + kind: 'url', + canReset: true, + }, + [HCI_SETTING.UI_PL]: { + kind: 'custom', from: 'import', alias: 'branding' + } +}; diff --git a/pkg/harvester/config/table-headers.js b/pkg/harvester/config/table-headers.js new file mode 100644 index 00000000..ecd7afa8 --- /dev/null +++ b/pkg/harvester/config/table-headers.js @@ -0,0 +1,36 @@ +/** + * Harvester + */ + +// image +export const IMAGE_DOWNLOAD_SIZE = { + name: 'downloadedBytes', + labelKey: 'tableHeaders.size', + value: 'downSize', + sort: 'status.size', + width: 120 +}; + +export const IMAGE_PROGRESS = { + name: 'Uploaded', + labelKey: 'tableHeaders.progress', + value: 'status.progress', + sort: 'status.progress', + formatter: 'ImagePercentageBar', +}; + +// SSH keys +export const FINGERPRINT = { + name: 'Fingerprint', + labelKey: 'tableHeaders.fingerprint', + value: 'status.fingerPrint', +}; + +// The column of target volume on snapshot list page +export const SNAPSHOT_TARGET_VOLUME = { + name: 'TargetVolume', + labelKey: 'harvester.tableHeaders.snapshotTargetVolume', + value: 'spec.source.persistentVolumeClaimName', + sort: 'spec.source.persistentVolumeClaimName', + formatter: 'SnapshotTargetVolume', +}; diff --git a/pkg/harvester/config/types.ts b/pkg/harvester/config/types.ts new file mode 100644 index 00000000..70910b38 --- /dev/null +++ b/pkg/harvester/config/types.ts @@ -0,0 +1,51 @@ +export const HCI = { + VM: 'kubevirt.io.virtualmachine', + VMI: 'kubevirt.io.virtualmachineinstance', + VMIM: 'kubevirt.io.virtualmachineinstancemigration', + VM_TEMPLATE: 'harvesterhci.io.virtualmachinetemplate', + VM_VERSION: 'harvesterhci.io.virtualmachinetemplateversion', + IMAGE: 'harvesterhci.io.virtualmachineimage', + SSH: 'harvesterhci.io.keypair', + VOLUME: 'harvesterhci.io.volume', + USER: 'harvesterhci.io.user', + SETTING: 'harvesterhci.io.setting', + UPGRADE: 'harvesterhci.io.upgrade', + UPGRADE_LOG: 'harvesterhci.io.upgradelog', + BACKUP: 'harvesterhci.io.virtualmachinebackup', + RESTORE: 'harvesterhci.io.virtualmachinerestore', + NODE_NETWORK: 'network.harvesterhci.io.nodenetwork', + CLUSTER_NETWORK: 'network.harvesterhci.io.clusternetwork', + SUPPORT_BUNDLE: 'harvesterhci.io.supportbundle', + NETWORK_ATTACHMENT: 'harvesterhci.io.networkattachmentdefinition', + CLUSTER: 'harvesterhci.io.management.cluster', + DASHBOARD: 'harvesterhci.io.dashboard', + BLOCK_DEVICE: 'harvesterhci.io.blockdevice', + CLOUD_TEMPLATE: 'harvesterhci.io.cloudtemplate', + HOST: 'harvesterhci.io.host', + VERSION: 'harvesterhci.io.version', + SNAPSHOT: 'harvesterhci.io.volumesnapshot', + VM_SNAPSHOT: 'harvesterhci.io.vmsnapshot', + ALERTMANAGERCONFIG: 'harvesterhci.io.monitoring.alertmanagerconfig', + CLUSTER_FLOW: 'harvesterhci.io.logging.clusterflow', + CLUSTER_OUTPUT: 'harvesterhci.io.logging.clusteroutput', + FLOW: 'harvesterhci.io.logging.flow', + OUTPUT: 'harvesterhci.io.logging.output', + STORAGE: 'harvesterhci.io.storage', + KSTUNED: 'node.harvesterhci.io.ksmtuned', + PCI_DEVICE: 'devices.harvesterhci.io.pcidevice', + PCI_CLAIM: 'devices.harvesterhci.io.pcideviceclaim', + SR_IOV: 'devices.harvesterhci.io.sriovnetworkdevice', + VLAN_CONFIG: 'network.harvesterhci.io.vlanconfig', + VLAN_STATUS: 'network.harvesterhci.io.vlanstatus', + ADD_ONS: 'harvesterhci.io.addon', + LINK_MONITOR: 'network.harvesterhci.io.linkmonitor', + SECRET: 'harvesterhci.io.secret', + INVENTORY: 'metal.harvesterhci.io.inventory', + LB: 'loadbalancer.harvesterhci.io.loadbalancer', + IP_POOL: 'loadbalancer.harvesterhci.io.ippool', + HARVESTER_CONFIG: 'rke-machine-config.cattle.io.harvesterconfig', +}; + +export const VOLUME_SNAPSHOT = 'snapshot.storage.k8s.io.volumesnapshot'; +export const CSI_DRIVER = 'storage.k8s.io.csidriver'; +export const VOLUME_SNAPSHOT_CLASS = 'snapshot.storage.k8s.io.volumesnapshotclass'; diff --git a/pkg/harvester/product.ts b/pkg/harvester/product.ts index bc8cbd76..154550b4 100644 --- a/pkg/harvester/product.ts +++ b/pkg/harvester/product.ts @@ -1,18 +1,24 @@ import { IPlugin } from '@shell/core/types'; +import { PRODUCT_NAME, BLANK_CLUSTER } from './config/harvester'; export function init($plugin: IPlugin, store: any) { - const PRODUCT_NAME = 'harvester'; - const BLANK_CLUSTER = '_'; - const { product } = $plugin.DSL(store, PRODUCT_NAME); + const isSingleProduct = process.env.rancherEnv === PRODUCT_NAME; + product({ - icon: 'gear', - inStore: 'management', - weight: 100, - to: { + inStore: 'management', + showNamespaceFilter: true, + hideKubeShell: true, + hideKubeConfig: true, + showClusterSwitcher: true, + hideCopyConfig: true, + hideSystemResources: true, + hideNamespaceLocation: true, + weight: 100, + to: { name: `${ PRODUCT_NAME }-c-cluster`, - path: `/${ PRODUCT_NAME }/c/:cluster/dashboard`, + path: `/${ PRODUCT_NAME }/c/:cluster`, params: { product: PRODUCT_NAME, cluster: BLANK_CLUSTER, diff --git a/pkg/harvester/routing/extension-routing.js b/pkg/harvester/routing/extension-routing.js index 5656df8b..8bc14168 100644 --- a/pkg/harvester/routing/extension-routing.js +++ b/pkg/harvester/routing/extension-routing.js @@ -1,8 +1,6 @@ // Don't forget to create a VueJS page called index.vue in the /pages folder!!! import Dashboard from '../pages/index.vue'; - -const BLANK_CLUSTER = '_'; -const PRODUCT_NAME = 'harvester'; +import { PRODUCT_NAME, BLANK_CLUSTER } from '../config/harvester'; const routes = [ { @@ -17,4 +15,4 @@ const routes = [ } ]; -export default routes; \ No newline at end of file +export default routes; diff --git a/vue.config.js b/vue.config.js index b0973bd4..83208dbd 100644 --- a/vue.config.js +++ b/vue.config.js @@ -2,5 +2,5 @@ const config = require('@rancher/shell/vue.config'); module.exports = config(__dirname, { excludes: [], - // excludes: ['fleet', 'example'] + // excludes: ['harvester'] });