mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-11-16 13:56:08 +08:00
Compare commits
21
Commits
new_vnc
...
v1.10.0-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3322162d9a | ||
|
|
6e0e0237ef | ||
|
|
d6f6f7c54c | ||
|
|
39ed41e527 | ||
|
|
2f72f25b6e | ||
|
|
5406c08f76 | ||
|
|
71141b257a | ||
|
|
02862bbeea | ||
|
|
5f13aadeed | ||
|
|
da36db143f | ||
|
|
5af181f5b6 | ||
|
|
528255dea4 | ||
|
|
3c92a06268 | ||
|
|
6256cdc97a | ||
|
|
4323132565 | ||
|
|
d05ec68e16 | ||
|
|
cb2cef5e73 | ||
|
|
45116b568a | ||
|
|
f42d798d10 | ||
|
|
50b4cf5248 | ||
|
|
cba37194b6 |
@@ -0,0 +1,12 @@
|
||||
name: Run Unit Tests
|
||||
description: Run Unit Tests
|
||||
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- name: Setup env
|
||||
uses: ./.github/actions/setup
|
||||
|
||||
- name: Run unit tests
|
||||
shell: bash
|
||||
run: yarn test:ci
|
||||
@@ -125,6 +125,13 @@ jobs:
|
||||
node-version-file: '.nvmrc'
|
||||
cache: 'yarn'
|
||||
|
||||
# Tag builds (RC, formal and sprint releases) ship the tag as the package
|
||||
# version. RC/formal tags already match package.json; sprint tags
|
||||
# (vX.Y.Z-dev-YYYYMMDD) only share its prefix, so pin it here for the build.
|
||||
- name: Pin package version to tag
|
||||
if: ${{ inputs.CI_BUILD_TAG != '' }}
|
||||
run: ./scripts/bump_version.sh "${{ inputs.CI_BUILD_TAG }}"
|
||||
|
||||
- id: ci-build-pkg
|
||||
name: Build pkg
|
||||
run: ./scripts/ci-build-pkg.sh harvester
|
||||
|
||||
@@ -58,6 +58,12 @@ jobs:
|
||||
- name: Setup Nodejs with yarn install
|
||||
uses: ./.github/actions/setup
|
||||
|
||||
# The catalog image is tagged with the package.json version. Sprint tags
|
||||
# (vX.Y.Z-dev-YYYYMMDD) only share its prefix, so pin it to the tag here.
|
||||
- name: Pin package version to tag
|
||||
if: ${{ github.ref_type == 'tag' }}
|
||||
run: ./scripts/bump_version.sh "${{ github.ref_name }}"
|
||||
|
||||
- name: Build and push UI image
|
||||
run: |
|
||||
publish="yarn publish-pkgs -cp -r ${{ inputs.registry_target }} -o ${{ inputs.registry_user }}"
|
||||
|
||||
@@ -71,3 +71,11 @@ jobs:
|
||||
GITHUB_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
|
||||
GITHUB_BEFORE: ${{ github.event.before }}
|
||||
GITHUB_AFTER: ${{ github.event.after }}
|
||||
|
||||
unit-tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
|
||||
|
||||
- name: Run unit tests
|
||||
uses: ./.github/actions/test
|
||||
|
||||
@@ -59,6 +59,8 @@ You are an expert Senior Software Engineer specializing in Vue.js and TypeScript
|
||||
| `yarn serve-pkgs` | Serve the locally built extension for testing |
|
||||
| `yarn lint` | Run ESLint (zero warnings allowed) |
|
||||
| `yarn lint:fix` | Run ESLint with auto-fix |
|
||||
| `yarn test` | Run the unit tests (Jest) in watch mode |
|
||||
| `yarn test:ci` | Run the unit tests once, as CI does (silent) |
|
||||
| `yarn clean` | Clean build artifacts |
|
||||
| `yarn agents:generate` | Regenerate `AGENTS.md` from `docs/agents.md/` sources |
|
||||
|
||||
@@ -95,6 +97,16 @@ You are an expert Senior Software Engineer specializing in Vue.js and TypeScript
|
||||
- ESLint covers `.js`, `.ts`, and `.vue` files.
|
||||
- Always run `yarn lint:fix` before committing.
|
||||
|
||||
### Unit Tests
|
||||
|
||||
- **Run**:
|
||||
```bash
|
||||
yarn test
|
||||
```
|
||||
- `yarn test` starts Jest in watch mode (like in the Rancher dashboard) and only runs the tests related to changed files. It does not exit, so use `yarn test:ci` for a single run of all tests, e.g. in scripts.
|
||||
- CI runs `yarn test:ci` on every pull request.
|
||||
- See the Unit Tests section of the Contributors Guide for how the tests are set up.
|
||||
|
||||
### Commit Conventions
|
||||
|
||||
- Commits are validated by [commitlint](https://commitlint.js.org/) via a Husky `commit-msg` hook.
|
||||
@@ -187,6 +199,19 @@ To add a feature in a new release, follow these steps:
|
||||
|
||||
See https://github.com/harvester/harvester-ui-tests
|
||||
|
||||
## Unit Tests (Jest)
|
||||
|
||||
Unit and component tests run with [Jest](https://jestjs.io/). The setup follows the Rancher dashboard and the Rancher extension template ([rancher/ui-plugin-examples](https://github.com/rancher/ui-plugin-examples)), so both stay aligned.
|
||||
|
||||
- Run the tests in watch mode with `yarn test`, all tests once with `yarn test:ci`, a single file with `yarn test <path>`. CI runs `yarn test:ci` on every pull request.
|
||||
- Test files live next to the code in `__tests__` folders and are named `<name>.test.js` or `<name>.test.ts`.
|
||||
- Configuration:
|
||||
- `jest.config.js`: environment, module aliases (`@shell`, `@components`, `@pkg`) and transforms.
|
||||
- `jest.setup.js`: global mocks (`t`, `$store`, common directives) and browser APIs that jsdom does not provide.
|
||||
- `vue3JestRegisterTs.js`: makes TypeScript available to the Vue compiler, otherwise `.vue` files with typed props fail to compile.
|
||||
- Components are tested with the Vue Test Utils 2 API: use `props` and `global.mocks`, not the Vue 2 options `propsData` and `mocks`.
|
||||
- Models and utils can be tested without mounting anything, see `pkg/harvester/models/__tests__` for examples.
|
||||
|
||||
## Node Dependencies
|
||||
|
||||
Dependencies are managed via `package.json` and `yarn`
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
| `yarn serve-pkgs` | Serve the locally built extension for testing |
|
||||
| `yarn lint` | Run ESLint (zero warnings allowed) |
|
||||
| `yarn lint:fix` | Run ESLint with auto-fix |
|
||||
| `yarn test` | Run the unit tests (Jest) in watch mode |
|
||||
| `yarn test:ci` | Run the unit tests once, as CI does (silent) |
|
||||
| `yarn clean` | Clean build artifacts |
|
||||
| `yarn agents:generate` | Regenerate `AGENTS.md` from `docs/agents.md/` sources |
|
||||
|
||||
@@ -51,6 +53,16 @@
|
||||
- ESLint covers `.js`, `.ts`, and `.vue` files.
|
||||
- Always run `yarn lint:fix` before committing.
|
||||
|
||||
### Unit Tests
|
||||
|
||||
- **Run**:
|
||||
```bash
|
||||
yarn test
|
||||
```
|
||||
- `yarn test` starts Jest in watch mode (like in the Rancher dashboard) and only runs the tests related to changed files. It does not exit, so use `yarn test:ci` for a single run of all tests, e.g. in scripts.
|
||||
- CI runs `yarn test:ci` on every pull request.
|
||||
- See the Unit Tests section of the Contributors Guide for how the tests are set up.
|
||||
|
||||
### Commit Conventions
|
||||
|
||||
- Commits are validated by [commitlint](https://commitlint.js.org/) via a Husky `commit-msg` hook.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
## Unit Tests (Jest)
|
||||
|
||||
Unit and component tests run with [Jest](https://jestjs.io/). The setup follows the Rancher dashboard and the Rancher extension template ([rancher/ui-plugin-examples](https://github.com/rancher/ui-plugin-examples)), so both stay aligned.
|
||||
|
||||
- Run the tests in watch mode with `yarn test`, all tests once with `yarn test:ci`, a single file with `yarn test <path>`. CI runs `yarn test:ci` on every pull request.
|
||||
- Test files live next to the code in `__tests__` folders and are named `<name>.test.js` or `<name>.test.ts`.
|
||||
- Configuration:
|
||||
- `jest.config.js`: environment, module aliases (`@shell`, `@components`, `@pkg`) and transforms.
|
||||
- `jest.setup.js`: global mocks (`t`, `$store`, common directives) and browser APIs that jsdom does not provide.
|
||||
- `vue3JestRegisterTs.js`: makes TypeScript available to the Vue compiler, otherwise `.vue` files with typed props fail to compile.
|
||||
- Components are tested with the Vue Test Utils 2 API: use `props` and `global.mocks`, not the Vue 2 options `propsData` and `mocks`.
|
||||
- Models and utils can be tested without mounting anything, see `pkg/harvester/models/__tests__` for examples.
|
||||
@@ -0,0 +1,46 @@
|
||||
// Same settings in every environment, otherwise tests that format dates depend on the machine
|
||||
process.env.TZ = 'UTC';
|
||||
|
||||
// The setup follows the one of the Rancher dashboard and of the Rancher extension template (rancher/ui-plugin-examples)
|
||||
module.exports = {
|
||||
roots: ['<rootDir>/pkg'],
|
||||
testEnvironment: 'jsdom',
|
||||
// Jest 28+ (jest-environment-jsdom) defaults package resolution to the "browser" export condition, which makes
|
||||
// packages like @vue/test-utils resolve their browser (global-Vue) build and throw "Vue is not defined".
|
||||
testEnvironmentOptions: { customExportConditions: ['node', 'node-addons'] },
|
||||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
||||
watchman: false,
|
||||
moduleFileExtensions: ['js', 'mjs', 'json', 'vue', 'ts'],
|
||||
modulePaths: ['<rootDir>'],
|
||||
moduleNameMapper: {
|
||||
'^~/(.*)$': '<rootDir>/$1',
|
||||
'^@/(.*)$': '<rootDir>/$1',
|
||||
'^@shell/(.*)$': '<rootDir>/node_modules/@rancher/shell/$1',
|
||||
'^@components/(.*)$': '<rootDir>/node_modules/@rancher/shell/rancher-components/$1',
|
||||
// At build time @pkg/<path> is resolved to the package that imports it (see vue.config.js of @rancher/shell)
|
||||
'^@pkg/harvester/(.*)$': '<rootDir>/pkg/harvester/$1',
|
||||
'^@pkg/(.*)$': '<rootDir>/pkg/harvester/$1',
|
||||
// clipboard-polyfill's package `exports` only declares an `import` condition, so map it to its ESM build
|
||||
// (transpiled via transformIgnorePatterns below)
|
||||
'^clipboard-polyfill$': '<rootDir>/node_modules/clipboard-polyfill/dist/es6/clipboard-polyfill.es6.js',
|
||||
'\\.(jpe?g|png|gif|webp|svg|mp4|webm|ogg|mp3|wav|flac|aac|woff2?|eot|ttf|otf)$': '<rootDir>/svgTransform.js',
|
||||
},
|
||||
modulePathIgnorePatterns: ['<rootDir>/pkg/harvester/node_modules'],
|
||||
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>(/.*)*/__tests__/utils/'],
|
||||
transform: {
|
||||
// vue3-jest, but with TypeScript registered for the Vue compiler first, see vue3JestRegisterTs.js
|
||||
'^.+\\.vue$': '<rootDir>/vue3JestRegisterTs.js',
|
||||
// isolatedModules: transpile only, the types are not checked while testing
|
||||
'^.+\\.tsx?$': ['ts-jest', { tsconfig: { sourceMap: true, isolatedModules: true } }],
|
||||
// Use the project babel config (babel.config.js, which extends the one of @rancher/shell)
|
||||
'^.+\\.js$': '<rootDir>/node_modules/babel-jest',
|
||||
// process mjs (e.g. vee-validate ESM) with babel-jest
|
||||
'^.+\\.mjs$': '<rootDir>/node_modules/babel-jest',
|
||||
'^.+\\.svg$': '<rootDir>/svgTransform.js',
|
||||
},
|
||||
transformIgnorePatterns: [
|
||||
// @rancher/shell is shipped untranspiled, the other packages are ESM-only. @replit/codemirror-vim-core is
|
||||
// required by the CommonJS build of @replit/codemirror-vim, which the shell's YamlEditor imports
|
||||
'/node_modules/(?!(@rancher/shell|color|color-string|color-convert|color-name|vee-validate|@vee-validate|clipboard-polyfill|intl-messageformat|@formatjs|@replit/codemirror-vim-core)/)',
|
||||
],
|
||||
};
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/* eslint-env jest */
|
||||
import { createApp } from 'vue';
|
||||
import { config } from '@vue/test-utils';
|
||||
import i18n from '@shell/plugins/i18n';
|
||||
import FloatingVue from 'floating-vue';
|
||||
import { floatingVueOptions } from '@shell/plugins/floating-vue';
|
||||
import vSelect from 'vue-select';
|
||||
import cleanTooltipDirective from '@shell/directives/clean-tooltip';
|
||||
import cleanHtmlDirective from '@shell/directives/clean-html';
|
||||
import htmlStrippedAriaLabelDirective from '@shell/directives/strip-html-aria-label';
|
||||
import '@shell/plugins/replaceall';
|
||||
import { TextEncoder, TextDecoder } from 'util';
|
||||
|
||||
const vueApp = createApp({});
|
||||
|
||||
global.TextEncoder = TextEncoder;
|
||||
global.TextDecoder = TextDecoder;
|
||||
|
||||
// vueApp.config.productionTip = false;
|
||||
vueApp.use(i18n, { store: { dispatch() {} } });
|
||||
vueApp.use(FloatingVue, floatingVueOptions);
|
||||
vueApp.directive('clean-html', cleanHtmlDirective);
|
||||
vueApp.directive('clean-tooltip', cleanTooltipDirective);
|
||||
vueApp.component('v-select', vSelect);
|
||||
|
||||
config.global.components['v-select'] = vSelect;
|
||||
config.global.plugins = [FloatingVue];
|
||||
config.global.mocks['t'] = (key) => `%${ key }%`;
|
||||
config.global.mocks['$store'] = {
|
||||
getters: {},
|
||||
dispatch: jest.fn(),
|
||||
commit: jest.fn(),
|
||||
};
|
||||
|
||||
config.global.directives = {
|
||||
...config.global.directives,
|
||||
t: {
|
||||
mounted(el, binding) {
|
||||
el.textContent = `%${ binding.value }%`;
|
||||
},
|
||||
updated(el, binding) {
|
||||
el.textContent = `%${ binding.value }%`;
|
||||
}
|
||||
},
|
||||
'clean-tooltip': cleanTooltipDirective,
|
||||
'clean-html': cleanHtmlDirective,
|
||||
'stripped-aria-label': htmlStrippedAriaLabelDirective,
|
||||
};
|
||||
|
||||
config.global.stubs['t'] = { template: '<span><slot /></span>' };
|
||||
|
||||
/**
|
||||
* Global configuration for Jest tests
|
||||
*/
|
||||
beforeAll(() => {
|
||||
// matchMedia and getContext methods aren't included in jest's version of jsdom for us to mock
|
||||
// implemented as per jest documentation: https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||
Object.defineProperty(window, 'matchMedia', {
|
||||
value: jest.fn().mockImplementation(() => ({
|
||||
addListener: jest.fn(),
|
||||
removeListener: jest.fn(),
|
||||
addEventListener: jest.fn(),
|
||||
removeEventListener: jest.fn()
|
||||
}))
|
||||
});
|
||||
Object.defineProperty(HTMLCanvasElement.prototype, 'getContext', {
|
||||
value: jest.fn().mockImplementation(() => ({
|
||||
createLinearGradient: jest.fn(),
|
||||
fillRect: jest.fn(),
|
||||
getImageData: jest.fn(() => ({ data: [] }))
|
||||
}))
|
||||
});
|
||||
Object.defineProperty(window, 'IntersectionObserver', {
|
||||
writable: true,
|
||||
value: jest.fn().mockImplementation(() => ({
|
||||
observe: jest.fn(),
|
||||
unobserve: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
})),
|
||||
});
|
||||
});
|
||||
jest.mock('@shell/composables/useI18n', () => {
|
||||
return {
|
||||
useI18n() {
|
||||
return { t: (key, options) => `${ key }${ options ? `-${ JSON.stringify(options) }` : '' }` };
|
||||
}
|
||||
};
|
||||
});
|
||||
// eslint-disable-next-line no-console
|
||||
jest.spyOn(console, 'warn').mockImplementation((warning) => warning.includes('[Vue warn]') ? null : console.log(warning));
|
||||
|
||||
/**
|
||||
* Common initialization for each test, required for resetting states
|
||||
*/
|
||||
beforeEach(() => {
|
||||
// jest.resetModules(); // Use this function inside your test if you need to remove any cache stored
|
||||
// jest.clearAllMocks(); // Use this function inside your test if you need to reset mocks
|
||||
jest.restoreAllMocks(); // Use this function inside your test if you need to reset mocks and restore existing functionality
|
||||
|
||||
// Mock the $extension object
|
||||
// config.mocks['$extension'] = { getDynamic: () => undefined };
|
||||
|
||||
config.global.mocks['$store'] = { getters: { 'i18n/t': jest.fn() } };
|
||||
// Overrides some components
|
||||
// config.stubs['my-component'] = { template: "<div></div> "};
|
||||
});
|
||||
+16
-4
@@ -1,13 +1,14 @@
|
||||
{
|
||||
"name": "harvester-ui-extension",
|
||||
"version": "1.10.0-dev",
|
||||
"version": "1.10.0-rc1",
|
||||
"private": false,
|
||||
"engines": {
|
||||
"node": ">=24.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/plugin-transform-class-static-block": "7.29.7",
|
||||
"@rancher/shell": "3.0.13",
|
||||
"@novnc/novnc": "1.7.0",
|
||||
"@rancher/shell": "3.0.14",
|
||||
"@vue-flow/background": "^1.3.0",
|
||||
"@vue-flow/controls": "^1.1.1",
|
||||
"@vue-flow/core": "^1.33.5",
|
||||
@@ -27,7 +28,8 @@
|
||||
"yaml": "^2.5.1"
|
||||
},
|
||||
"resolutions": {
|
||||
"@types/node": "25.9.5",
|
||||
"@novnc/novnc": "1.7.0",
|
||||
"@types/node": "25.9.6",
|
||||
"cronstrue": "2.59.0",
|
||||
"d3-color": "3.1.0",
|
||||
"ejs": "3.1.10",
|
||||
@@ -50,6 +52,8 @@
|
||||
"clean": "./node_modules/@rancher/shell/scripts/clean",
|
||||
"lint": "./node_modules/@rancher/shell/scripts/lint --max-warnings 0 --ext .js,.ts,.vue .",
|
||||
"lint:fix": "./node_modules/@rancher/shell/scripts/lint --fix --max-warnings 0 --ext .js,.ts,.vue .",
|
||||
"test": "jest --watch",
|
||||
"test:ci": "NODE_OPTIONS=--max_old_space_size=8192 jest --silent",
|
||||
"build-pkg": "./node_modules/@rancher/shell/scripts/build-pkg.sh",
|
||||
"serve-pkgs": "./node_modules/@rancher/shell/scripts/serve-pkgs",
|
||||
"publish-pkgs": "./node_modules/@rancher/shell/scripts/extension/publish",
|
||||
@@ -66,6 +70,14 @@
|
||||
"@commitlint/config-conventional": "^19.8.1",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^7.1.0",
|
||||
"husky": "^9.1.7"
|
||||
"husky": "^9.1.7",
|
||||
"@types/jest": "29.5.12",
|
||||
"@vue/test-utils": "2.4.6",
|
||||
"@vue/vue3-jest": "29.2.6",
|
||||
"babel-jest": "29.7.0",
|
||||
"babel-plugin-transform-require-context": "0.1.1",
|
||||
"jest": "29.7.0",
|
||||
"jest-environment-jsdom": "29.7.0",
|
||||
"ts-jest": "29.4.12"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.8 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.8 KiB |
@@ -128,6 +128,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
|
||||
this.cancel();
|
||||
} catch (err) {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { docLink } from '../utils/feature-flags';
|
||||
const CATEGORY = {
|
||||
ui: [
|
||||
'branding',
|
||||
HCI_SETTING.SERVER_FLAVOR,
|
||||
'ui-source',
|
||||
'ui-index',
|
||||
]
|
||||
@@ -53,7 +54,7 @@ export default {
|
||||
};
|
||||
},
|
||||
|
||||
computed: { ...mapGetters({ t: 'i18n/t' }) },
|
||||
computed: { ...mapGetters({ t: 'i18n/t', isHarvesterPrime: 'harvester-common/isHarvesterPrime' }) },
|
||||
|
||||
watch: {
|
||||
settings: {
|
||||
@@ -269,7 +270,8 @@ export default {
|
||||
v-if="!setting.hide"
|
||||
class="settings-value"
|
||||
>
|
||||
<pre v-if="setting.kind === 'json'">{{ setting.json }}</pre>
|
||||
<pre v-if="setting.id === 'branding' && isHarvesterPrime">{{ $store.getters['harvester-common/privateLabel'] }}</pre>
|
||||
<pre v-else-if="setting.kind === 'json'">{{ setting.json }}</pre>
|
||||
<pre v-else-if="setting.kind === 'multiline'">{{ setting.data.value || setting.data.default }}</pre>
|
||||
<pre v-else-if="setting.kind === 'enum'">{{ t(setting.enum) }}</pre>
|
||||
<pre v-else-if="setting.kind === 'custom' && setting.custom">{{ setting.custom }}</pre>
|
||||
|
||||
@@ -1,153 +1,540 @@
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="connected && disconnected">
|
||||
<main class="main-layout error">
|
||||
<div class="text-center">
|
||||
<BrandImage
|
||||
file-name="error-desert-landscape.svg"
|
||||
width="900"
|
||||
height="300"
|
||||
/>
|
||||
<h1>
|
||||
{{ t('generic.notification.title.warning') }}
|
||||
</h1>
|
||||
<h2 class="text-secondary mt-20">
|
||||
{{ t('vncConsole.error.message') }}
|
||||
</h2>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div v-if="reconnecting">
|
||||
<main class="main-layout">
|
||||
<div class="text-center">
|
||||
<h2 class="text-secondary mt-20">
|
||||
{{ t('vncConsole.reconnecting.message') }}:{{ retryTimes }} of {{ maximumRetryTimes }}
|
||||
</h2>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
<div
|
||||
ref="view"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import RFB from '@novnc/novnc/core/rfb';
|
||||
import BrandImage from '@shell/components/BrandImage';
|
||||
import ModalWithCard from '@shell/components/ModalWithCard';
|
||||
import ZoomableRFB from './ZoomableRFB';
|
||||
|
||||
export const CONSOLE_STATUS = {
|
||||
CONNECTING: 'connecting',
|
||||
CONNECTED: 'connected',
|
||||
RECONNECTING: 'reconnecting',
|
||||
DISCONNECTED: 'disconnected',
|
||||
FAILED: 'failed',
|
||||
};
|
||||
|
||||
export const CONSOLE_FAILURE = {
|
||||
IN_USE: 'inUse',
|
||||
UNAVAILABLE: 'unavailable',
|
||||
DROPPED: 'dropped',
|
||||
ERROR: 'error',
|
||||
};
|
||||
|
||||
const MAXIMUM_RETRY_TIMES = 10;
|
||||
const BASE_RECONNECT_DELAY = 1000;
|
||||
const MAXIMUM_RECONNECT_DELAY = 30000;
|
||||
|
||||
const clampLevel = (value, fallback) => {
|
||||
const level = Number.parseInt(value, 10);
|
||||
|
||||
if (Number.isNaN(level)) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return Math.min(Math.max(level, 0), 9);
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'NovncConsole',
|
||||
|
||||
components: { ModalWithCard },
|
||||
|
||||
props: {
|
||||
url: {
|
||||
type: String,
|
||||
default: ''
|
||||
}
|
||||
},
|
||||
|
||||
settings: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
|
||||
// KubeVirt honours preserveSession from v1.6.3. Older versions ignore it, so every
|
||||
// connection takes the console over and automatic retries would kick the other user.
|
||||
preserveSession: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
|
||||
vmRunning: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
},
|
||||
|
||||
components: { BrandImage },
|
||||
emits: ['status-changed', 'capabilities'],
|
||||
|
||||
data() {
|
||||
return {
|
||||
rfb: null,
|
||||
connected: false,
|
||||
disconnected: false,
|
||||
reconnectDelay: 3000,
|
||||
reconnecting: false,
|
||||
maximumRetryTimes: 10,
|
||||
status: CONSOLE_STATUS.CONNECTING,
|
||||
statusDetail: '',
|
||||
desktopName: '',
|
||||
retryTimes: 0,
|
||||
setTimeout: null,
|
||||
maximumRetryTimes: MAXIMUM_RETRY_TIMES,
|
||||
reconnectTimer: null,
|
||||
isClosed: false,
|
||||
failure: '',
|
||||
showTakeOverModal: false,
|
||||
focused: false,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
statusInfo() {
|
||||
return {
|
||||
status: this.status,
|
||||
detail: this.statusDetail,
|
||||
desktopName: this.desktopName,
|
||||
retryTimes: this.retryTimes,
|
||||
maximumRetryTimes: this.maximumRetryTimes,
|
||||
};
|
||||
},
|
||||
|
||||
showError() {
|
||||
return this.status === CONSOLE_STATUS.FAILED || (this.status === CONSOLE_STATUS.DISCONNECTED && this.failure === CONSOLE_FAILURE.DROPPED);
|
||||
},
|
||||
|
||||
canTakeOver() {
|
||||
return this.preserveSession && !this.isClosed;
|
||||
},
|
||||
|
||||
failureTitle() {
|
||||
return this.t(`harvester.virtualMachine.detail.console.failure.${ this.failure || CONSOLE_FAILURE.ERROR }`);
|
||||
},
|
||||
|
||||
showReconnecting() {
|
||||
return this.status === CONSOLE_STATUS.RECONNECTING;
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
url() {
|
||||
this.reconnect();
|
||||
},
|
||||
|
||||
settings: {
|
||||
deep: true,
|
||||
handler: 'applySettings'
|
||||
},
|
||||
|
||||
statusInfo: {
|
||||
immediate: true,
|
||||
handler(neu) {
|
||||
this.$emit('status-changed', neu);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
// noVNC hides the canvas focus outline, so track focus to show where typing goes.
|
||||
this.$refs.view.addEventListener('focusin', this.onFocusIn);
|
||||
this.$refs.view.addEventListener('focusout', this.onFocusOut);
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.connect();
|
||||
});
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
this.clearTimeout();
|
||||
this.$refs.view?.removeEventListener('focusin', this.onFocusIn);
|
||||
this.$refs.view?.removeEventListener('focusout', this.onFocusOut);
|
||||
this.isClosed = true;
|
||||
this.clearReconnectTimer();
|
||||
this.teardown();
|
||||
},
|
||||
|
||||
methods: {
|
||||
connect() {
|
||||
const rfb = new RFB(this.$refs.view, this.url);
|
||||
connect(takeOver = false) {
|
||||
if (!this.url || this.isClosed) {
|
||||
return;
|
||||
}
|
||||
|
||||
rfb.addEventListener('connect', () => {
|
||||
this.clearTimeout();
|
||||
this.teardown();
|
||||
|
||||
this.connected = true;
|
||||
this.retryTimes = 0;
|
||||
this.reconnecting = false;
|
||||
});
|
||||
this.failure = '';
|
||||
this.status = this.retryTimes > 0 ? CONSOLE_STATUS.RECONNECTING : CONSOLE_STATUS.CONNECTING;
|
||||
|
||||
rfb.addEventListener('disconnect', (e) => {
|
||||
this.clearTimeout();
|
||||
let rfb;
|
||||
|
||||
this.disconnected = true;
|
||||
this.rfb = null;
|
||||
this.reconnect();
|
||||
});
|
||||
try {
|
||||
const url = new URL(this.url);
|
||||
|
||||
if (this.preserveSession) {
|
||||
url.searchParams.set('preserveSession', takeOver === true ? 'false' : 'true');
|
||||
}
|
||||
rfb = new ZoomableRFB(this.$refs.view, url.href, { shared: true });
|
||||
} catch (err) {
|
||||
this.statusDetail = err?.message || `${ err }`;
|
||||
this.status = CONSOLE_STATUS.FAILED;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
rfb.addEventListener('connect', this.onConnect);
|
||||
rfb.addEventListener('disconnect', this.onDisconnect);
|
||||
rfb.addEventListener('securityfailure', this.onSecurityFailure);
|
||||
rfb.addEventListener('credentialsrequired', this.onCredentialsRequired);
|
||||
rfb.addEventListener('desktopname', this.onDesktopName);
|
||||
rfb.addEventListener('capabilities', this.onCapabilities);
|
||||
|
||||
this.rfb = rfb;
|
||||
this.applySettings();
|
||||
},
|
||||
|
||||
reconnect() {
|
||||
this.clearReconnectTimer();
|
||||
|
||||
this.isClosed = false;
|
||||
this.retryTimes = 0;
|
||||
this.statusDetail = '';
|
||||
this.connect();
|
||||
},
|
||||
|
||||
takeOver() {
|
||||
this.showTakeOverModal = true;
|
||||
},
|
||||
|
||||
cancelTakeOver() {
|
||||
this.showTakeOverModal = false;
|
||||
},
|
||||
|
||||
confirmTakeOver() {
|
||||
this.showTakeOverModal = false;
|
||||
this.clearReconnectTimer();
|
||||
this.isClosed = false;
|
||||
this.retryTimes = 0;
|
||||
this.statusDetail = '';
|
||||
this.connect(true);
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
this.isClosed = true;
|
||||
this.clearReconnectTimer();
|
||||
this.teardown();
|
||||
this.status = CONSOLE_STATUS.DISCONNECTED;
|
||||
},
|
||||
|
||||
onConnect() {
|
||||
this.clearReconnectTimer();
|
||||
|
||||
this.retryTimes = 0;
|
||||
this.statusDetail = '';
|
||||
this.status = CONSOLE_STATUS.CONNECTED;
|
||||
this.applySettings();
|
||||
this.focus();
|
||||
},
|
||||
|
||||
focus() {
|
||||
this.rfb?.focus();
|
||||
},
|
||||
|
||||
onFocusIn() {
|
||||
this.focused = true;
|
||||
},
|
||||
|
||||
onFocusOut() {
|
||||
this.focused = false;
|
||||
},
|
||||
|
||||
onDisconnect() {
|
||||
const wasConnected = this.status === CONSOLE_STATUS.CONNECTED;
|
||||
const wasRetrying = this.status === CONSOLE_STATUS.RECONNECTING;
|
||||
|
||||
this.teardown(false);
|
||||
|
||||
if (this.isClosed) {
|
||||
if (this.status !== CONSOLE_STATUS.FAILED) {
|
||||
this.status = CONSOLE_STATUS.DISCONNECTED;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (wasConnected && !this.preserveSession) {
|
||||
// Without preserveSession a retry would take the console back from whoever
|
||||
// opened it, and the two sessions would keep kicking each other out.
|
||||
this.clearReconnectTimer();
|
||||
this.failure = CONSOLE_FAILURE.DROPPED;
|
||||
this.statusDetail = this.t('harvester.virtualMachine.detail.console.failureDetail.dropped');
|
||||
this.status = CONSOLE_STATUS.DISCONNECTED;
|
||||
} else if (wasConnected) {
|
||||
this.scheduleReconnect();
|
||||
} else if (wasRetrying) {
|
||||
// Retries use preserveSession, so they fail while another session owns the
|
||||
// console. Keep retrying so the console is picked up once it is released,
|
||||
// instead of kicking the other session back out.
|
||||
this.statusDetail = this.t('harvester.virtualMachine.detail.console.status.inUse');
|
||||
this.scheduleReconnect();
|
||||
} else {
|
||||
this.clearReconnectTimer();
|
||||
this.fail(this.preserveSession && this.vmRunning ? CONSOLE_FAILURE.IN_USE : CONSOLE_FAILURE.UNAVAILABLE);
|
||||
}
|
||||
},
|
||||
|
||||
// The browser cannot see why a WebSocket handshake failed. With preserveSession and a
|
||||
// running VM, a refused connection almost always means another session holds the console.
|
||||
fail(failure, detail) {
|
||||
this.failure = failure;
|
||||
this.statusDetail = detail ?? this.t(`harvester.virtualMachine.detail.console.failureDetail.${ failure }`);
|
||||
this.status = CONSOLE_STATUS.FAILED;
|
||||
},
|
||||
|
||||
// Authentication problems will not fix themselves, so stop retrying.
|
||||
onSecurityFailure(e) {
|
||||
this.isClosed = true;
|
||||
this.clearReconnectTimer();
|
||||
this.fail(CONSOLE_FAILURE.ERROR, e?.detail?.reason || '');
|
||||
},
|
||||
|
||||
// noVNC pauses the handshake until credentials are sent, so close the socket
|
||||
// to avoid holding the console while the failure is shown.
|
||||
onCredentialsRequired() {
|
||||
this.isClosed = true;
|
||||
this.clearReconnectTimer();
|
||||
this.teardown();
|
||||
this.fail(CONSOLE_FAILURE.ERROR, this.t('harvester.virtualMachine.detail.console.status.credentialsRequired'));
|
||||
},
|
||||
|
||||
onDesktopName(e) {
|
||||
this.desktopName = e?.detail?.name || '';
|
||||
},
|
||||
|
||||
onCapabilities(e) {
|
||||
this.$emit('capabilities', e?.detail?.capabilities || {});
|
||||
},
|
||||
|
||||
scheduleReconnect() {
|
||||
this.clearReconnectTimer();
|
||||
|
||||
if (this.isClosed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.retryTimes >= this.maximumRetryTimes) {
|
||||
this.reconnecting = false;
|
||||
this.connected = true;
|
||||
this.disconnected = true;
|
||||
this.fail(this.vmRunning ? CONSOLE_FAILURE.IN_USE : CONSOLE_FAILURE.UNAVAILABLE);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.retryTimes += 1;
|
||||
this.reconnecting = true;
|
||||
this.connected = false;
|
||||
this.disconnected = false;
|
||||
this.status = CONSOLE_STATUS.RECONNECTING;
|
||||
|
||||
this.setTimeout = setTimeout(() => {
|
||||
const delay = Math.min(BASE_RECONNECT_DELAY * (2 ** (this.retryTimes - 1)), MAXIMUM_RECONNECT_DELAY);
|
||||
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
this.reconnectTimer = null;
|
||||
this.connect();
|
||||
}, this.reconnectDelay);
|
||||
}, delay);
|
||||
},
|
||||
|
||||
clearTimeout() {
|
||||
if (this.setTimeout) {
|
||||
clearTimeout(this.setTimeout);
|
||||
clearReconnectTimer() {
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
},
|
||||
|
||||
disconnect() {
|
||||
this.rfb.disconnect();
|
||||
teardown(disconnect = true) {
|
||||
const rfb = this.rfb;
|
||||
|
||||
if (!rfb) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.rfb = null;
|
||||
|
||||
rfb.removeEventListener('connect', this.onConnect);
|
||||
rfb.removeEventListener('disconnect', this.onDisconnect);
|
||||
rfb.removeEventListener('securityfailure', this.onSecurityFailure);
|
||||
rfb.removeEventListener('credentialsrequired', this.onCredentialsRequired);
|
||||
rfb.removeEventListener('desktopname', this.onDesktopName);
|
||||
rfb.removeEventListener('capabilities', this.onCapabilities);
|
||||
|
||||
if (!disconnect) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
rfb.disconnect();
|
||||
} catch (err) {
|
||||
// The socket may already be gone, nothing left to clean up.
|
||||
}
|
||||
},
|
||||
|
||||
applySettings() {
|
||||
const rfb = this.rfb;
|
||||
|
||||
if (!rfb) {
|
||||
return;
|
||||
}
|
||||
|
||||
const settings = this.settings || {};
|
||||
|
||||
rfb.viewOnly = !!settings.viewOnly;
|
||||
rfb.scaleViewport = !!settings.scaleViewport;
|
||||
rfb.resizeSession = !!settings.resizeSession;
|
||||
rfb.clipViewport = !!settings.clipViewport;
|
||||
rfb.dragViewport = !!settings.dragViewport;
|
||||
rfb.zoomPercent = settings.zoomPercent;
|
||||
rfb.focusOnClick = settings.focusOnClick !== false;
|
||||
rfb.qualityLevel = clampLevel(settings.qualityLevel, 6);
|
||||
rfb.compressionLevel = clampLevel(settings.compressionLevel, 2);
|
||||
},
|
||||
|
||||
ctrlAltDelete() {
|
||||
this.rfb.sendCtrlAltDel();
|
||||
this.rfb?.sendCtrlAltDel();
|
||||
},
|
||||
|
||||
sendKey(keysym, code, down) {
|
||||
this.rfb.sendKey(keysym, code, down);
|
||||
}
|
||||
this.rfb?.sendKey(keysym, code, down);
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="novnc-console">
|
||||
<div
|
||||
ref="view"
|
||||
class="novnc-screen"
|
||||
:class="{ 'is-focused': focused }"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="showError || showReconnecting"
|
||||
class="novnc-overlay"
|
||||
>
|
||||
<div
|
||||
v-if="showError"
|
||||
class="novnc-overlay__card text-center"
|
||||
>
|
||||
<h3>
|
||||
{{ failureTitle }}
|
||||
</h3>
|
||||
<p
|
||||
v-if="statusDetail"
|
||||
class="mt-10"
|
||||
>
|
||||
{{ statusDetail }}
|
||||
</p>
|
||||
<button
|
||||
class="btn role-primary mt-20"
|
||||
@click="reconnect"
|
||||
>
|
||||
{{ t('harvester.action.reconnect') }}
|
||||
</button>
|
||||
<button
|
||||
v-if="canTakeOver"
|
||||
class="btn role-secondary mt-20 ml-10"
|
||||
@click="takeOver"
|
||||
>
|
||||
{{ t('harvester.virtualMachine.detail.console.takeOver.label') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else
|
||||
class="text-center"
|
||||
>
|
||||
<h2>
|
||||
{{ t('vncConsole.reconnecting.message') }}:{{ retryTimes }} of {{ maximumRetryTimes }}
|
||||
</h2>
|
||||
<p
|
||||
v-if="statusDetail"
|
||||
class="mt-10"
|
||||
>
|
||||
{{ statusDetail }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ModalWithCard
|
||||
v-if="showTakeOverModal"
|
||||
name="takeOverConsole"
|
||||
:width="480"
|
||||
@finish="cancelTakeOver"
|
||||
>
|
||||
<template #title>
|
||||
{{ t('harvester.virtualMachine.detail.console.takeOver.title') }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<p>{{ t('harvester.virtualMachine.detail.console.takeOver.confirm') }}</p>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="take-over-actions">
|
||||
<button
|
||||
class="btn role-secondary mr-10"
|
||||
@click="cancelTakeOver"
|
||||
>
|
||||
{{ t('generic.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
class="btn role-primary"
|
||||
@click="confirmTakeOver"
|
||||
>
|
||||
{{ t('harvester.virtualMachine.detail.console.takeOver.label') }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</ModalWithCard>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.error {
|
||||
.novnc-console {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
height: 100%;
|
||||
padding: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.row {
|
||||
align-items: center;
|
||||
.novnc-screen {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.novnc-overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: auto;
|
||||
background: rgba(0, 0, 0, 0.75);
|
||||
// The overlay is always dark, so its text cannot follow the theme's text colours.
|
||||
color: #fff;
|
||||
|
||||
h2,
|
||||
h3 {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 5rem;
|
||||
p {
|
||||
color: rgba(255, 255, 255, 0.8);
|
||||
}
|
||||
|
||||
.desert-landscape {
|
||||
img {
|
||||
max-width: 100%;
|
||||
}
|
||||
&__card {
|
||||
max-width: 480px;
|
||||
padding: 0 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.take-over-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
// noVNC sets an inline `outline: none` on its canvas, so mark keyboard focus with a ring instead.
|
||||
.novnc-screen.is-focused canvas {
|
||||
box-shadow: 0 0 0 2px var(--primary);
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import { STEVE } from '@shell/config/types';
|
||||
import ModalWithCard from '@shell/components/ModalWithCard';
|
||||
import { escapeHtml } from '@shell/utils/string';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
import KeyTable from '@novnc/novnc/core/input/keysym';
|
||||
@@ -8,9 +9,29 @@ import { HCI } from '../../types';
|
||||
import NovncConsole from './NovncConsole';
|
||||
import NovncConsoleItem from './NovncConsoleItem';
|
||||
import NovncConsoleCustomKeys from './NovncConsoleCustomKeys';
|
||||
import { normalizeZoom } from './ZoomableRFB';
|
||||
|
||||
const CONSOLE_SETTINGS_KEY = 'harvester-vnc-console-settings';
|
||||
const PREFERED_SHORTCUT_KEYS = 'prefered-shortcut-keys';
|
||||
|
||||
export const CONFIRM_ACTION = {
|
||||
CTRL_ALT_DEL: 'ctrlAltDel',
|
||||
SOFT_REBOOT: 'softReboot',
|
||||
};
|
||||
|
||||
const VIEW_MODE = {
|
||||
SCALE: 'scale',
|
||||
NONE: 'none',
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
viewMode: VIEW_MODE.NONE,
|
||||
zoomPercent: 100,
|
||||
viewOnly: false,
|
||||
qualityLevel: 6,
|
||||
compressionLevel: 2,
|
||||
};
|
||||
|
||||
const SHORT_KEYS = {
|
||||
ControlLeft: {
|
||||
label: 'Ctrl',
|
||||
@@ -106,7 +127,7 @@ const F_KEYS = {
|
||||
export default {
|
||||
name: 'NovncConsoleWrapper',
|
||||
components: {
|
||||
NovncConsole, NovncConsoleItem, NovncConsoleCustomKeys
|
||||
ModalWithCard, NovncConsole, NovncConsoleItem, NovncConsoleCustomKeys
|
||||
},
|
||||
|
||||
async fetch() {
|
||||
@@ -132,44 +153,68 @@ export default {
|
||||
keysRecord: [],
|
||||
vmResource: {},
|
||||
renderKeysModal: false,
|
||||
currentUser: null,
|
||||
hideCustomKeysBar: false,
|
||||
settings: { ...DEFAULT_SETTINGS },
|
||||
capabilities: {},
|
||||
isFullscreen: false,
|
||||
confirmAction: null,
|
||||
consoleStatus: {
|
||||
status: 'connecting',
|
||||
retryTimes: 0,
|
||||
maximumRetryTimes: 0,
|
||||
desktopName: '',
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
preference() {
|
||||
return this.$store.getters['management/all'](STEVE.PREFERENCE)?.[0];
|
||||
},
|
||||
|
||||
// Custom keys are stored in the user preference, which is not available everywhere.
|
||||
hideCustomKeysBar() {
|
||||
return !this.preference?.data;
|
||||
},
|
||||
|
||||
savedShortcutKeys() {
|
||||
const preference = this.$store.getters['management/all'](STEVE.PREFERENCE);
|
||||
const preferedShortcutKeys = preference?.[0]?.data?.[PREFERED_SHORTCUT_KEYS];
|
||||
let out = [];
|
||||
|
||||
if (!preference?.[0]?.data) {
|
||||
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
|
||||
this.hideCustomKeysBar = true;
|
||||
|
||||
return out;
|
||||
}
|
||||
const preferedShortcutKeys = this.preference?.data?.[PREFERED_SHORTCUT_KEYS];
|
||||
|
||||
if (!preferedShortcutKeys) {
|
||||
return out;
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
out = JSON.parse(preferedShortcutKeys);
|
||||
return JSON.parse(preferedShortcutKeys);
|
||||
} catch (err) {
|
||||
this.$store.dispatch('growl/fromError', {
|
||||
title: this.t('generic.notification.title.error', { name: escapeHtml(this.value.metadata.name) }),
|
||||
err,
|
||||
}, { root: true });
|
||||
return [];
|
||||
}
|
||||
},
|
||||
|
||||
return out;
|
||||
preferredShortcutKeys() {
|
||||
return (this.savedShortcutKeys || []).map((item) => {
|
||||
return {
|
||||
label: item.map((K) => K.key.charAt(0).toUpperCase() + K.key.slice(1)).join('+'),
|
||||
value: item
|
||||
};
|
||||
});
|
||||
},
|
||||
|
||||
canSendKeys() {
|
||||
return this.consoleStatus.status === 'connected' && !this.settings.viewOnly;
|
||||
},
|
||||
|
||||
isDown() {
|
||||
return this.isEmpty(this.value);
|
||||
},
|
||||
|
||||
preserveSession() {
|
||||
return !!this.$store.getters['harvester-common/getFeatureEnabled']('vncPreserveSession');
|
||||
},
|
||||
|
||||
vmRunning() {
|
||||
return this.value?.status?.phase === 'Running';
|
||||
},
|
||||
|
||||
url() {
|
||||
const ip = `${ window.location.hostname }:${ window.location.port }`;
|
||||
|
||||
@@ -192,13 +237,16 @@ export default {
|
||||
...F_KEYS,
|
||||
};
|
||||
|
||||
out.AltLeft.keys = { PrintScreen: FUNCTION_KEYS.PrintScreen, ...F_KEYS };
|
||||
out.ControlLeft.keys = {
|
||||
AltLeft: {
|
||||
...Object.assign(SHORT_KEYS.AltLeft, {}),
|
||||
keys: { Delete: FUNCTION_KEYS.Delete }
|
||||
out.AltLeft = { ...SHORT_KEYS.AltLeft, keys: { PrintScreen: FUNCTION_KEYS.PrintScreen, ...F_KEYS } };
|
||||
out.ControlLeft = {
|
||||
...SHORT_KEYS.ControlLeft,
|
||||
keys: {
|
||||
AltLeft: {
|
||||
...SHORT_KEYS.AltLeft,
|
||||
keys: { Delete: FUNCTION_KEYS.Delete }
|
||||
},
|
||||
...NORMAL_KEYS,
|
||||
},
|
||||
...NORMAL_KEYS,
|
||||
};
|
||||
|
||||
return out;
|
||||
@@ -208,14 +256,57 @@ export default {
|
||||
return !!this.vmResource?.actions?.softreboot;
|
||||
},
|
||||
|
||||
preferredShortcutKeys() {
|
||||
return (this.savedShortcutKeys || []).map((item) => {
|
||||
return {
|
||||
label: item.map((K) => K.key.charAt(0).toUpperCase() + K.key.slice(1)).join('+'),
|
||||
value: item
|
||||
};
|
||||
});
|
||||
rfbSettings() {
|
||||
return {
|
||||
viewOnly: this.settings.viewOnly,
|
||||
scaleViewport: this.settings.viewMode === VIEW_MODE.SCALE,
|
||||
zoomPercent: normalizeZoom(this.settings.zoomPercent),
|
||||
resizeSession: false,
|
||||
clipViewport: false,
|
||||
dragViewport: false,
|
||||
qualityLevel: this.settings.qualityLevel,
|
||||
compressionLevel: this.settings.compressionLevel,
|
||||
};
|
||||
},
|
||||
|
||||
viewModeOptions() {
|
||||
return Object.values(VIEW_MODE).map((value) => ({
|
||||
value,
|
||||
label: this.t(`harvester.virtualMachine.detail.console.settings.viewMode.${ value }`)
|
||||
}));
|
||||
},
|
||||
|
||||
statusLabel() {
|
||||
const { status, retryTimes, maximumRetryTimes } = this.consoleStatus;
|
||||
|
||||
if (status === 'reconnecting') {
|
||||
return this.t('harvester.virtualMachine.detail.console.status.reconnecting', { retryTimes, maximumRetryTimes });
|
||||
}
|
||||
|
||||
if (status === 'connected' && this.settings.viewOnly) {
|
||||
return this.t('harvester.virtualMachine.detail.console.status.connectedViewOnly');
|
||||
}
|
||||
|
||||
return this.t(`harvester.virtualMachine.detail.console.status.${ status }`);
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
settings: {
|
||||
deep: true,
|
||||
handler(neu) {
|
||||
window.localStorage.setItem(CONSOLE_SETTINGS_KEY, JSON.stringify(neu));
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.loadSettings();
|
||||
document.addEventListener('fullscreenchange', this.onFullscreenChange);
|
||||
},
|
||||
|
||||
beforeUnmount() {
|
||||
document.removeEventListener('fullscreenchange', this.onFullscreenChange);
|
||||
},
|
||||
|
||||
methods: {
|
||||
@@ -233,36 +324,39 @@ export default {
|
||||
|
||||
// Send function key, e.g. ALT + F
|
||||
sendKeys() {
|
||||
if (!this.canSendKeys || !this.$refs.novncConsole) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.keysRecord.forEach((key) => {
|
||||
this.$refs.novncConsole.sendKey(this.allKeys[key].value, key, true);
|
||||
});
|
||||
|
||||
this.keysRecord.reverse().forEach((key) => {
|
||||
[...this.keysRecord].reverse().forEach((key) => {
|
||||
this.$refs.novncConsole.sendKey(this.allKeys[key].value, key, false);
|
||||
});
|
||||
|
||||
this.$refs.popover.isOpen = false;
|
||||
this.$refs.popover.hide();
|
||||
this.keysRecord = [];
|
||||
this.$refs.novncConsole.focus();
|
||||
},
|
||||
|
||||
sendCustomKeys(keys) {
|
||||
if (!this.canSendKeys || !this.$refs.novncConsole) {
|
||||
return;
|
||||
}
|
||||
|
||||
const keyList = [].concat(keys);
|
||||
|
||||
keyList.forEach((K) => {
|
||||
this.$refs.novncConsole.sendKey(KeyboardUtil.getKeysym(K), KeyboardUtil.getKeycode(K), true);
|
||||
});
|
||||
|
||||
keyList.reverse().forEach((K) => {
|
||||
[...keyList].reverse().forEach((K) => {
|
||||
this.$refs.novncConsole.sendKey(KeyboardUtil.getKeysym(K), KeyboardUtil.getKeycode(K), false);
|
||||
});
|
||||
},
|
||||
|
||||
reconnect() {
|
||||
this.$refs.novncConsole.reconnect();
|
||||
},
|
||||
|
||||
softReboot() {
|
||||
this.vmResource.doSoftReboot();
|
||||
this.$refs.novncConsole.focus();
|
||||
},
|
||||
|
||||
showKeysModal() {
|
||||
@@ -272,116 +366,406 @@ export default {
|
||||
hideKeysModal() {
|
||||
this.renderKeysModal = false;
|
||||
},
|
||||
|
||||
reconnect() {
|
||||
this.$refs.novncConsole.reconnect();
|
||||
},
|
||||
|
||||
loadSettings() {
|
||||
try {
|
||||
const saved = JSON.parse(window.localStorage.getItem(CONSOLE_SETTINGS_KEY) || '{}');
|
||||
|
||||
this.settings = {
|
||||
viewMode: Object.values(VIEW_MODE).includes(saved?.viewMode) ? saved.viewMode : DEFAULT_SETTINGS.viewMode,
|
||||
zoomPercent: normalizeZoom(saved?.zoomPercent ?? DEFAULT_SETTINGS.zoomPercent),
|
||||
viewOnly: saved?.viewOnly === true,
|
||||
qualityLevel: saved?.qualityLevel ?? DEFAULT_SETTINGS.qualityLevel,
|
||||
compressionLevel: saved?.compressionLevel ?? DEFAULT_SETTINGS.compressionLevel,
|
||||
};
|
||||
} catch (err) {
|
||||
this.settings = { ...DEFAULT_SETTINGS };
|
||||
}
|
||||
},
|
||||
|
||||
onStatusChanged(info) {
|
||||
this.consoleStatus = info;
|
||||
},
|
||||
|
||||
onCapabilities(capabilities) {
|
||||
this.capabilities = capabilities;
|
||||
},
|
||||
|
||||
// Both can restart the VM with one click (Ctrl+Alt+Del reboots most Linux guests), so ask first.
|
||||
ctrlAltDelete() {
|
||||
if (this.canSendKeys) {
|
||||
this.confirmAction = CONFIRM_ACTION.CTRL_ALT_DEL;
|
||||
}
|
||||
},
|
||||
|
||||
softReboot() {
|
||||
this.confirmAction = CONFIRM_ACTION.SOFT_REBOOT;
|
||||
},
|
||||
|
||||
// The modal returns focus to the console canvas (return-focus-selector) once it closes.
|
||||
cancelConfirm() {
|
||||
this.confirmAction = null;
|
||||
},
|
||||
|
||||
runConfirmedAction() {
|
||||
const action = this.confirmAction;
|
||||
|
||||
this.confirmAction = null;
|
||||
|
||||
if (action === CONFIRM_ACTION.CTRL_ALT_DEL && this.canSendKeys) {
|
||||
this.$refs.novncConsole?.ctrlAltDelete();
|
||||
} else if (action === CONFIRM_ACTION.SOFT_REBOOT) {
|
||||
this.vmResource.doSoftReboot();
|
||||
}
|
||||
},
|
||||
|
||||
async toggleFullscreen() {
|
||||
try {
|
||||
if (document.fullscreenElement) {
|
||||
await document.exitFullscreen();
|
||||
} else {
|
||||
await this.$refs.consoleContainer.requestFullscreen();
|
||||
// Keyboard lock lets shortcuts such as Ctrl+W and F11 reach the guest.
|
||||
await navigator.keyboard?.lock?.(['KeyW', 'F11']);
|
||||
}
|
||||
} catch (err) {
|
||||
this.$store.dispatch('growl/fromError', {
|
||||
title: this.t('generic.notification.title.error', { name: escapeHtml(this.value.metadata.name) }),
|
||||
err,
|
||||
}, { root: true });
|
||||
}
|
||||
},
|
||||
|
||||
onFullscreenChange() {
|
||||
this.isFullscreen = !!document.fullscreenElement;
|
||||
|
||||
if (!this.isFullscreen) {
|
||||
navigator.keyboard?.unlock?.();
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div id="app">
|
||||
<div class="vm-console">
|
||||
<div
|
||||
ref="consoleContainer"
|
||||
class="vm-console"
|
||||
>
|
||||
<div class="combination-keys">
|
||||
<v-dropdown
|
||||
ref="popover"
|
||||
placement="top"
|
||||
trigger="click"
|
||||
:container="false"
|
||||
@auto-hide="keysRecord = []"
|
||||
>
|
||||
<button class="btn btn-sm bg-primary">
|
||||
{{ t("harvester.virtualMachine.detail.console.shortcutKeys") }}
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<novnc-console-item
|
||||
:items="keymap"
|
||||
:path="keysRecord"
|
||||
:pos="0"
|
||||
@update="update"
|
||||
@send-keys="sendKeys"
|
||||
/>
|
||||
</template>
|
||||
</v-dropdown>
|
||||
|
||||
<button
|
||||
v-if="hasSoftRebootAction"
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="softReboot"
|
||||
>
|
||||
{{ t("harvester.action.softreboot") }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="reconnect"
|
||||
>
|
||||
{{ t("harvester.action.reconnect") }}
|
||||
</button>
|
||||
|
||||
<v-dropdown
|
||||
v-if="!hideCustomKeysBar"
|
||||
ref="customKeyPopover"
|
||||
placement="top"
|
||||
trigger="click"
|
||||
:container="false"
|
||||
>
|
||||
<button class="btn btn-sm bg-primary">
|
||||
{{ t("harvester.virtualMachine.detail.console.customShortcutKeys") }}
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<div>
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="showKeysModal"
|
||||
>
|
||||
{{ t("harvester.virtualMachine.detail.console.management") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div
|
||||
v-for="(keys, index) in preferredShortcutKeys"
|
||||
:key="index"
|
||||
<div class="toolbar-group">
|
||||
<v-dropdown
|
||||
ref="popover"
|
||||
placement="top"
|
||||
trigger="click"
|
||||
:container="false"
|
||||
@auto-hide="keysRecord = []"
|
||||
>
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
:disabled="!canSendKeys"
|
||||
>
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="sendCustomKeys(keys.value)"
|
||||
>
|
||||
{{ keys.label }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</v-dropdown>
|
||||
{{ t("harvester.virtualMachine.detail.console.shortcutKeys") }}
|
||||
</button>
|
||||
|
||||
<NovncConsoleCustomKeys
|
||||
v-if="renderKeysModal"
|
||||
:current-user="currentUser"
|
||||
@close="hideKeysModal"
|
||||
/>
|
||||
<template #popper>
|
||||
<novnc-console-item
|
||||
:items="keymap"
|
||||
:path="keysRecord"
|
||||
:pos="0"
|
||||
@update="update"
|
||||
@send-keys="sendKeys"
|
||||
/>
|
||||
</template>
|
||||
</v-dropdown>
|
||||
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
:disabled="!canSendKeys"
|
||||
@click="ctrlAltDelete"
|
||||
>
|
||||
{{ t("harvester.virtualMachine.detail.console.ctrlAltDel") }}
|
||||
</button>
|
||||
|
||||
<v-dropdown
|
||||
v-if="!hideCustomKeysBar"
|
||||
placement="top"
|
||||
trigger="click"
|
||||
:container="false"
|
||||
>
|
||||
<button class="btn btn-sm bg-primary">
|
||||
{{ t("harvester.virtualMachine.detail.console.customShortcutKeys") }}
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<div>
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="showKeysModal"
|
||||
>
|
||||
{{ t("harvester.virtualMachine.detail.console.management") }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<div
|
||||
v-for="(keys, index) in preferredShortcutKeys"
|
||||
:key="index"
|
||||
>
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
:disabled="!canSendKeys"
|
||||
@click="sendCustomKeys(keys.value)"
|
||||
>
|
||||
{{ keys.label }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</v-dropdown>
|
||||
|
||||
<v-dropdown
|
||||
placement="top"
|
||||
trigger="click"
|
||||
:container="false"
|
||||
>
|
||||
<button class="btn btn-sm bg-primary">
|
||||
{{ t("harvester.virtualMachine.detail.console.settings.label") }}
|
||||
</button>
|
||||
|
||||
<template #popper>
|
||||
<div class="console-panel">
|
||||
<label>{{ t('harvester.virtualMachine.detail.console.settings.viewMode.label') }}</label>
|
||||
<div
|
||||
v-for="option in viewModeOptions"
|
||||
:key="option.value"
|
||||
>
|
||||
<label class="console-panel__option">
|
||||
<input
|
||||
v-model="settings.viewMode"
|
||||
type="radio"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label
|
||||
for="vnc-zoom"
|
||||
class="console-panel__zoom-label"
|
||||
>
|
||||
<span>{{ t('harvester.virtualMachine.detail.console.settings.zoom') }}</span>
|
||||
<span>{{ settings.zoomPercent }}%</span>
|
||||
</label>
|
||||
<input
|
||||
id="vnc-zoom"
|
||||
v-model.number="settings.zoomPercent"
|
||||
class="console-panel__zoom"
|
||||
type="range"
|
||||
min="50"
|
||||
max="200"
|
||||
step="10"
|
||||
:disabled="settings.viewMode === 'scale'"
|
||||
:aria-valuetext="`${ settings.zoomPercent }%`"
|
||||
>
|
||||
|
||||
<label class="console-panel__option">
|
||||
<input
|
||||
v-model="settings.viewOnly"
|
||||
type="checkbox"
|
||||
>
|
||||
{{ t('harvester.virtualMachine.detail.console.settings.viewOnly') }}
|
||||
</label>
|
||||
|
||||
<label
|
||||
for="vnc-quality"
|
||||
class="console-panel__zoom-label"
|
||||
>
|
||||
<span>{{ t('harvester.virtualMachine.detail.console.settings.quality') }}</span>
|
||||
<span>{{ settings.qualityLevel }}</span>
|
||||
</label>
|
||||
<input
|
||||
id="vnc-quality"
|
||||
v-model.number="settings.qualityLevel"
|
||||
class="console-panel__zoom"
|
||||
type="range"
|
||||
min="0"
|
||||
max="9"
|
||||
step="1"
|
||||
>
|
||||
|
||||
<label
|
||||
for="vnc-compression"
|
||||
class="console-panel__zoom-label"
|
||||
>
|
||||
<span>{{ t('harvester.virtualMachine.detail.console.settings.compression') }}</span>
|
||||
<span>{{ settings.compressionLevel }}</span>
|
||||
</label>
|
||||
<input
|
||||
id="vnc-compression"
|
||||
v-model.number="settings.compressionLevel"
|
||||
class="console-panel__zoom"
|
||||
type="range"
|
||||
min="0"
|
||||
max="9"
|
||||
step="1"
|
||||
>
|
||||
</div>
|
||||
</template>
|
||||
</v-dropdown>
|
||||
</div>
|
||||
|
||||
<div class="toolbar-group">
|
||||
<span
|
||||
class="console-status"
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
>{{ statusLabel }}</span>
|
||||
|
||||
<button
|
||||
v-if="hasSoftRebootAction"
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="softReboot"
|
||||
>
|
||||
{{ t("harvester.action.softreboot") }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="reconnect"
|
||||
>
|
||||
{{ t("harvester.action.reconnect") }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class="btn btn-sm bg-primary"
|
||||
@click="toggleFullscreen"
|
||||
>
|
||||
{{ isFullscreen ? t('harvester.virtualMachine.detail.console.fullscreen.exit') : t('harvester.virtualMachine.detail.console.fullscreen.enter') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<NovncConsole
|
||||
v-if="url && !isDown"
|
||||
ref="novncConsole"
|
||||
:url="url"
|
||||
:settings="rfbSettings"
|
||||
:preserve-session="preserveSession"
|
||||
:vm-running="vmRunning"
|
||||
@status-changed="onStatusChanged"
|
||||
@capabilities="onCapabilities"
|
||||
/>
|
||||
<p v-if="isDown">
|
||||
{{ t("harvester.virtualMachine.detail.console.down") }}
|
||||
</p>
|
||||
|
||||
<ModalWithCard
|
||||
v-if="confirmAction"
|
||||
name="confirmConsoleAction"
|
||||
:width="480"
|
||||
return-focus-selector=".novnc-screen canvas"
|
||||
@finish="cancelConfirm"
|
||||
>
|
||||
<template #title>
|
||||
{{ t(`harvester.virtualMachine.detail.console.confirm.${ confirmAction }.title`) }}
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<p>{{ t(`harvester.virtualMachine.detail.console.confirm.${ confirmAction }.message`) }}</p>
|
||||
</template>
|
||||
|
||||
<template #footer>
|
||||
<div class="confirm-actions">
|
||||
<button
|
||||
class="btn role-secondary mr-10"
|
||||
@click="cancelConfirm"
|
||||
>
|
||||
{{ t('generic.cancel') }}
|
||||
</button>
|
||||
<button
|
||||
class="btn role-primary"
|
||||
data-testid="vnc-confirm-action"
|
||||
@click="runConfirmedAction"
|
||||
>
|
||||
{{ t(`harvester.virtualMachine.detail.console.confirm.${ confirmAction }.button`) }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
</ModalWithCard>
|
||||
|
||||
<NovncConsoleCustomKeys
|
||||
v-if="renderKeysModal"
|
||||
@close="hideKeysModal"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.vm-console {
|
||||
height: 100%;
|
||||
height: 100vh;
|
||||
height: 100dvh;
|
||||
display: grid;
|
||||
grid-template-rows: 30px auto;
|
||||
grid-template-rows: 32px minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.combination-keys {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
background: rgb(40, 40, 40);
|
||||
}
|
||||
|
||||
.toolbar-group {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.confirm-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.console-status {
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
margin-right: 8px;
|
||||
}
|
||||
|
||||
.console-panel {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 260px;
|
||||
padding: 4px;
|
||||
|
||||
&__zoom-label {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
margin-top: 8px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
&__zoom {
|
||||
width: 100%;
|
||||
margin: 4px 0 8px;
|
||||
}
|
||||
|
||||
&__option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
margin: 2px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import RFB from '@novnc/novnc/core/rfb';
|
||||
|
||||
export function normalizeZoom(value) {
|
||||
const percent = Number(value);
|
||||
|
||||
if (!Number.isFinite(percent)) {
|
||||
return 100;
|
||||
}
|
||||
|
||||
return Math.min(200, Math.max(50, Math.round(percent / 10) * 10));
|
||||
}
|
||||
|
||||
export default class ZoomableRFB extends RFB {
|
||||
get zoomPercent() {
|
||||
return this._zoomPercent ?? 100;
|
||||
}
|
||||
|
||||
set zoomPercent(value) {
|
||||
this._zoomPercent = normalizeZoom(value);
|
||||
this._updateScale();
|
||||
}
|
||||
|
||||
_updateScale() {
|
||||
if (this.scaleViewport) {
|
||||
super._updateScale();
|
||||
} else {
|
||||
this._display.scale = this.zoomPercent / 100;
|
||||
this._fixScrollbars();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import NovncConsole, { CONSOLE_STATUS, CONSOLE_FAILURE } from '../NovncConsole.vue';
|
||||
|
||||
const mockInstances = [];
|
||||
|
||||
jest.mock('../ZoomableRFB', () => {
|
||||
return jest.fn().mockImplementation((el, url) => {
|
||||
const listeners = {};
|
||||
const rfb = {
|
||||
url,
|
||||
addEventListener: jest.fn((name, cb) => {
|
||||
listeners[name] = cb;
|
||||
}),
|
||||
removeEventListener: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
focus: jest.fn(),
|
||||
emit: (name, detail) => listeners[name]?.({ detail }),
|
||||
};
|
||||
|
||||
mockInstances.push(rfb);
|
||||
|
||||
return rfb;
|
||||
});
|
||||
});
|
||||
|
||||
const URL = 'wss://example.com/apis/subresources.kubevirt.io/v1/namespaces/default/virtualmachineinstances/vm/vnc';
|
||||
|
||||
const mountConsole = (props = {}) => {
|
||||
mockInstances.length = 0;
|
||||
jest.useFakeTimers();
|
||||
|
||||
return shallowMount(NovncConsole, { props: { url: URL, ...props } });
|
||||
};
|
||||
|
||||
const lastRFB = () => mockInstances[mockInstances.length - 1];
|
||||
|
||||
describe('component: NovncConsole', () => {
|
||||
it('should connect with preserveSession so an existing session is not kicked', async() => {
|
||||
mountConsole();
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
|
||||
expect(new window.URL(lastRFB().url).searchParams.get('preserveSession')).toBe('true');
|
||||
});
|
||||
|
||||
it('should keep retrying while the console is held by another session', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('connect');
|
||||
|
||||
// Dropped by another session taking over.
|
||||
lastRFB().emit('disconnect');
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.RECONNECTING);
|
||||
|
||||
// The first retry is rejected because the other session is still active.
|
||||
jest.advanceTimersByTime(1000);
|
||||
lastRFB().emit('disconnect');
|
||||
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.RECONNECTING);
|
||||
expect(wrapper.vm.retryTimes).toBe(2);
|
||||
expect(wrapper.vm.statusDetail).toBe('%harvester.virtualMachine.detail.console.status.inUse%');
|
||||
expect(new window.URL(lastRFB().url).searchParams.get('preserveSession')).toBe('true');
|
||||
});
|
||||
|
||||
it('should fail with a take over option after the retries are exhausted', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('connect');
|
||||
lastRFB().emit('disconnect');
|
||||
|
||||
for (let i = 0; i < wrapper.vm.maximumRetryTimes; i++) {
|
||||
jest.runOnlyPendingTimers();
|
||||
lastRFB().emit('disconnect');
|
||||
}
|
||||
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.FAILED);
|
||||
expect(wrapper.vm.failure).toBe(CONSOLE_FAILURE.IN_USE);
|
||||
expect(wrapper.vm.isClosed).toBe(false);
|
||||
});
|
||||
|
||||
it('should show the console as in use when a running VM refuses the first connection', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('disconnect');
|
||||
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.FAILED);
|
||||
expect(wrapper.vm.failure).toBe(CONSOLE_FAILURE.IN_USE);
|
||||
expect(wrapper.vm.canTakeOver).toBe(true);
|
||||
});
|
||||
|
||||
it('should not claim the console is in use when the VM is not running', async() => {
|
||||
const wrapper = mountConsole({ vmRunning: false });
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('disconnect');
|
||||
|
||||
expect(wrapper.vm.failure).toBe(CONSOLE_FAILURE.UNAVAILABLE);
|
||||
});
|
||||
|
||||
it('should only take over after the modal is confirmed', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
const connections = mockInstances.length;
|
||||
|
||||
wrapper.vm.takeOver();
|
||||
expect(wrapper.vm.showTakeOverModal).toBe(true);
|
||||
expect(mockInstances).toHaveLength(connections);
|
||||
|
||||
wrapper.vm.confirmTakeOver();
|
||||
|
||||
expect(wrapper.vm.showTakeOverModal).toBe(false);
|
||||
expect(new window.URL(lastRFB().url).searchParams.get('preserveSession')).toBe('false');
|
||||
});
|
||||
|
||||
it('should not take over when the modal is cancelled', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
const connections = mockInstances.length;
|
||||
|
||||
wrapper.vm.takeOver();
|
||||
wrapper.vm.cancelTakeOver();
|
||||
|
||||
expect(wrapper.vm.showTakeOverModal).toBe(false);
|
||||
expect(mockInstances).toHaveLength(connections);
|
||||
});
|
||||
|
||||
it('should focus the console once it connects, so typing reaches the VM', async() => {
|
||||
mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('connect');
|
||||
|
||||
expect(lastRFB().focus).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should mark the console while it has keyboard focus', async() => {
|
||||
const wrapper = mountConsole();
|
||||
const view = wrapper.find('.novnc-screen');
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
|
||||
view.element.dispatchEvent(new FocusEvent('focusin'));
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(view.classes()).toContain('is-focused');
|
||||
|
||||
view.element.dispatchEvent(new FocusEvent('focusout'));
|
||||
await wrapper.vm.$nextTick();
|
||||
expect(view.classes()).not.toContain('is-focused');
|
||||
});
|
||||
|
||||
describe('when the cluster does not support preserveSession', () => {
|
||||
it('should connect without the parameter and offer no take over', async() => {
|
||||
const wrapper = mountConsole({ preserveSession: false });
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
expect(new window.URL(lastRFB().url).searchParams.has('preserveSession')).toBe(false);
|
||||
|
||||
lastRFB().emit('disconnect');
|
||||
|
||||
expect(wrapper.vm.failure).toBe(CONSOLE_FAILURE.UNAVAILABLE);
|
||||
expect(wrapper.vm.canTakeOver).toBe(false);
|
||||
});
|
||||
|
||||
it('should not reconnect on its own after the session drops', async() => {
|
||||
const wrapper = mountConsole({ preserveSession: false });
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
lastRFB().emit('connect');
|
||||
const connections = mockInstances.length;
|
||||
|
||||
lastRFB().emit('disconnect');
|
||||
jest.runOnlyPendingTimers();
|
||||
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.DISCONNECTED);
|
||||
expect(wrapper.vm.failure).toBe(CONSOLE_FAILURE.DROPPED);
|
||||
expect(wrapper.vm.showError).toBe(true);
|
||||
expect(mockInstances).toHaveLength(connections);
|
||||
});
|
||||
});
|
||||
|
||||
it('should close the socket when credentials are required', async() => {
|
||||
const wrapper = mountConsole();
|
||||
|
||||
await jest.runOnlyPendingTimersAsync();
|
||||
const rfb = lastRFB();
|
||||
|
||||
rfb.emit('credentialsrequired');
|
||||
|
||||
expect(rfb.disconnect).toHaveBeenCalledWith();
|
||||
expect(wrapper.vm.rfb).toBeNull();
|
||||
expect(wrapper.vm.status).toBe(CONSOLE_STATUS.FAILED);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import NovncConsoleWrapper, { CONFIRM_ACTION } from '../NovncConsoleWrapper.vue';
|
||||
|
||||
jest.mock('../ZoomableRFB', () => ({ normalizeZoom: (value) => value }));
|
||||
jest.mock('@novnc/novnc/core/input/keysym', () => ({}), { virtual: true });
|
||||
jest.mock('@novnc/novnc/core/input/util', () => ({}), { virtual: true });
|
||||
|
||||
const consoleRef = {
|
||||
ctrlAltDelete: jest.fn(),
|
||||
focus: jest.fn(),
|
||||
};
|
||||
|
||||
const mountWrapper = () => {
|
||||
consoleRef.ctrlAltDelete.mockClear();
|
||||
consoleRef.focus.mockClear();
|
||||
|
||||
const wrapper = shallowMount(NovncConsoleWrapper, {
|
||||
props: {
|
||||
value: {
|
||||
id: 'default/vm', metadata: { name: 'vm' }, status: { phase: 'Running' }
|
||||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'management/all': () => [],
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
},
|
||||
},
|
||||
$fetchState: { pending: false },
|
||||
},
|
||||
stubs: {
|
||||
NovncConsole: {
|
||||
template: '<div />',
|
||||
methods: {
|
||||
ctrlAltDelete: consoleRef.ctrlAltDelete,
|
||||
focus: consoleRef.focus,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
wrapper.vm.onStatusChanged({ status: 'connected' });
|
||||
|
||||
return wrapper;
|
||||
};
|
||||
|
||||
describe('component: NovncConsoleWrapper', () => {
|
||||
it('should only send Ctrl+Alt+Del after it is confirmed', async() => {
|
||||
const wrapper = mountWrapper();
|
||||
|
||||
wrapper.vm.ctrlAltDelete();
|
||||
expect(wrapper.vm.confirmAction).toBe(CONFIRM_ACTION.CTRL_ALT_DEL);
|
||||
expect(consoleRef.ctrlAltDelete).not.toHaveBeenCalled();
|
||||
|
||||
wrapper.vm.runConfirmedAction();
|
||||
|
||||
expect(consoleRef.ctrlAltDelete).toHaveBeenCalledTimes(1);
|
||||
expect(wrapper.vm.confirmAction).toBeNull();
|
||||
});
|
||||
|
||||
it('should not send Ctrl+Alt+Del when the confirmation is cancelled', () => {
|
||||
const wrapper = mountWrapper();
|
||||
|
||||
wrapper.vm.ctrlAltDelete();
|
||||
wrapper.vm.cancelConfirm();
|
||||
|
||||
expect(consoleRef.ctrlAltDelete).not.toHaveBeenCalled();
|
||||
expect(wrapper.vm.confirmAction).toBeNull();
|
||||
});
|
||||
|
||||
it('should only soft reboot after it is confirmed', () => {
|
||||
const wrapper = mountWrapper();
|
||||
const doSoftReboot = jest.fn();
|
||||
|
||||
wrapper.vm.vmResource = { doSoftReboot };
|
||||
|
||||
wrapper.vm.softReboot();
|
||||
expect(doSoftReboot).not.toHaveBeenCalled();
|
||||
|
||||
wrapper.vm.runConfirmedAction();
|
||||
expect(doSoftReboot).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not ask to send Ctrl+Alt+Del while keys cannot be sent', () => {
|
||||
const wrapper = mountWrapper();
|
||||
|
||||
wrapper.vm.onStatusChanged({ status: 'reconnecting' });
|
||||
wrapper.vm.ctrlAltDelete();
|
||||
|
||||
expect(wrapper.vm.confirmAction).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -19,7 +19,8 @@ export default {
|
||||
<div class="row mb-20">
|
||||
<div class="col span-12">
|
||||
<FileSelector
|
||||
class="btn btn-sm bg-primary mb-10"
|
||||
variant="primary"
|
||||
class="mb-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
|
||||
@@ -191,7 +191,8 @@ export default {
|
||||
>
|
||||
<div class="col span-12">
|
||||
<FileSelector
|
||||
class="btn btn-sm bg-primary mb-10"
|
||||
variant="primary"
|
||||
class="mb-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
@selected="onKeySelected"
|
||||
/>
|
||||
@@ -213,9 +214,7 @@ $yaml-height: 540px;
|
||||
:deep() .yaml-editor{
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
& .code-mirror .CodeMirror {
|
||||
position: initial;
|
||||
height: auto;
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
|
||||
@@ -62,7 +62,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('publicCertificate', $event)"
|
||||
/>
|
||||
@@ -80,7 +81,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('privateKey', $event)"
|
||||
/>
|
||||
@@ -98,7 +100,8 @@ export default {
|
||||
<div class="chooseFile">
|
||||
<FileSelector
|
||||
:include-file-name="true"
|
||||
class="btn btn-sm bg-primary mr-20"
|
||||
variant="primary"
|
||||
class="mr-20"
|
||||
label="Choose File"
|
||||
@selected="onKeySelectedCa('ca', $event)"
|
||||
/>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect.vue';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { Banner } from '@components/Banner';
|
||||
import Tip from '@shell/components/Tip';
|
||||
|
||||
@@ -5,7 +5,7 @@ import { RadioGroup } from '@components/Form/Radio';
|
||||
import { Banner } from '@components/Banner';
|
||||
import ArrayList from '@shell/components/form/ArrayList';
|
||||
import { allHash } from '@shell/utils/promise';
|
||||
import { isValidCIDR } from '@shell/utils/validators/cidr';
|
||||
import { isValidCIDR } from '@pkg/harvester/utils/regular';
|
||||
import { NODE } from '@shell/config/types';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import { HCI } from '../../types';
|
||||
|
||||
@@ -56,6 +56,7 @@ const FEATURE_FLAGS = {
|
||||
'kubevirtMigration',
|
||||
'hotplugNic',
|
||||
'resumeUpgradePausedNode',
|
||||
'vncPreserveSession',
|
||||
],
|
||||
'v1.7.1': [],
|
||||
'v1.8.0': [
|
||||
@@ -77,6 +78,14 @@ const FEATURE_FLAGS = {
|
||||
'staticIPForVM',
|
||||
'fsFreezeDeadline',
|
||||
],
|
||||
'v1.9.1': [
|
||||
'lvmDmThinOnly',
|
||||
'highPerformanceStorage',
|
||||
],
|
||||
'v1.10.0': [
|
||||
'maintenanceModeConditions',
|
||||
'maintenanceModeDrainTimeoutSetting',
|
||||
],
|
||||
};
|
||||
|
||||
const generateFeatureFlags = () => {
|
||||
|
||||
@@ -57,6 +57,12 @@ import {
|
||||
} from './table-headers';
|
||||
import { ADD_ONS } from './harvester-map';
|
||||
import { registerAddonSideNav } from '../utils/dynamic-nav';
|
||||
import { setStandalonePrime } from '../utils/l10n-globals';
|
||||
import { setVendor } from '@shell/config/private-label';
|
||||
import { CONFIGURABLE_TABLES } from '@shell/store/features';
|
||||
import { tableViewsOffFeature } from '../utils/table-views';
|
||||
import { SETTING } from '@shell/config/settings';
|
||||
import { primeBrandUpdater } from '../utils/prime-brand';
|
||||
|
||||
const TEMPLATE = HCI.VM_VERSION;
|
||||
const MONITORING_GROUP = 'Monitoring & Logging::Monitoring';
|
||||
@@ -109,15 +115,57 @@ export function init($plugin, store) {
|
||||
}
|
||||
};
|
||||
|
||||
store.dispatch('setIsSingleProduct', {
|
||||
productName: PRODUCT_NAME,
|
||||
logo: require(`@shell/assets/images/providers/harvester.svg`),
|
||||
productNameKey: 'harvester.productLabel',
|
||||
getVersionInfo: (store) => store.getters[`${ PRODUCT_NAME }/byId`]?.(HCI.SETTING, 'server-version')?.value || 'unknown',
|
||||
afterLoginRoute: home,
|
||||
logoRoute: home,
|
||||
supportCustomLogo: true
|
||||
});
|
||||
store.watch(
|
||||
(_state, getters) => JSON.stringify([
|
||||
!!getters['harvester-common/isHarvesterPrime'],
|
||||
getters['prefs/theme'] === 'dark',
|
||||
getters['harvester-common/privateLabel']
|
||||
]),
|
||||
(value) => {
|
||||
const [isHarvesterPrime, isDark, privateLabel] = JSON.parse(value);
|
||||
const primeLogo = isDark ? require('../assets/images/dark/suse-virtualization.svg') : require('../assets/images/suse-virtualization.svg');
|
||||
|
||||
setStandalonePrime(isHarvesterPrime);
|
||||
setVendor(privateLabel || '');
|
||||
|
||||
const primeLabelKey = privateLabel ? 'harvester.branding.primeLabel' : 'harvester.branding.primeEmptyLabel';
|
||||
|
||||
store.dispatch('setIsSingleProduct', {
|
||||
productName: PRODUCT_NAME,
|
||||
logo: isHarvesterPrime ? primeLogo : require(`@shell/assets/images/providers/harvester.svg`),
|
||||
productNameKey: isHarvesterPrime ? primeLabelKey : 'harvester.productLabel',
|
||||
getVersionInfo: (store) => store.getters[`${ PRODUCT_NAME }/byId`]?.(HCI.SETTING, 'server-version')?.value || 'unknown',
|
||||
afterLoginRoute: home,
|
||||
logoRoute: home,
|
||||
supportCustomLogo: !isHarvesterPrime
|
||||
});
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
// Keep the shell's table views off: they drop the filters the lists put in the table header
|
||||
store.watch(
|
||||
(_state, getters) => getters['management/byId'](MANAGEMENT.FEATURE, CONFIGURABLE_TABLES),
|
||||
(feature) => {
|
||||
if (!feature) {
|
||||
store.dispatch('management/load', { data: tableViewsOffFeature() });
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const updateBrand = primeBrandUpdater();
|
||||
|
||||
// The value is read too: a change event from the server is loaded into the same setting object
|
||||
store.watch(
|
||||
(_state, getters) => {
|
||||
const brandSetting = getters['management/byId'](MANAGEMENT.SETTING, SETTING.BRAND);
|
||||
|
||||
return [!!getters['harvester-common/isHarvesterPrime'], brandSetting, brandSetting?.value];
|
||||
},
|
||||
([isHarvesterPrime, brandSetting]) => updateBrand(brandSetting, isHarvesterPrime),
|
||||
{ immediate: true }
|
||||
);
|
||||
}
|
||||
|
||||
product({
|
||||
|
||||
@@ -39,6 +39,21 @@ export const VOLUME_TYPE = [{
|
||||
value: 'cd-rom'
|
||||
}];
|
||||
|
||||
// KubeVirt high-performance disk features
|
||||
// https://kubevirt.io/user-guide/storage/disks_and_volumes/#high-performance-features
|
||||
export const DISK_CACHE_MODE = ['', 'none', 'writeback', 'writethrough'];
|
||||
|
||||
export const DISK_IO_MODE = ['', 'native', 'threads'];
|
||||
|
||||
export const IO_THREADS_POLICY = ['', 'shared', 'auto', 'supplementalPool'];
|
||||
|
||||
// "Easy-to-consume" presets layered on top of the raw KubeVirt fields.
|
||||
export const DISK_PERFORMANCE_PROFILE = {
|
||||
DEFAULT: 'default',
|
||||
HIGH: 'highPerformance',
|
||||
CUSTOM: 'custom',
|
||||
};
|
||||
|
||||
export const VOLUME_HOTPLUG_ACTION = {
|
||||
INSERT_CDROM_IMAGE: 'INSERT_CDROM_IMAGE',
|
||||
EJECT_CDROM_IMAGE: 'EJECT_CDROM_IMAGE',
|
||||
|
||||
@@ -22,7 +22,7 @@ export const HCI = {
|
||||
VM_NAME_PREFIX: 'harvesterhci.io/vmNamePrefix',
|
||||
VM_DISPLAY_NAME: 'harvesterhci.io/vmDisplayName',
|
||||
VM_RESERVED_MEMORY: 'harvesterhci.io/reservedMemory',
|
||||
MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status',
|
||||
MAINTENANCE_STATUS: 'harvesterhci.io/maintain-status', // Deprecated >= v1.10.0
|
||||
HOST_CUSTOM_NAME: 'harvesterhci.io/host-custom-name',
|
||||
HOST_CONSOLE_URL: 'harvesterhci.io/host-console-url',
|
||||
RESTORE_NAME: 'restore.harvesterhci.io/name',
|
||||
@@ -33,6 +33,11 @@ export const HCI = {
|
||||
CLONE_BACKEND_STORAGE_STATUS: 'harvesterhci.io/clone-backend-storage-status',
|
||||
MIGRATION_STATE: 'harvesterhci.io/migrationState',
|
||||
VOLUME_CLAIM_TEMPLATE: 'harvesterhci.io/volumeClaimTemplates',
|
||||
// Default KubeVirt high-performance disk settings, applied when the volume is
|
||||
// attached to a VM as a disk. See disks_and_volumes.md#high-performance-features.
|
||||
DISK_CACHE_MODE: 'harvesterhci.io/disk-cache-mode',
|
||||
DISK_IO_MODE: 'harvesterhci.io/disk-io-mode',
|
||||
DISK_DEDICATED_IOTHREAD: 'harvesterhci.io/disk-dedicated-iothread',
|
||||
IMAGE_NAME: 'harvesterhci.io/image-name',
|
||||
INIT_IP: 'etcd.rke2.cattle.io/node-address',
|
||||
NODE_SCHEDULABLE: 'kubevirt.io/schedulable',
|
||||
|
||||
@@ -3,6 +3,7 @@ export const HCI_SETTING = {
|
||||
CONTAINERD_REGISTRY: 'containerd-registry',
|
||||
LOG_LEVEL: 'log-level',
|
||||
SERVER_VERSION: 'server-version',
|
||||
SERVER_FLAVOR: 'server-flavor',
|
||||
UI_INDEX: 'ui-index',
|
||||
UPGRADE_CHECKER_ENABLED: 'upgrade-checker-enabled',
|
||||
UPGRADE_CHECKER_URL: 'upgrade-checker-url',
|
||||
@@ -44,7 +45,8 @@ export const HCI_SETTING = {
|
||||
MAX_HOTPLUG_RATIO: 'max-hotplug-ratio',
|
||||
KUBEVIRT_MIGRATION: 'kubevirt-migration',
|
||||
INSTANCE_MANAGER_RESOURCES: 'instance-manager-resources',
|
||||
CLUSTER_POD_SECURITY_STANDARD: 'cluster-pod-security-standard'
|
||||
CLUSTER_POD_SECURITY_STANDARD: 'cluster-pod-security-standard',
|
||||
MAINTENANCE_MODE_DRAIN_TIMEOUT: 'maintenance-mode-drain-timeout'
|
||||
};
|
||||
|
||||
export const HCI_ALLOWED_SETTINGS = {
|
||||
@@ -68,6 +70,7 @@ export const HCI_ALLOWED_SETTINGS = {
|
||||
kind: 'json', from: 'import', featureFlag: 'csiOnlineExpandValidation'
|
||||
},
|
||||
[HCI_SETTING.SERVER_VERSION]: { readOnly: true },
|
||||
[HCI_SETTING.SERVER_FLAVOR]: { readOnly: true },
|
||||
[HCI_SETTING.UPGRADE_CHECKER_ENABLED]: { kind: 'boolean' },
|
||||
[HCI_SETTING.UPGRADE_CHECKER_URL]: { kind: 'url' },
|
||||
[HCI_SETTING.HTTP_PROXY]: { kind: 'json', from: 'import' },
|
||||
@@ -146,6 +149,9 @@ export const HCI_ALLOWED_SETTINGS = {
|
||||
},
|
||||
[HCI_SETTING.CLUSTER_POD_SECURITY_STANDARD]: {
|
||||
kind: 'json', from: 'import', canReset: true, featureFlag: 'clusterPodSecurityStandardSetting'
|
||||
},
|
||||
[HCI_SETTING.MAINTENANCE_MODE_DRAIN_TIMEOUT]: {
|
||||
kind: 'number', canReset: true, featureFlag: 'maintenanceModeDrainTimeoutSetting'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import OverviewKeypairs from '../kubevirt.io.virtualmachine/VirtualMachineTabs/V
|
||||
import Volume from '../../edit/kubevirt.io.virtualmachine/VirtualMachineVolume';
|
||||
import Network from '../../edit/kubevirt.io.virtualmachine/VirtualMachineNetwork';
|
||||
import CloudConfig from '../../edit/kubevirt.io.virtualmachine/VirtualMachineCloudConfig';
|
||||
import { getBootDevices } from '../../utils/vm';
|
||||
const UNDEFINED = 'n/a';
|
||||
|
||||
export default {
|
||||
@@ -74,18 +75,8 @@ export default {
|
||||
return image?.spec?.displayName || '-';
|
||||
},
|
||||
|
||||
disks() {
|
||||
const disks = this?.spec?.template?.spec?.domain?.devices?.disks || [];
|
||||
|
||||
return disks.filter((disk) => {
|
||||
return !!disk.bootOrder;
|
||||
}).sort((a, b) => {
|
||||
if (a.bootOrder < b.bootOrder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
bootDevices() {
|
||||
return getBootDevices(this?.spec?.template?.spec?.domain?.devices);
|
||||
},
|
||||
|
||||
cdroms() {
|
||||
@@ -101,8 +92,10 @@ export default {
|
||||
getDeviceType(o) {
|
||||
if (o.disk) {
|
||||
return 'Disk';
|
||||
} else {
|
||||
} else if (o.cdrom) {
|
||||
return 'CD-ROM';
|
||||
} else {
|
||||
return 'Network';
|
||||
}
|
||||
},
|
||||
isEmpty(o) {
|
||||
@@ -184,10 +177,10 @@ export default {
|
||||
<div>
|
||||
<ul>
|
||||
<li
|
||||
v-for="(disk, i) in disks"
|
||||
v-for="(device, i) in bootDevices"
|
||||
:key="i"
|
||||
>
|
||||
{{ disk.bootOrder }}. {{ disk.name }} ({{ getDeviceType(disk) }})
|
||||
{{ device.bootOrder }}. {{ device.name }} ({{ getDeviceType(device) }})
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -233,6 +226,7 @@ export default {
|
||||
>
|
||||
<Network
|
||||
v-model:value="networkRows"
|
||||
:network-boot-first="networkBootFirst"
|
||||
:mode="mode"
|
||||
/>
|
||||
</Tab>
|
||||
|
||||
@@ -15,6 +15,7 @@ import OverviewKeypairs from '../kubevirt.io.virtualmachine/VirtualMachineTabs/V
|
||||
import Volume from '../../edit/kubevirt.io.virtualmachine/VirtualMachineVolume';
|
||||
import Network from '../../edit/kubevirt.io.virtualmachine/VirtualMachineNetwork';
|
||||
import CloudConfig from '../../edit/kubevirt.io.virtualmachine/VirtualMachineCloudConfig';
|
||||
import { getBootDevices } from '../../utils/vm';
|
||||
const UNDEFINED = 'n/a';
|
||||
|
||||
export default {
|
||||
@@ -74,18 +75,8 @@ export default {
|
||||
return image?.spec?.displayName || '-';
|
||||
},
|
||||
|
||||
disks() {
|
||||
const disks = this?.spec?.template?.spec?.domain?.devices?.disks || [];
|
||||
|
||||
return disks.filter((disk) => {
|
||||
return !!disk.bootOrder;
|
||||
}).sort((a, b) => {
|
||||
if (a.bootOrder < b.bootOrder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
bootDevices() {
|
||||
return getBootDevices(this?.spec?.template?.spec?.domain?.devices);
|
||||
},
|
||||
|
||||
cdroms() {
|
||||
@@ -101,8 +92,10 @@ export default {
|
||||
getDeviceType(o) {
|
||||
if (o.disk) {
|
||||
return 'Disk';
|
||||
} else {
|
||||
} else if (o.cdrom) {
|
||||
return 'CD-ROM';
|
||||
} else {
|
||||
return 'Network';
|
||||
}
|
||||
},
|
||||
isEmpty(o) {
|
||||
@@ -184,10 +177,10 @@ export default {
|
||||
<div>
|
||||
<ul>
|
||||
<li
|
||||
v-for="(disk, i) in disks"
|
||||
v-for="(device, i) in bootDevices"
|
||||
:key="i"
|
||||
>
|
||||
{{ disk.bootOrder }}. {{ disk.name }} ({{ getDeviceType(disk) }})
|
||||
{{ device.bootOrder }}. {{ device.name }} ({{ getDeviceType(device) }})
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
@@ -234,6 +227,7 @@ export default {
|
||||
>
|
||||
<Network
|
||||
v-model:value="networkRows"
|
||||
:network-boot-first="networkBootFirst"
|
||||
:mode="mode"
|
||||
/>
|
||||
</Tab>
|
||||
|
||||
+9
-16
@@ -6,6 +6,7 @@ import HarvesterIpAddress from '../../../formatters/HarvesterIpAddress';
|
||||
import VMConsoleBar from '../../../components/VMConsoleBar';
|
||||
import { HCI } from '../../../types';
|
||||
import { getVmCPUMemoryValues } from '../../../utils/cpuMemory';
|
||||
import { getBootDevices } from '../../../utils/vm';
|
||||
|
||||
const UNDEFINED = 'n/a';
|
||||
|
||||
@@ -69,18 +70,8 @@ export default {
|
||||
return image?.spec?.displayName || 'N/A';
|
||||
},
|
||||
|
||||
disks() {
|
||||
const disks = this.value?.spec?.template?.spec?.domain?.devices?.disks || [];
|
||||
|
||||
return disks.filter((disk) => {
|
||||
return !!disk.bootOrder;
|
||||
}).sort((a, b) => {
|
||||
if (a.bootOrder < b.bootOrder) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
bootDevices() {
|
||||
return getBootDevices(this.value?.spec?.template?.spec?.domain?.devices);
|
||||
},
|
||||
|
||||
cdroms() {
|
||||
@@ -122,8 +113,10 @@ export default {
|
||||
getDeviceType(o) {
|
||||
if (o.disk) {
|
||||
return 'Disk';
|
||||
} else {
|
||||
} else if (o.cdrom) {
|
||||
return 'CD-ROM';
|
||||
} else {
|
||||
return 'Network';
|
||||
}
|
||||
},
|
||||
isEmpty(o) {
|
||||
@@ -219,16 +212,16 @@ export default {
|
||||
<div class="col span-6">
|
||||
<InputOrDisplay
|
||||
:name="t('harvester.virtualMachine.detail.details.bootOrder')"
|
||||
:value="disks"
|
||||
:value="bootDevices"
|
||||
:mode="mode"
|
||||
>
|
||||
<template #value>
|
||||
<ul>
|
||||
<li
|
||||
v-for="(disk, i) in disks"
|
||||
v-for="(device, i) in bootDevices"
|
||||
:key="i"
|
||||
>
|
||||
{{ disk.bootOrder }}. {{ disk.name }} ({{ getDeviceType(disk) }})
|
||||
{{ device.bootOrder }}. {{ device.name }} ({{ getDeviceType(device) }})
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
@@ -14,6 +14,7 @@ import Labels from '@shell/components/form/Labels';
|
||||
import LabelValue from '@shell/components/LabelValue';
|
||||
import { HCI } from '../../types';
|
||||
import VM_MIXIN from '../../mixins/harvester-vm';
|
||||
import { getLatestMigration } from '../../utils/vm';
|
||||
|
||||
import CloudConfig from '../../edit/kubevirt.io.virtualmachine/VirtualMachineCloudConfig';
|
||||
import Volume from '../../edit/kubevirt.io.virtualmachine/VirtualMachineVolume';
|
||||
@@ -139,18 +140,7 @@ export default {
|
||||
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||
const vmimList = this.$store.getters[`${ inStore }/all`](HCI.VMIM) || [];
|
||||
|
||||
const vmiName = this.vmi?.name || '';
|
||||
|
||||
// filter the corresponding vmims by vmim.spec.vmiName and find the latest one by creationTimestamp
|
||||
const vmim = vmimList.filter((VMIM) => VMIM?.spec?.vmiName === vmiName).sort((a, b) => {
|
||||
if (a?.metadata?.creationTimestamp > b?.metadata?.creationTimestamp) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
});
|
||||
|
||||
return vmim.length > 0 && vmim[0] ? vmim[0] : null;
|
||||
return getLatestMigration(vmimList, this.vmi?.metadata?.namespace, this.vmi?.name) || null;
|
||||
},
|
||||
|
||||
migrationEvents() {
|
||||
@@ -214,6 +204,15 @@ export default {
|
||||
|
||||
this['diskRows'] = diskRows;
|
||||
this['networkRows'] = this.getNetworkRows(neu, { fromTemplate: false, init: false });
|
||||
this['networkBootFirst'] = this.isNetworkBootFirst(neu.spec);
|
||||
|
||||
// getInitConfig() seeds these on created(); refresh them here too so the
|
||||
// VM-wide performance panel does not go stale when the spec changes.
|
||||
const domain = neu?.spec?.template?.spec?.domain;
|
||||
|
||||
this['blockMultiQueue'] = domain?.devices?.blockMultiQueue || false;
|
||||
this['ioThreadsPolicy'] = domain?.ioThreadsPolicy || '';
|
||||
this['ioThreadCount'] = domain?.ioThreads?.supplementalPoolThreadCount || 2;
|
||||
},
|
||||
deep: true
|
||||
}
|
||||
@@ -254,6 +253,9 @@ export default {
|
||||
:namespace="value.metadata.namespace"
|
||||
:vm="value"
|
||||
:resource-type="value.type"
|
||||
:block-multi-queue="blockMultiQueue"
|
||||
:io-threads-policy="ioThreadsPolicy"
|
||||
:io-thread-count="ioThreadCount"
|
||||
/>
|
||||
</Tab>
|
||||
|
||||
@@ -265,6 +267,7 @@ export default {
|
||||
>
|
||||
<Network
|
||||
v-model:value="networkRows"
|
||||
:network-boot-first="networkBootFirst"
|
||||
mode="view"
|
||||
:vm="value"
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<script>
|
||||
import merge from 'lodash/merge';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { mapGetters } from 'vuex';
|
||||
import { Card } from '@components/Card';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import AsyncButton from '@shell/components/AsyncButton';
|
||||
import { escapeHtml } from '@shell/utils/string';
|
||||
|
||||
const DEFAULT_VALUE = {
|
||||
rancher: {
|
||||
hostname: '',
|
||||
version: '',
|
||||
bootstrapPassword: '',
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEnableK3k',
|
||||
|
||||
emits: ['close'],
|
||||
|
||||
components: {
|
||||
AsyncButton,
|
||||
Card,
|
||||
LabeledInput,
|
||||
},
|
||||
|
||||
props: {
|
||||
resources: {
|
||||
type: Array,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
data() {
|
||||
const addon = this.resources[0];
|
||||
let valuesContentJson;
|
||||
|
||||
try {
|
||||
valuesContentJson = merge({}, DEFAULT_VALUE, jsyaml.load(addon.spec.valuesContent));
|
||||
} catch (e) {
|
||||
valuesContentJson = merge({}, DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
return { valuesContentJson };
|
||||
},
|
||||
|
||||
computed: {
|
||||
...mapGetters({ t: 'i18n/t' }),
|
||||
|
||||
buttonDisabled() {
|
||||
const { rancher } = this.valuesContentJson;
|
||||
|
||||
return !(rancher?.hostname || '').trim() || !(rancher?.version || '').trim() || !(rancher?.bootstrapPassword || '').trim();
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
close() {
|
||||
this.$emit('close');
|
||||
},
|
||||
|
||||
async enable(buttonCb) {
|
||||
const addon = this.resources[0];
|
||||
|
||||
try {
|
||||
addon.spec.valuesContent = jsyaml.dump(this.valuesContentJson);
|
||||
addon.spec.enabled = true;
|
||||
await addon.save();
|
||||
buttonCb(true);
|
||||
this.close();
|
||||
} catch (err) {
|
||||
addon.spec.enabled = false;
|
||||
this.$store.dispatch('growl/fromError', {
|
||||
title: this.t('generic.notification.title.error', { name: escapeHtml(addon.metadata.name) }),
|
||||
err,
|
||||
}, { root: true });
|
||||
buttonCb(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card :show-highlight-border="false">
|
||||
<template #title>
|
||||
<h4
|
||||
v-clean-html="t('harvester.addons.rancherK3k.enable.title')"
|
||||
class="text-default-text"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<template #body>
|
||||
<div class="body">
|
||||
<div class="row mb-15">
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.hostname"
|
||||
:required="true"
|
||||
:label="t('harvester.addons.rancherK3k.hostname')"
|
||||
placeholder="rancher.$vip.nip.io"
|
||||
/>
|
||||
</div>
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.version"
|
||||
:required="true"
|
||||
:label="t('harvester.addons.rancherK3k.version')"
|
||||
placeholder="v1.14.0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-15">
|
||||
<div class="col span-12">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.bootstrapPassword"
|
||||
:required="true"
|
||||
type="password"
|
||||
:label="t('harvester.addons.rancherK3k.password')"
|
||||
:tooltip="t('harvester.addons.rancherK3k.passwordTooltip')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #actions>
|
||||
<div class="buttons actions">
|
||||
<button
|
||||
class="btn role-secondary mr-10"
|
||||
@click="close"
|
||||
>
|
||||
{{ t('generic.cancel') }}
|
||||
</button>
|
||||
|
||||
<AsyncButton
|
||||
mode="enable"
|
||||
:disabled="buttonDisabled"
|
||||
@click="enable"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 400px;
|
||||
}
|
||||
|
||||
.actions {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,141 @@
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { _CREATE, _EDIT, _VIEW } from '@shell/config/query-params';
|
||||
import YamlEditor from '@shell/components/YamlEditor';
|
||||
import { HCI } from '@pkg/harvester/config/labels-annotations';
|
||||
import HarvesterEditCloudTemplate from '../harvesterhci.io.cloudtemplate.vue';
|
||||
|
||||
const OLD_CONFIG = '#cloud-config\npassword: old\n';
|
||||
const NEW_CONFIG = '#cloud-config\npassword: new\n';
|
||||
|
||||
// A cloud-config template as the store gives it, `save` records what would be sent to the API
|
||||
function cloudTemplate({ isNew = false } = {}) {
|
||||
const value = {
|
||||
type: 'configmap',
|
||||
metadata: {
|
||||
name: 'tpl',
|
||||
namespace: 'default',
|
||||
...(isNew ? {} : { labels: { [HCI.CLOUD_INIT]: 'user' } }),
|
||||
},
|
||||
data: isNew ? undefined : { cloudInit: OLD_CONFIG },
|
||||
$dispatch: jest.fn(),
|
||||
save: () => Promise.resolve(),
|
||||
saved: [],
|
||||
};
|
||||
|
||||
jest.spyOn(value, 'save').mockImplementation(() => {
|
||||
value.saved.push(JSON.parse(JSON.stringify({ metadata: value.metadata, data: value.data })));
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// The real shell YamlEditor, with only its CodeMirror editor stubbed, so the events the form listens to are the
|
||||
// ones the shell emits
|
||||
function mountForm(mode, value) {
|
||||
return mount(HarvesterEditCloudTemplate, {
|
||||
props: { value, mode },
|
||||
global: {
|
||||
stubs: {
|
||||
CruResource: { template: '<div><slot /></div>' },
|
||||
Tabbed: { template: '<div><slot /></div>' },
|
||||
Tab: { template: '<div><slot /></div>' },
|
||||
NameNsDescription: true,
|
||||
LabeledSelect: true,
|
||||
CodeMirror: {
|
||||
name: 'CodeMirror', template: '<div />', emits: ['onInput', 'onReady', 'validationChanged']
|
||||
},
|
||||
FileDiff: true,
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'prefs/get': jest.fn(),
|
||||
'type-map/isSpoofed': () => false,
|
||||
currentStore: () => 'harvester',
|
||||
'harvester/schemaFor': () => ({ linkFor: () => '/v1/harvester/configmaps' }),
|
||||
'i18n/t': (key) => key,
|
||||
},
|
||||
},
|
||||
$router: { replace: jest.fn() },
|
||||
$route: {
|
||||
name: 'c-cluster-product-resource-id', params: {}, query: {}
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// What a user typing in the editor does: CodeMirror reports the new text to the YamlEditor
|
||||
async function typeInEditor(wrapper, text) {
|
||||
wrapper.findComponent(YamlEditor).findComponent({ name: 'CodeMirror' }).vm.$emit('onInput', text);
|
||||
await wrapper.vm.$nextTick();
|
||||
}
|
||||
|
||||
describe('component: HarvesterEditCloudTemplate', () => {
|
||||
it('should save the edited cloud config when editing a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.save).toHaveBeenCalledTimes(1);
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: NEW_CONFIG });
|
||||
});
|
||||
|
||||
it('should keep the template type label when editing a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].metadata.labels).toStrictEqual({ [HCI.CLOUD_INIT]: 'user' });
|
||||
});
|
||||
|
||||
it('should save the last text when the cloud config is edited several times', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await typeInEditor(wrapper, '#cloud-config\n');
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: NEW_CONFIG });
|
||||
});
|
||||
|
||||
it('should save the cloud config unchanged when only saving a template', async() => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_EDIT, value);
|
||||
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.saved[0].data).toStrictEqual({ cloudInit: OLD_CONFIG });
|
||||
});
|
||||
|
||||
it('should save the cloud config and the template type when creating a template', async() => {
|
||||
const value = cloudTemplate({ isNew: true });
|
||||
const wrapper = mountForm(_CREATE, value);
|
||||
|
||||
await typeInEditor(wrapper, NEW_CONFIG);
|
||||
await wrapper.vm.save(jest.fn());
|
||||
|
||||
expect(value.save).toHaveBeenCalledWith({ url: '/v1/harvester/configmaps' });
|
||||
expect(value.saved[0]).toStrictEqual({
|
||||
metadata: {
|
||||
name: 'tpl', namespace: 'default', labels: { [HCI.CLOUD_INIT]: 'user' }
|
||||
},
|
||||
data: { cloudInit: NEW_CONFIG },
|
||||
});
|
||||
});
|
||||
|
||||
it('should show the template cloud config in the editor when viewing a template', () => {
|
||||
const value = cloudTemplate();
|
||||
const wrapper = mountForm(_VIEW, value);
|
||||
|
||||
expect(wrapper.findComponent(YamlEditor).props('value')).toBe(OLD_CONFIG);
|
||||
expect(value.data).toStrictEqual({ cloudInit: OLD_CONFIG });
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,167 @@
|
||||
<script>
|
||||
import merge from 'lodash/merge';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
|
||||
const DEFAULT_VALUE = {
|
||||
certManagerVersion: 'v1.20.2',
|
||||
rancher: {
|
||||
hostname: '',
|
||||
version: '',
|
||||
bootstrapPassword: '',
|
||||
},
|
||||
k3kCluster: {
|
||||
servers: 1,
|
||||
version: 'v1.35.4-k3s1',
|
||||
storageClassName: 'harvester-longhorn',
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
name: 'EditAddonRancherK3k',
|
||||
components: { LabeledInput, RadioGroup },
|
||||
|
||||
inheritAttrs: false,
|
||||
|
||||
props: {
|
||||
value: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
|
||||
mode: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
registerBeforeHook: {
|
||||
type: Function,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
let valuesContentJson = {};
|
||||
|
||||
try {
|
||||
valuesContentJson = merge({}, DEFAULT_VALUE, jsyaml.load(this.value.spec.valuesContent));
|
||||
} catch (err) {
|
||||
valuesContentJson = merge({}, DEFAULT_VALUE);
|
||||
|
||||
this.$store.dispatch('growl/fromError', {
|
||||
title: this.$store.getters['i18n/t']('generic.notification.title.error'),
|
||||
err: err.data || err,
|
||||
}, { root: true });
|
||||
}
|
||||
|
||||
return { valuesContentJson };
|
||||
},
|
||||
|
||||
created() {
|
||||
if (this.registerBeforeHook) {
|
||||
this.registerBeforeHook(this.willSave, 'willSave');
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
willSave() {
|
||||
const errors = [];
|
||||
|
||||
if (!this.value.spec.enabled) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (!this.valuesContentJson.rancher.hostname) {
|
||||
errors.push(this.t('validation.required', { key: this.t('harvester.addons.rancherK3k.hostname') }, true));
|
||||
}
|
||||
|
||||
if (!this.valuesContentJson.rancher.version) {
|
||||
errors.push(this.t('validation.required', { key: this.t('harvester.addons.rancherK3k.version') }, true));
|
||||
}
|
||||
|
||||
if (!this.valuesContentJson.rancher.bootstrapPassword) {
|
||||
errors.push(this.t('validation.required', { key: this.t('harvester.addons.rancherK3k.password') }, true));
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return Promise.reject(errors);
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
valuesContentJson: {
|
||||
handler(neu) {
|
||||
this.value.spec['valuesContent'] = jsyaml.dump(neu);
|
||||
},
|
||||
deep: true,
|
||||
immediate: true
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="row">
|
||||
<div class="col span-12">
|
||||
<RadioGroup
|
||||
v-model:value="value.spec.enabled"
|
||||
class="mb-20"
|
||||
name="model"
|
||||
:mode="mode"
|
||||
:options="[true,false]"
|
||||
:labels="[t('generic.enabled'), t('generic.disabled')]"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template v-if="value.spec.enabled">
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.hostname"
|
||||
label-key="harvester.addons.rancherK3k.hostname"
|
||||
:required="true"
|
||||
:mode="mode"
|
||||
placeholder="rancher.$vip.nip.io"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.version"
|
||||
label-key="harvester.addons.rancherK3k.version"
|
||||
:required="true"
|
||||
:mode="mode"
|
||||
placeholder="v1.14.0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-20">
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="valuesContentJson.rancher.bootstrapPassword"
|
||||
label-key="harvester.addons.rancherK3k.password"
|
||||
:mode="mode"
|
||||
:required="true"
|
||||
type="password"
|
||||
:tooltip="t('harvester.addons.rancherK3k.passwordTooltip')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
:deep() .radio-group {
|
||||
display: flex;
|
||||
.radio-container {
|
||||
margin-right: 30px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -7,6 +7,7 @@ import NameNsDescription from '@shell/components/form/NameNsDescription';
|
||||
import YamlEditor from '@shell/components/YamlEditor';
|
||||
|
||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||
import FormValidation from '@shell/mixins/form-validation';
|
||||
import { HCI } from '@pkg/harvester/config/labels-annotations';
|
||||
|
||||
export default {
|
||||
@@ -23,14 +24,19 @@ export default {
|
||||
NameNsDescription,
|
||||
},
|
||||
|
||||
mixins: [CreateEditView],
|
||||
mixins: [CreateEditView, FormValidation],
|
||||
|
||||
inheritAttrs: false,
|
||||
|
||||
data() {
|
||||
return {
|
||||
config: this.value.data?.cloudInit || '',
|
||||
type: this.value?.metadata?.labels?.[HCI.CLOUD_INIT] || 'user',
|
||||
config: this.value.data?.cloudInit || '',
|
||||
type: this.value?.metadata?.labels?.[HCI.CLOUD_INIT] || 'user',
|
||||
fvFormRuleSets: [{
|
||||
path: 'metadata.name',
|
||||
rules: ['required'],
|
||||
translationKey: 'nameNsDescription.name.label',
|
||||
}],
|
||||
};
|
||||
},
|
||||
|
||||
@@ -53,8 +59,8 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
update() {
|
||||
this.value.data = { cloudInit: this.config };
|
||||
update(config) {
|
||||
this.value.data = { cloudInit: config };
|
||||
},
|
||||
|
||||
updateBeforeSave() {
|
||||
@@ -78,6 +84,7 @@ export default {
|
||||
:resource="value"
|
||||
:errors="errors"
|
||||
:apply-hooks="applyHooks"
|
||||
:validation-passed="fvFormIsValid"
|
||||
@finish="save"
|
||||
@cancel="done"
|
||||
@error="e=>errors=e"
|
||||
@@ -86,6 +93,7 @@ export default {
|
||||
:value="value"
|
||||
:mode="mode"
|
||||
:namespaced="true"
|
||||
:rules="{ name: fvGetAndReportPathRules('metadata.name') }"
|
||||
@update:value="$emit('update:value', $event)"
|
||||
/>
|
||||
|
||||
@@ -111,7 +119,7 @@ export default {
|
||||
:mode="mode"
|
||||
class="yaml-editor"
|
||||
:editor-mode="mode === 'view' ? 'VIEW_CODE' : 'EDIT_CODE'"
|
||||
@onChanges="update"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</Tab>
|
||||
@@ -125,9 +133,7 @@ export default {
|
||||
:deep() .yaml-editor{
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
& .code-mirror .CodeMirror {
|
||||
position: initial;
|
||||
height: auto;
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,8 @@ export default {
|
||||
<div class="header mb-20">
|
||||
<FileSelector
|
||||
v-if="isCreate"
|
||||
class="btn btn-sm bg-primary mt-10"
|
||||
variant="primary"
|
||||
class="mt-10"
|
||||
:label="t('generic.readFromFile')"
|
||||
accept=".pub"
|
||||
@selected="onKeySelected"
|
||||
|
||||
@@ -16,6 +16,8 @@ import isEmpty from 'lodash/isEmpty';
|
||||
import jsyaml from 'js-yaml';
|
||||
import { createYaml } from '@shell/utils/create-yaml';
|
||||
import YamlEditor, { EDITOR_MODES } from '@shell/components/YamlEditor';
|
||||
import { foldAllComments } from '@components/RcCodeMirror';
|
||||
import { unfoldCode } from '@codemirror/language';
|
||||
import { FLOW_TYPE } from '../config/harvester-map';
|
||||
|
||||
const LOGGING_EVENT = 'Logging/Event';
|
||||
@@ -172,10 +174,9 @@ export default {
|
||||
});
|
||||
}
|
||||
},
|
||||
onYamlEditorReady(cm) {
|
||||
cm.getMode().fold = 'yamlcomments';
|
||||
cm.execCommand('foldAll');
|
||||
cm.execCommand('unfold');
|
||||
onYamlEditorReady(view) {
|
||||
foldAllComments(view);
|
||||
unfoldCode(view);
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
+14
-1
@@ -7,8 +7,12 @@ import { allHash } from '@shell/utils/promise';
|
||||
import { clone } from '@shell/utils/object';
|
||||
import { HCI } from '../../../types';
|
||||
import { NODE } from '@shell/config/types';
|
||||
import { _CREATE, _CLONE } from '@shell/config/query-params';
|
||||
import { LVM_TOPOLOGY_LABEL } from '../index.vue';
|
||||
|
||||
const STRIPED_TYPE = 'striped';
|
||||
const DM_THIN_TYPE = 'dm-thin';
|
||||
|
||||
const DEFAULT_PARAMETERS = [
|
||||
'type',
|
||||
'vgName'
|
||||
@@ -54,8 +58,17 @@ export default {
|
||||
data() {
|
||||
const node = (this.value.allowedTopologies?.[0]?.matchLabelExpressions || []).find((t) => t.key === LVM_TOPOLOGY_LABEL)?.values[0];
|
||||
|
||||
// striped is dropped once the LVM add-on reaches GA (v1.9.1); dm-thin is the only supported type.
|
||||
const dmThinOnly = this.$store.getters['harvester-common/getFeatureEnabled']('lvmDmThinOnly');
|
||||
const volumeGroupTypes = dmThinOnly ? [DM_THIN_TYPE] : [STRIPED_TYPE, DM_THIN_TYPE];
|
||||
|
||||
// Default new storage classes to dm-thin, and reset a cloned striped type that is no longer selectable.
|
||||
if (dmThinOnly && [_CREATE, _CLONE].includes(this.realMode) && !volumeGroupTypes.includes(this.value.parameters.type)) {
|
||||
this.value.parameters.type = DM_THIN_TYPE;
|
||||
}
|
||||
|
||||
return {
|
||||
volumeGroupTypes: ['striped', 'dm-thin'],
|
||||
volumeGroupTypes,
|
||||
node,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -173,6 +173,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
buttonCb(true);
|
||||
|
||||
this.$router.push({
|
||||
|
||||
@@ -299,6 +299,7 @@ export default {
|
||||
|
||||
const res = await this.value.save();
|
||||
|
||||
res.notifyGeneratedName?.();
|
||||
res.uploadImage(file);
|
||||
|
||||
buttonCb(true);
|
||||
|
||||
@@ -278,6 +278,25 @@ export default {
|
||||
name="Basics"
|
||||
:label="t('harvester.vmTemplate.tabs.basics')"
|
||||
>
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="osType"
|
||||
label-key="harvester.virtualMachine.osType"
|
||||
:mode="mode"
|
||||
:options="OS"
|
||||
:tooltip="isCreate ? t('harvester.virtualMachine.osTypeTooltip') : null"
|
||||
/>
|
||||
</div>
|
||||
<div class="col span-6">
|
||||
<CpuModel
|
||||
:value="spec.template.spec.domain.cpu?.model || ''"
|
||||
:mode="mode"
|
||||
@update:value="updateCpuModel"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CpuMemory
|
||||
class="mb-20"
|
||||
:cpu="cpu"
|
||||
@@ -289,6 +308,69 @@ export default {
|
||||
@updateCpuMemory="updateCpuMemory"
|
||||
/>
|
||||
|
||||
<div class="mb-20">
|
||||
<Checkbox
|
||||
v-if="value.cpuPinningFeatureEnabled"
|
||||
v-model:value="cpuPinning"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.cpuPinning.tooltip"
|
||||
label-key="harvester.virtualMachine.cpuPinning.label"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="installUSBTablet"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.enableUsb')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="tpmEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.systemOptions.tpm"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
||||
v-model:value="tpmPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.tpmPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="efiEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.efiEnabled')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
||||
v-model:value="efiPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.efiPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="efiEnabled"
|
||||
v-model:value="secureBoot"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.secureBoot')"
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="mb-20">
|
||||
<SSHKey
|
||||
v-model:value="sshKey"
|
||||
@@ -308,6 +390,9 @@ export default {
|
||||
>
|
||||
<Volume
|
||||
v-model:value="diskRows"
|
||||
v-model:block-multi-queue="blockMultiQueue"
|
||||
v-model:io-threads-policy="ioThreadsPolicy"
|
||||
v-model:io-thread-count="ioThreadCount"
|
||||
:mode="mode"
|
||||
:namespace="value.metadata.namespace"
|
||||
:existing-volume-disabled="true"
|
||||
@@ -321,6 +406,7 @@ export default {
|
||||
>
|
||||
<Network
|
||||
v-model:value="networkRows"
|
||||
v-model:network-boot-first="networkBootFirst"
|
||||
:mode="mode"
|
||||
/>
|
||||
</Tab>
|
||||
@@ -442,18 +528,6 @@ export default {
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="osType"
|
||||
label-key="harvester.virtualMachine.osType"
|
||||
:mode="mode"
|
||||
:options="OS"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="maintenanceStrategy"
|
||||
@@ -463,6 +537,9 @@ export default {
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<Reserved
|
||||
:reserved-memory="reservedMemory"
|
||||
@@ -472,16 +549,6 @@ export default {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<CpuModel
|
||||
:value="spec.template.spec.domain.cpu?.model || ''"
|
||||
:mode="mode"
|
||||
@update:value="updateCpuModel"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<a
|
||||
v-if="showAdvanced"
|
||||
@@ -519,76 +586,17 @@ export default {
|
||||
:network-script="networkScript"
|
||||
@updateUserData="updateUserData"
|
||||
@updateNetworkData="updateNetworkData"
|
||||
/>
|
||||
|
||||
<div class="spacer"></div>
|
||||
<Checkbox
|
||||
v-if="value.cpuPinningFeatureEnabled"
|
||||
v-model:value="cpuPinning"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.cpuPinning.tooltip"
|
||||
label-key="harvester.virtualMachine.cpuPinning.label"
|
||||
:mode="mode"
|
||||
/>
|
||||
<Checkbox
|
||||
v-model:value="installUSBTablet"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.enableUsb')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="installAgent"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.installAgent"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="tpmEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.advancedOptions.tpm"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
||||
v-model:value="tpmPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.tpmPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="efiEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.efiEnabled')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
||||
v-model:value="efiPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.efiPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="efiEnabled"
|
||||
v-model:value="secureBoot"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.secureBoot')"
|
||||
:mode="mode"
|
||||
/>
|
||||
>
|
||||
<template #after-user-data>
|
||||
<Checkbox
|
||||
v-model:value="installAgent"
|
||||
class="check mb-20"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.installAgent"
|
||||
:mode="mode"
|
||||
/>
|
||||
</template>
|
||||
</CloudConfig>
|
||||
</Tab>
|
||||
</Tabbed>
|
||||
</CruResource>
|
||||
|
||||
@@ -172,6 +172,7 @@ export default {
|
||||
|
||||
try {
|
||||
await proxyResource.save();
|
||||
proxyResource.notifyGeneratedName?.();
|
||||
buttonCb(true);
|
||||
|
||||
this.$router.push({
|
||||
|
||||
@@ -8,6 +8,7 @@ import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import NameNsDescription from '@shell/components/form/NameNsDescription';
|
||||
import Conditions from '@shell/components/form/Conditions';
|
||||
import DiskPerformanceOptions from './kubevirt.io.virtualmachine/VirtualMachineVolume/DiskPerformanceOptions';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { Checkbox } from '@components/Form/Checkbox';
|
||||
import jsyaml from 'js-yaml';
|
||||
@@ -47,7 +48,8 @@ export default {
|
||||
LabeledSelect,
|
||||
LabeledInput,
|
||||
NameNsDescription,
|
||||
Conditions
|
||||
Conditions,
|
||||
DiskPerformanceOptions
|
||||
},
|
||||
|
||||
mixins: [CreateEditView],
|
||||
@@ -100,7 +102,15 @@ export default {
|
||||
createWithDataVolume: false,
|
||||
snapshots: [],
|
||||
images: [],
|
||||
GIBIBYTE
|
||||
GIBIBYTE,
|
||||
// Default KubeVirt high-performance disk profile, stored as annotations and
|
||||
// applied when this volume is later attached to a VM as a disk.
|
||||
perf: {
|
||||
cache: get(this.value, `metadata.annotations."${ HCI_ANNOTATIONS.DISK_CACHE_MODE }"`) || '',
|
||||
io: get(this.value, `metadata.annotations."${ HCI_ANNOTATIONS.DISK_IO_MODE }"`) || '',
|
||||
dedicatedIOThread: get(this.value, `metadata.annotations."${ HCI_ANNOTATIONS.DISK_DEDICATED_IOTHREAD }"`) === 'true',
|
||||
volumeMode: this.value?.spec?.volumeMode,
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -332,6 +342,7 @@ export default {
|
||||
}
|
||||
},
|
||||
'value.spec.volumeMode'(neu) {
|
||||
this.perf.volumeMode = neu;
|
||||
if (neu === VOLUME_MODE.FILE_SYSTEM) {
|
||||
this.setVolumeForVmAnnotation();
|
||||
} else if (neu === VOLUME_MODE.BLOCK ) {
|
||||
@@ -446,6 +457,23 @@ export default {
|
||||
imageAnnotations = { ...this.value.metadata.annotations };
|
||||
}
|
||||
|
||||
// Persist the default high-performance disk profile as annotations.
|
||||
if (this.perf.cache) {
|
||||
imageAnnotations[HCI_ANNOTATIONS.DISK_CACHE_MODE] = this.perf.cache;
|
||||
} else {
|
||||
delete imageAnnotations[HCI_ANNOTATIONS.DISK_CACHE_MODE];
|
||||
}
|
||||
if (this.perf.io) {
|
||||
imageAnnotations[HCI_ANNOTATIONS.DISK_IO_MODE] = this.perf.io;
|
||||
} else {
|
||||
delete imageAnnotations[HCI_ANNOTATIONS.DISK_IO_MODE];
|
||||
}
|
||||
if (this.perf.dedicatedIOThread) {
|
||||
imageAnnotations[HCI_ANNOTATIONS.DISK_DEDICATED_IOTHREAD] = 'true';
|
||||
} else {
|
||||
delete imageAnnotations[HCI_ANNOTATIONS.DISK_DEDICATED_IOTHREAD];
|
||||
}
|
||||
|
||||
const spec = {
|
||||
...this.value.spec,
|
||||
resources: { requests: { storage: this.storage } },
|
||||
@@ -610,6 +638,16 @@ export default {
|
||||
class="mb-20"
|
||||
@update:value="update"
|
||||
/>
|
||||
|
||||
<Banner
|
||||
color="info"
|
||||
:label="t('harvester.volume.performance.pvcTip')"
|
||||
/>
|
||||
<DiskPerformanceOptions
|
||||
:value="perf"
|
||||
:mode="mode"
|
||||
@update="update"
|
||||
/>
|
||||
</Tab>
|
||||
<Tab
|
||||
v-if="!isCreate"
|
||||
|
||||
+1
-1
@@ -157,7 +157,7 @@ $yaml-height: 200px;
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,8 @@ export default {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<slot name="after-user-data" />
|
||||
|
||||
<div class="mb-20">
|
||||
<DataTemplate
|
||||
ref="networkTemplate"
|
||||
@@ -287,7 +289,7 @@ $yaml-height: 350px;
|
||||
flex: 1;
|
||||
min-height: $yaml-height;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $yaml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
import InputOrDisplay from '@shell/components/InputOrDisplay';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import { Checkbox } from '@components/Form/Checkbox';
|
||||
|
||||
import { clone } from '@shell/utils/object';
|
||||
import { _CREATE, _VIEW } from '@shell/config/query-params';
|
||||
@@ -33,7 +34,7 @@ export default {
|
||||
emits: ['update'],
|
||||
|
||||
components: {
|
||||
LabeledInput, LabeledSelect, InputOrDisplay
|
||||
LabeledInput, LabeledSelect, InputOrDisplay, Checkbox
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -169,6 +170,7 @@ export default {
|
||||
this.value.isPod = true;
|
||||
this.value.macAddress = '';
|
||||
this.value.staticIp = '';
|
||||
this.value.networkBoot = false;
|
||||
} else {
|
||||
this.value.isPod = false;
|
||||
}
|
||||
@@ -285,6 +287,22 @@ export default {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="!isMasquerade"
|
||||
data-testid="input-hen-networkBoot"
|
||||
class="row mb-20"
|
||||
>
|
||||
<div class="col span-12">
|
||||
<Checkbox
|
||||
v-model:value="value.networkBoot"
|
||||
:label="t('harvester.virtualMachine.network.networkBoot.label')"
|
||||
:tooltip="t('harvester.virtualMachine.network.networkBoot.tip')"
|
||||
:mode="mode"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!isMasquerade && isSingle">
|
||||
<div class="row mb-20">
|
||||
<a
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import InfoBox from '@shell/components/InfoBox';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import { NETWORK_ATTACHMENT } from '@shell/config/types';
|
||||
import { sortBy } from '@shell/utils/sort';
|
||||
import { clone } from '@shell/utils/object';
|
||||
@@ -10,7 +11,11 @@ import { HCI as HCI_ANNOTATIONS } from '../../../config/labels-annotations';
|
||||
import Base from './base';
|
||||
|
||||
export default {
|
||||
components: { InfoBox, Base },
|
||||
components: {
|
||||
InfoBox, Base, RadioGroup
|
||||
},
|
||||
|
||||
emits: ['update:value', 'update:networkBootFirst'],
|
||||
|
||||
props: {
|
||||
vm: {
|
||||
@@ -35,6 +40,11 @@ export default {
|
||||
isSingle: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
|
||||
networkBootFirst: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
},
|
||||
|
||||
@@ -82,6 +92,20 @@ export default {
|
||||
|
||||
vmState() {
|
||||
return this.vm?.stateDisplay;
|
||||
},
|
||||
|
||||
hasNetworkBoot() {
|
||||
return this.rows.some((R) => R.networkBoot);
|
||||
},
|
||||
|
||||
networkBootOrderOptions() {
|
||||
return [{
|
||||
label: this.t('harvester.virtualMachine.network.networkBoot.first'),
|
||||
value: true
|
||||
}, {
|
||||
label: this.t('harvester.virtualMachine.network.networkBoot.last'),
|
||||
value: false
|
||||
}];
|
||||
}
|
||||
},
|
||||
|
||||
@@ -218,6 +242,22 @@ export default {
|
||||
/>
|
||||
</InfoBox>
|
||||
|
||||
<div
|
||||
v-if="hasNetworkBoot"
|
||||
data-testid="input-hen-networkBootFirst"
|
||||
class="mb-20"
|
||||
>
|
||||
<RadioGroup
|
||||
:value="networkBootFirst"
|
||||
name="networkBootFirst"
|
||||
:label="t('harvester.virtualMachine.network.networkBoot.order')"
|
||||
:options="networkBootOrderOptions"
|
||||
:mode="mode"
|
||||
:row="true"
|
||||
@update:value="$emit('update:networkBootFirst', $event)"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
v-if="!isView"
|
||||
type="button"
|
||||
|
||||
+321
@@ -0,0 +1,321 @@
|
||||
<script>
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import { Checkbox } from '@components/Form/Checkbox';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { _VIEW } from '@shell/config/query-params';
|
||||
import { DISK_CACHE_MODE, DISK_IO_MODE, DISK_PERFORMANCE_PROFILE } from '../../../config/harvester-map';
|
||||
|
||||
const { DEFAULT, HIGH, CUSTOM } = DISK_PERFORMANCE_PROFILE;
|
||||
|
||||
export default {
|
||||
name: 'DiskPerformanceOptions',
|
||||
|
||||
components: {
|
||||
LabeledSelect, Checkbox, Banner
|
||||
},
|
||||
|
||||
emits: ['update'],
|
||||
|
||||
props: {
|
||||
// The disk row. This component reads/writes value.cache, value.io,
|
||||
// value.dedicatedIOThread and (for the "High Performance" preset) value.bus.
|
||||
value: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
|
||||
mode: {
|
||||
type: String,
|
||||
default: 'create'
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
const hasPerf = !!(this.value.cache || this.value.io || this.value.dedicatedIOThread);
|
||||
|
||||
return {
|
||||
DISK_PERFORMANCE_PROFILE,
|
||||
expanded: hasPerf,
|
||||
profile: this.detectProfile(),
|
||||
// Bus the disk used before the "High Performance" preset switched it to
|
||||
// virtio, so returning to "Default" can put it back.
|
||||
busBeforeHighProfile: null,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
isView() {
|
||||
return this.mode === _VIEW;
|
||||
},
|
||||
|
||||
storagePerformanceEnabled() {
|
||||
return this.$store.getters['harvester-common/getFeatureEnabled']('highPerformanceStorage');
|
||||
},
|
||||
|
||||
isCdRom() {
|
||||
return this.value.type === 'cd-rom';
|
||||
},
|
||||
|
||||
isCustom() {
|
||||
return this.profile === CUSTOM;
|
||||
},
|
||||
|
||||
isNativeIo() {
|
||||
return this.value.io === 'native';
|
||||
},
|
||||
|
||||
profileOptions() {
|
||||
return [DEFAULT, HIGH, CUSTOM].map((value) => ({
|
||||
label: this.t(`harvester.virtualMachine.volume.performance.profile.${ value }`),
|
||||
value,
|
||||
}));
|
||||
},
|
||||
|
||||
cacheOptions() {
|
||||
return DISK_CACHE_MODE.map((value) => ({
|
||||
label: this.cacheLabel(value),
|
||||
value,
|
||||
// Native AIO only works with an uncached (O_DIRECT) disk, so while it is
|
||||
// selected the only valid cache option is "none" — disable everything
|
||||
// else, including "Default", to prevent an invalid combination.
|
||||
disabled: this.isNativeIo && value !== 'none',
|
||||
}));
|
||||
},
|
||||
|
||||
ioOptions() {
|
||||
return DISK_IO_MODE.map((value) => ({
|
||||
label: value === '' ? this.t('harvester.virtualMachine.volume.performance.ioMode.default') : this.t(`harvester.virtualMachine.volume.performance.ioMode.${ value }`),
|
||||
value,
|
||||
}));
|
||||
},
|
||||
|
||||
showFilesystemCacheWarning() {
|
||||
return this.value.cache === 'none' && this.value.volumeMode === 'Filesystem';
|
||||
},
|
||||
|
||||
showBusTip() {
|
||||
const hasPerf = !!(this.value.cache || this.value.io || this.value.dedicatedIOThread);
|
||||
|
||||
return hasPerf && this.value.bus && this.value.bus !== 'virtio';
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
// Keep the profile selector in sync if the row is repopulated (e.g. editing an existing VM).
|
||||
'value.cache'() {
|
||||
this.profile = this.detectProfile();
|
||||
},
|
||||
'value.io'() {
|
||||
this.profile = this.detectProfile();
|
||||
},
|
||||
'value.dedicatedIOThread'() {
|
||||
this.profile = this.detectProfile();
|
||||
},
|
||||
},
|
||||
|
||||
methods: {
|
||||
detectProfile() {
|
||||
const { cache, io, dedicatedIOThread } = this.value;
|
||||
|
||||
if (!cache && !io && !dedicatedIOThread) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
if (cache === 'none' && io === 'native' && dedicatedIOThread) {
|
||||
return HIGH;
|
||||
}
|
||||
|
||||
return CUSTOM;
|
||||
},
|
||||
|
||||
cacheLabel(value) {
|
||||
if (value === '') {
|
||||
return this.t('harvester.virtualMachine.volume.performance.cacheMode.default');
|
||||
}
|
||||
|
||||
return this.t(`harvester.virtualMachine.volume.performance.cacheMode.${ value }`);
|
||||
},
|
||||
|
||||
onProfileChange(profile) {
|
||||
const previous = this.profile;
|
||||
|
||||
this.profile = profile;
|
||||
|
||||
if (profile === DEFAULT) {
|
||||
this.value.cache = '';
|
||||
this.value.io = '';
|
||||
this.value.dedicatedIOThread = false;
|
||||
|
||||
// "Default" means no overrides, so also undo the virtio bus that the
|
||||
// "High Performance" preset applied. Skip it if the user has since
|
||||
// picked a different bus themselves — that choice is theirs to keep.
|
||||
if (this.busBeforeHighProfile !== null) {
|
||||
if (this.value.bus === 'virtio') {
|
||||
this.value.bus = this.busBeforeHighProfile;
|
||||
}
|
||||
this.busBeforeHighProfile = null;
|
||||
}
|
||||
} else if (profile === HIGH) {
|
||||
this.value.cache = 'none';
|
||||
this.value.io = 'native';
|
||||
this.value.dedicatedIOThread = true;
|
||||
|
||||
if (previous !== HIGH) {
|
||||
this.busBeforeHighProfile = this.value.bus || '';
|
||||
}
|
||||
this.value.bus = 'virtio';
|
||||
}
|
||||
// CUSTOM keeps whatever is currently set, including the bus.
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
onIoChange(io) {
|
||||
this.value.io = io;
|
||||
// Native AIO requires an uncached disk; force cache to "none" to keep the
|
||||
// combo valid — including when cache is still on its "Default" ('') value,
|
||||
// which libvirt would otherwise reject at domain start.
|
||||
if (io === 'native' && this.value.cache !== 'none') {
|
||||
this.value.cache = 'none';
|
||||
}
|
||||
this.update();
|
||||
},
|
||||
|
||||
update() {
|
||||
this.$emit('update');
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="!isCdRom && storagePerformanceEnabled"
|
||||
class="disk-performance"
|
||||
>
|
||||
<button
|
||||
v-if="!isView"
|
||||
type="button"
|
||||
class="btn btn-sm role-link expand-toggle"
|
||||
:aria-expanded="expanded"
|
||||
:aria-label="expanded ? t('harvester.virtualMachine.volume.performance.collapse') : t('harvester.virtualMachine.volume.performance.expand')"
|
||||
@click.prevent="expanded = !expanded"
|
||||
>
|
||||
<i
|
||||
class="icon"
|
||||
:class="expanded ? 'icon-chevron-down' : 'icon-chevron-right'"
|
||||
/>
|
||||
{{ t('harvester.virtualMachine.volume.performance.title') }}
|
||||
</button>
|
||||
|
||||
<div
|
||||
v-if="expanded || isView"
|
||||
class="perf-body mt-10"
|
||||
>
|
||||
<div class="row mb-20">
|
||||
<div
|
||||
class="col span-6"
|
||||
data-testid="input-disk-perf-profile"
|
||||
>
|
||||
<LabeledSelect
|
||||
:value="profile"
|
||||
:label="t('harvester.virtualMachine.volume.performance.profile.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.performance.profile.tip')"
|
||||
:options="profileOptions"
|
||||
:mode="mode"
|
||||
@update:value="onProfileChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Banner
|
||||
v-if="profile === DISK_PERFORMANCE_PROFILE.HIGH"
|
||||
color="info"
|
||||
:label="t('harvester.virtualMachine.volume.performance.highProfileTip')"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="isCustom || isView"
|
||||
class="row mb-20"
|
||||
>
|
||||
<div
|
||||
class="col span-6"
|
||||
data-testid="input-disk-cache"
|
||||
>
|
||||
<LabeledSelect
|
||||
v-model:value="value.cache"
|
||||
:label="t('harvester.virtualMachine.volume.performance.cacheMode.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.performance.cacheMode.tip')"
|
||||
:options="cacheOptions"
|
||||
:mode="mode"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
class="col span-6"
|
||||
data-testid="input-disk-io"
|
||||
>
|
||||
<LabeledSelect
|
||||
:value="value.io"
|
||||
:label="t('harvester.virtualMachine.volume.performance.ioMode.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.performance.ioMode.tip')"
|
||||
:options="ioOptions"
|
||||
:mode="mode"
|
||||
@update:value="onIoChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="isCustom || isView"
|
||||
class="row mb-10"
|
||||
>
|
||||
<div
|
||||
class="col span-12"
|
||||
data-testid="input-disk-dedicated-iothread"
|
||||
>
|
||||
<Checkbox
|
||||
v-model:value="value.dedicatedIOThread"
|
||||
:label="t('harvester.virtualMachine.volume.performance.dedicatedIOThread.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.performance.dedicatedIOThread.tip')"
|
||||
:mode="mode"
|
||||
@update:value="update"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Banner
|
||||
v-if="isNativeIo"
|
||||
color="info"
|
||||
:label="t('harvester.virtualMachine.volume.performance.ioMode.nativeRequiresNoCacheTip')"
|
||||
/>
|
||||
<Banner
|
||||
v-if="showFilesystemCacheWarning"
|
||||
color="warning"
|
||||
:label="t('harvester.virtualMachine.volume.performance.cacheMode.filesystemWarning')"
|
||||
/>
|
||||
<Banner
|
||||
v-if="showBusTip"
|
||||
color="warning"
|
||||
:label="t('harvester.virtualMachine.volume.performance.busTip')"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.disk-performance {
|
||||
border-top: 1px solid var(--border);
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
|
||||
.expand-toggle {
|
||||
padding: 0;
|
||||
font-weight: 600;
|
||||
|
||||
.icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<script>
|
||||
import InfoBox from '@shell/components/InfoBox';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import { Checkbox } from '@components/Form/Checkbox';
|
||||
import { Banner } from '@components/Banner';
|
||||
import { _VIEW } from '@shell/config/query-params';
|
||||
import { IO_THREADS_POLICY } from '../../../config/harvester-map';
|
||||
|
||||
export default {
|
||||
name: 'VMPerformanceOptions',
|
||||
|
||||
components: {
|
||||
InfoBox, LabeledSelect, LabeledInput, Checkbox, Banner
|
||||
},
|
||||
|
||||
emits: ['update:blockMultiQueue', 'update:ioThreadsPolicy', 'update:ioThreadCount'],
|
||||
|
||||
props: {
|
||||
blockMultiQueue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
|
||||
ioThreadsPolicy: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
|
||||
ioThreadCount: {
|
||||
type: Number,
|
||||
default: 2
|
||||
},
|
||||
|
||||
mode: {
|
||||
type: String,
|
||||
default: 'create'
|
||||
},
|
||||
|
||||
// Whether the current disk set contains a virtio disk (VM context only).
|
||||
hasVirtioDisk: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
},
|
||||
|
||||
// Whether any disk requests a dedicated I/O thread (drives the auto-enable hint).
|
||||
hasDedicatedIothread: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
},
|
||||
|
||||
data() {
|
||||
// These are specialist tuning options, so keep the panel collapsed unless the
|
||||
// VM already has something configured.
|
||||
return { expanded: !!(this.blockMultiQueue || this.ioThreadsPolicy) };
|
||||
},
|
||||
|
||||
computed: {
|
||||
isView() {
|
||||
return this.mode === _VIEW;
|
||||
},
|
||||
|
||||
storagePerformanceEnabled() {
|
||||
return this.$store.getters['harvester-common/getFeatureEnabled']('highPerformanceStorage');
|
||||
},
|
||||
|
||||
ioThreadsPolicyOptions() {
|
||||
return IO_THREADS_POLICY.map((value) => ({
|
||||
label: value === '' ? this.t('harvester.virtualMachine.volume.diskPerformance.ioThreadsPolicy.default') : this.t(`harvester.virtualMachine.volume.diskPerformance.ioThreadsPolicy.${ value }`),
|
||||
value,
|
||||
}));
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
// Block Multi-Queue only applies to virtio disks. If the last virtio disk is
|
||||
// removed while it is enabled, clear it so the VM is not left with an invalid
|
||||
// setting the disabled checkbox can no longer surface.
|
||||
hasVirtioDisk(neu) {
|
||||
if (!neu && this.blockMultiQueue) {
|
||||
this.$emit('update:blockMultiQueue', false);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<InfoBox
|
||||
v-if="storagePerformanceEnabled && (!isView || blockMultiQueue || !!ioThreadsPolicy)"
|
||||
class="vm-perf mt-10"
|
||||
>
|
||||
<button
|
||||
v-if="!isView"
|
||||
type="button"
|
||||
class="btn btn-sm role-link expand-toggle"
|
||||
:aria-expanded="expanded"
|
||||
:aria-label="expanded ? t('harvester.virtualMachine.volume.diskPerformance.collapse') : t('harvester.virtualMachine.volume.diskPerformance.expand')"
|
||||
@click.prevent="expanded = !expanded"
|
||||
>
|
||||
<i
|
||||
class="icon"
|
||||
:class="expanded ? 'icon-chevron-down' : 'icon-chevron-right'"
|
||||
/>
|
||||
{{ t('harvester.virtualMachine.volume.diskPerformance.title') }}
|
||||
</button>
|
||||
<h3
|
||||
v-else
|
||||
class="mb-5"
|
||||
>
|
||||
{{ t('harvester.virtualMachine.volume.diskPerformance.title') }}
|
||||
</h3>
|
||||
|
||||
<template v-if="expanded || isView">
|
||||
<p class="text-muted mb-15 mt-10">
|
||||
{{ t('harvester.virtualMachine.volume.diskPerformance.description') }}
|
||||
</p>
|
||||
|
||||
<div class="row mb-10">
|
||||
<div
|
||||
class="col span-12"
|
||||
data-testid="input-vm-block-multi-queue"
|
||||
>
|
||||
<Checkbox
|
||||
:value="blockMultiQueue"
|
||||
:label="t('harvester.virtualMachine.volume.diskPerformance.blockMultiQueue.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.diskPerformance.blockMultiQueue.tip')"
|
||||
:mode="mode"
|
||||
:disabled="!hasVirtioDisk"
|
||||
@update:value="$emit('update:blockMultiQueue', $event)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Banner
|
||||
v-if="!hasVirtioDisk && !isView"
|
||||
color="info"
|
||||
:label="t('harvester.virtualMachine.volume.diskPerformance.blockMultiQueue.noVirtioTip')"
|
||||
/>
|
||||
|
||||
<div class="row mb-10">
|
||||
<div
|
||||
class="col span-6"
|
||||
data-testid="input-vm-iothreads-policy"
|
||||
>
|
||||
<LabeledSelect
|
||||
:value="ioThreadsPolicy"
|
||||
:label="t('harvester.virtualMachine.volume.diskPerformance.ioThreadsPolicy.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.diskPerformance.ioThreadsPolicy.tip')"
|
||||
:options="ioThreadsPolicyOptions"
|
||||
:mode="mode"
|
||||
@update:value="$emit('update:ioThreadsPolicy', $event)"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-if="ioThreadsPolicy === 'supplementalPool'"
|
||||
class="col span-6"
|
||||
data-testid="input-vm-iothread-count"
|
||||
>
|
||||
<LabeledInput
|
||||
type="number"
|
||||
min="1"
|
||||
:value="ioThreadCount"
|
||||
:label="t('harvester.virtualMachine.volume.diskPerformance.ioThreadCount.label')"
|
||||
:tooltip="t('harvester.virtualMachine.volume.diskPerformance.ioThreadCount.tip')"
|
||||
:mode="mode"
|
||||
@update:value="$emit('update:ioThreadCount', Number($event))"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<Banner
|
||||
v-if="hasDedicatedIothread && !ioThreadsPolicy"
|
||||
color="info"
|
||||
:label="t('harvester.virtualMachine.volume.diskPerformance.ioThreadsPolicy.autoEnabledTip')"
|
||||
/>
|
||||
</template>
|
||||
</InfoBox>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.vm-perf {
|
||||
.expand-toggle {
|
||||
padding: 0;
|
||||
font-weight: 600;
|
||||
|
||||
.icon {
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
import { mount } from '@vue/test-utils';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import DiskPerformanceOptions from '../DiskPerformanceOptions.vue';
|
||||
|
||||
const mountOptions = (value, { featureEnabled = true } = {}) => ({
|
||||
props: { value, mode: _EDIT },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => featureEnabled,
|
||||
'i18n/t': (key) => key,
|
||||
'i18n/exists': () => true,
|
||||
}
|
||||
},
|
||||
t: (key) => key,
|
||||
},
|
||||
}
|
||||
});
|
||||
|
||||
const hardDisk = (overrides = {}) => ({
|
||||
type: 'disk', bus: 'virtio', cache: '', io: '', dedicatedIOThread: false, ...overrides
|
||||
});
|
||||
|
||||
describe('component: DiskPerformanceOptions', () => {
|
||||
it('is hidden when the highPerformanceStorage feature is disabled', () => {
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(hardDisk(), { featureEnabled: false }));
|
||||
|
||||
expect(wrapper.find('.disk-performance').exists()).toBe(false);
|
||||
});
|
||||
|
||||
it('renders for a hard disk when the feature is enabled', () => {
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(hardDisk()));
|
||||
|
||||
expect(wrapper.find('.disk-performance').exists()).toBe(true);
|
||||
});
|
||||
|
||||
it('applies the High Performance preset and emits update', () => {
|
||||
const value = hardDisk();
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onProfileChange('highPerformance');
|
||||
|
||||
expect(value.cache).toBe('none');
|
||||
expect(value.io).toBe('native');
|
||||
expect(value.dedicatedIOThread).toBe(true);
|
||||
expect(value.bus).toBe('virtio');
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('clears all overrides when switching back to Default', () => {
|
||||
const value = hardDisk({
|
||||
cache: 'none', io: 'native', dedicatedIOThread: true
|
||||
});
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onProfileChange('default');
|
||||
|
||||
expect(value.cache).toBe('');
|
||||
expect(value.io).toBe('');
|
||||
expect(value.dedicatedIOThread).toBe(false);
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('restores the original bus when leaving High Performance for Default', () => {
|
||||
const value = hardDisk({ bus: 'sata' });
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onProfileChange('highPerformance');
|
||||
expect(value.bus).toBe('virtio');
|
||||
|
||||
wrapper.vm.onProfileChange('default');
|
||||
expect(value.bus).toBe('sata');
|
||||
});
|
||||
|
||||
it('keeps a bus the user picked themselves after High Performance', () => {
|
||||
const value = hardDisk({ bus: 'sata' });
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onProfileChange('highPerformance');
|
||||
value.bus = 'scsi';
|
||||
|
||||
wrapper.vm.onProfileChange('default');
|
||||
expect(value.bus).toBe('scsi');
|
||||
});
|
||||
|
||||
it('leaves the bus alone for a disk that never used the High Performance preset', () => {
|
||||
const value = hardDisk({
|
||||
bus: 'sata', cache: 'writeback', io: 'threads'
|
||||
});
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onProfileChange('default');
|
||||
expect(value.bus).toBe('sata');
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a cached state', 'writeback'],
|
||||
['the Default cache', ''],
|
||||
])('forces cache to none when Native I/O is selected from %s', (_label, cache) => {
|
||||
const value = hardDisk({ cache });
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(value));
|
||||
|
||||
wrapper.vm.onIoChange('native');
|
||||
|
||||
expect(value.io).toBe('native');
|
||||
expect(value.cache).toBe('none');
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('disables every cache option except none while Native I/O is active', () => {
|
||||
const wrapper = mount(DiskPerformanceOptions, mountOptions(hardDisk({ io: 'native' })));
|
||||
|
||||
const disabledByValue = wrapper.vm.cacheOptions.reduce((acc, opt) => {
|
||||
acc[opt.value] = opt.disabled;
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
|
||||
expect(disabledByValue['none']).toBe(false);
|
||||
expect(disabledByValue['']).toBe(true);
|
||||
expect(disabledByValue['writeback']).toBe(true);
|
||||
expect(disabledByValue['writethrough']).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -7,13 +7,14 @@ import UnitInput from '@shell/components/form/UnitInput';
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import ModalWithCard from '@shell/components/ModalWithCard';
|
||||
import VMPerformanceOptions from './VMPerformanceOptions';
|
||||
import { VOLUME_HOTPLUG_ACTION, SOURCE_TYPE } from '../../../config/harvester-map';
|
||||
import { PVC, STORAGE_CLASS } from '@shell/config/types';
|
||||
import { clone } from '@shell/utils/object';
|
||||
import { ucFirst, randomStr } from '@shell/utils/string';
|
||||
import { removeObject } from '@shell/utils/array';
|
||||
import { _VIEW, _EDIT, _CREATE } from '@shell/config/query-params';
|
||||
import { PLUGIN_DEVELOPER, DEV } from '@shell/store/prefs';
|
||||
import { VOLUME_HOTPLUG_ACTION, SOURCE_TYPE } from '../../../config/harvester-map';
|
||||
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../../../config/harvester';
|
||||
import { HCI } from '../../../types';
|
||||
import { VOLUME_MODE, ACCESS_MODE } from '@pkg/harvester/config/types';
|
||||
@@ -23,10 +24,10 @@ import { EMPTY_IMAGE } from '../../../utils/vm';
|
||||
const { READ_WRITE_MANY } = ACCESS_MODE;
|
||||
|
||||
export default {
|
||||
emits: ['update:value'],
|
||||
emits: ['update:value', 'update:blockMultiQueue', 'update:ioThreadsPolicy', 'update:ioThreadCount'],
|
||||
|
||||
components: {
|
||||
Banner, BadgeStateFormatter, VueDraggableNext, InfoBox, LabeledInput, UnitInput, LabeledSelect, ModalWithCard
|
||||
Banner, BadgeStateFormatter, VueDraggableNext, InfoBox, LabeledInput, UnitInput, LabeledSelect, ModalWithCard, VMPerformanceOptions
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -77,6 +78,22 @@ export default {
|
||||
resourceType: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
|
||||
// KubeVirt high-performance VM-level features
|
||||
blockMultiQueue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
|
||||
ioThreadsPolicy: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
|
||||
ioThreadCount: {
|
||||
type: Number,
|
||||
default: 2
|
||||
}
|
||||
},
|
||||
|
||||
@@ -147,6 +164,14 @@ export default {
|
||||
isLHV2VolExpansionFeatureEnabled() {
|
||||
return this.$store.getters['harvester-common/getFeatureEnabled']('lhV2VolExpansion');
|
||||
},
|
||||
|
||||
hasVirtioDisk() {
|
||||
return this.rows.some((R) => R.type === 'disk' && R.bus === 'virtio');
|
||||
},
|
||||
|
||||
hasDedicatedIOThread() {
|
||||
return this.rows.some((R) => R.dedicatedIOThread);
|
||||
},
|
||||
},
|
||||
|
||||
watch: {
|
||||
@@ -508,6 +533,18 @@ export default {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<VMPerformanceOptions
|
||||
:block-multi-queue="blockMultiQueue"
|
||||
:io-threads-policy="ioThreadsPolicy"
|
||||
:io-thread-count="ioThreadCount"
|
||||
:has-virtio-disk="hasVirtioDisk"
|
||||
:has-dedicated-iothread="hasDedicatedIOThread"
|
||||
:mode="mode"
|
||||
@update:block-multi-queue="$emit('update:blockMultiQueue', $event)"
|
||||
@update:io-threads-policy="$emit('update:ioThreadsPolicy', $event)"
|
||||
@update:io-thread-count="$emit('update:ioThreadCount', $event)"
|
||||
/>
|
||||
|
||||
<ModalWithCard
|
||||
v-if="isOpen"
|
||||
name="deleteTip"
|
||||
|
||||
+17
-3
@@ -2,9 +2,23 @@ import { mount } from '@vue/test-utils';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import HarvesterEditContainer from '../container.vue';
|
||||
|
||||
const mountOptions = () => ({
|
||||
props: { mode: _EDIT, value: {} },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
describe('component: HarvesterEditContainer', () => {
|
||||
it('should display all the inputs', () => {
|
||||
const wrapper = mount(HarvesterEditContainer, { propsData: { mode: _EDIT, value: {} } });
|
||||
const wrapper = mount(HarvesterEditContainer, mountOptions());
|
||||
|
||||
const inputWraps = wrapper.findAll('[data-testid^=input-hec-]');
|
||||
|
||||
@@ -15,7 +29,7 @@ describe('component: HarvesterEditContainer', () => {
|
||||
'name',
|
||||
'container',
|
||||
])('should emit an update on %p input', (field) => {
|
||||
const wrapper = mount(HarvesterEditContainer, { propsData: { mode: _EDIT, value: {} } });
|
||||
const wrapper = mount(HarvesterEditContainer, mountOptions());
|
||||
const input = wrapper.find(`[data-testid="input-hec-${ field }"]`).find('input');
|
||||
const newValue = 123;
|
||||
|
||||
@@ -28,7 +42,7 @@ describe('component: HarvesterEditContainer', () => {
|
||||
'type',
|
||||
'bus',
|
||||
])('should emit an update on %p selection change', async(field) => {
|
||||
const wrapper = mount(HarvesterEditContainer, { propsData: { mode: _EDIT, value: {} } });
|
||||
const wrapper = mount(HarvesterEditContainer, mountOptions());
|
||||
const select = wrapper.find(`[data-testid="input-hec-${ field }"]`);
|
||||
|
||||
select.find('button').trigger('click');
|
||||
|
||||
+36
-24
@@ -5,14 +5,17 @@ import HarvesterEditExisting from '../existing.vue';
|
||||
describe('component: HarvesterEditExisting', () => {
|
||||
it('should display all the inputs', () => {
|
||||
const wrapper = mount(HarvesterEditExisting, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _EDIT, value: {}, rows: []
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,14 +30,17 @@ describe('component: HarvesterEditExisting', () => {
|
||||
'name',
|
||||
])('should emit an update on %p input', (field) => {
|
||||
const wrapper = mount(HarvesterEditExisting, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _EDIT, value: {}, rows: []
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -53,14 +59,17 @@ describe('component: HarvesterEditExisting', () => {
|
||||
'size',
|
||||
])('should emit an update on %p input and blur', (field) => {
|
||||
const wrapper = mount(HarvesterEditExisting, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _EDIT, value: {}, rows: []
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,14 +89,17 @@ describe('component: HarvesterEditExisting', () => {
|
||||
// 'bus', // disabled
|
||||
])('should emit an update on %p selection change', async(field) => {
|
||||
const wrapper = mount(HarvesterEditExisting, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _EDIT, value: {}, rows: []
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': () => [],
|
||||
'i18n/t': jest.fn()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+55
-36
@@ -2,23 +2,29 @@ import { mount } from '@vue/test-utils';
|
||||
import { _CREATE } from '@shell/config/query-params';
|
||||
import HarvesterEditVMImage from '../vmImage.vue';
|
||||
|
||||
// The form emits an update when it is created, so count only the updates that an interaction adds
|
||||
const updates = (wrapper) => wrapper.emitted('update')?.length ?? 0;
|
||||
|
||||
describe('component: HarvesterEditVMImage', () => {
|
||||
it('should display all the inputs', () => {
|
||||
const wrapper = mount(HarvesterEditVMImage, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _CREATE,
|
||||
isVirtualType: false,
|
||||
newCreateId: '123',
|
||||
validateRequired: true,
|
||||
idx: 1
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -31,20 +37,23 @@ describe('component: HarvesterEditVMImage', () => {
|
||||
'name',
|
||||
])('should emit an update on %p input', (field) => {
|
||||
const wrapper = mount(HarvesterEditVMImage, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _CREATE,
|
||||
isVirtualType: false,
|
||||
newCreateId: '123',
|
||||
validateRequired: true,
|
||||
idx: 1
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const input = wrapper.find(`[data-testid="input-hevi-${ field }"]`).find('input');
|
||||
@@ -57,31 +66,38 @@ describe('component: HarvesterEditVMImage', () => {
|
||||
|
||||
it.each([
|
||||
'size',
|
||||
])('should emit an update on %p input blur', (field) => {
|
||||
])('should emit an update on %p input blur', async(field) => {
|
||||
const wrapper = mount(HarvesterEditVMImage, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _CREATE,
|
||||
isVirtualType: false,
|
||||
newCreateId: '123',
|
||||
validateRequired: true,
|
||||
idx: 1
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const input = wrapper.find(`[data-testid="input-hevi-${ field }"]`).find('input');
|
||||
const newValue = 123;
|
||||
|
||||
input.setValue(newValue);
|
||||
input.trigger('blur');
|
||||
// setting the value already emits an update, so the blur has to add one on top of that
|
||||
await input.setValue(newValue);
|
||||
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
const afterSetValue = updates(wrapper);
|
||||
|
||||
await input.trigger('blur');
|
||||
|
||||
expect(updates(wrapper)).toBeGreaterThan(afterSetValue);
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -90,20 +106,23 @@ describe('component: HarvesterEditVMImage', () => {
|
||||
'bus',
|
||||
])('should emit an update on %p selection change', async(field) => {
|
||||
const wrapper = mount(HarvesterEditVMImage, {
|
||||
propsData: {
|
||||
props: {
|
||||
mode: _CREATE,
|
||||
isVirtualType: false,
|
||||
newCreateId: '123',
|
||||
validateRequired: true,
|
||||
idx: 1
|
||||
},
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const select = wrapper.find(`[data-testid="input-hevi-${ field }"]`);
|
||||
|
||||
+74
-37
@@ -2,18 +2,24 @@ import { mount } from '@vue/test-utils';
|
||||
import { _EDIT } from '@shell/config/query-params';
|
||||
import HarvesterEditVolume from '../volume.vue';
|
||||
|
||||
// The form emits an update when it is created, so count only the updates that an interaction adds
|
||||
const updates = (wrapper) => wrapper.emitted('update')?.length ?? 0;
|
||||
|
||||
describe('component: HarvesterEditVolume', () => {
|
||||
it('should display all the inputs', () => {
|
||||
const wrapper = mount(HarvesterEditVolume, {
|
||||
propsData: { validateRequired: true },
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
props: { validateRequired: true },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,29 +28,56 @@ describe('component: HarvesterEditVolume', () => {
|
||||
expect(inputWraps).toHaveLength(4);
|
||||
});
|
||||
|
||||
it.each([
|
||||
'name',
|
||||
'size',
|
||||
])('should emit an update on %p input blur', (field) => {
|
||||
it('should emit an update on name input', async() => {
|
||||
const wrapper = mount(HarvesterEditVolume, {
|
||||
propsData: { mode: _EDIT, validateRequired: true },
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
props: { mode: _EDIT, validateRequired: true },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const input = wrapper.find(`[data-testid="input-hev-${ field }"]`).find('input');
|
||||
const newValue = 123;
|
||||
const before = updates(wrapper);
|
||||
const input = wrapper.find('[data-testid="input-hev-name"]').find('input');
|
||||
|
||||
input.setValue(newValue);
|
||||
input.trigger('blur');
|
||||
await input.setValue(123);
|
||||
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
expect(updates(wrapper)).toBeGreaterThan(before);
|
||||
});
|
||||
|
||||
it('should emit an update on size input blur', async() => {
|
||||
const wrapper = mount(HarvesterEditVolume, {
|
||||
props: { mode: _EDIT, validateRequired: true },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const input = wrapper.find('[data-testid="input-hev-size"]').find('input');
|
||||
|
||||
// setting the value already emits an update, so the blur has to add one on top of that
|
||||
await input.setValue(123);
|
||||
|
||||
const afterSetValue = updates(wrapper);
|
||||
|
||||
await input.trigger('blur');
|
||||
|
||||
expect(updates(wrapper)).toBeGreaterThan(afterSetValue);
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -52,23 +85,27 @@ describe('component: HarvesterEditVolume', () => {
|
||||
'bus'
|
||||
])('should emit an update on %p selection change', async(field) => {
|
||||
const wrapper = mount(HarvesterEditVolume, {
|
||||
propsData: { mode: _EDIT, validateRequired: true },
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
props: { mode: _EDIT, validateRequired: true },
|
||||
global: {
|
||||
mocks: {
|
||||
$store: {
|
||||
getters: {
|
||||
'harvester-common/getFeatureEnabled': () => true,
|
||||
'harvester/all': jest.fn(),
|
||||
'i18n/t': jest.fn(),
|
||||
'i18n/exists': jest.fn(),
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
const before = updates(wrapper);
|
||||
const select = wrapper.find(`[data-testid="input-hev-${ field }"]`);
|
||||
|
||||
select.find('button').trigger('click');
|
||||
await wrapper.trigger('keydown.down');
|
||||
await wrapper.trigger('keydown.enter');
|
||||
|
||||
expect(wrapper.emitted('update')).toHaveLength(1);
|
||||
expect(updates(wrapper)).toBeGreaterThan(before);
|
||||
});
|
||||
});
|
||||
|
||||
+9
-1
@@ -2,8 +2,10 @@
|
||||
import { LabeledInput } from '@components/Form/LabeledInput';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
import InputOrDisplay from '@shell/components/InputOrDisplay';
|
||||
import LabelValue from '@shell/components/LabelValue';
|
||||
import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
|
||||
import { Banner } from '@components/Banner';
|
||||
import DiskPerformanceOptions from '../DiskPerformanceOptions';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEditContainer',
|
||||
@@ -11,7 +13,7 @@ export default {
|
||||
emits: ['update'],
|
||||
|
||||
components: {
|
||||
LabeledInput, LabeledSelect, InputOrDisplay, Banner
|
||||
LabeledInput, LabeledSelect, InputOrDisplay, LabelValue, Banner, DiskPerformanceOptions
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -153,5 +155,11 @@ export default {
|
||||
class="mb-20"
|
||||
:label="value.volumeBackups.error.message"
|
||||
/>
|
||||
|
||||
<DiskPerformanceOptions
|
||||
:value="value"
|
||||
:mode="mode"
|
||||
@update="update"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
+16
-1
@@ -14,6 +14,7 @@ import { VOLUME_MODE } from '@pkg/harvester/config/types';
|
||||
import { HCI } from '../../../../types';
|
||||
import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
|
||||
import { GIBIBYTE } from '../../../../utils/unit';
|
||||
import DiskPerformanceOptions from '../DiskPerformanceOptions';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEditExisting',
|
||||
@@ -21,7 +22,7 @@ export default {
|
||||
emits: ['update'],
|
||||
|
||||
components: {
|
||||
UnitInput, LabeledInput, LabeledSelect, InputOrDisplay, LabelValue, Banner, Checkbox
|
||||
UnitInput, LabeledInput, LabeledSelect, InputOrDisplay, LabelValue, Banner, Checkbox, DiskPerformanceOptions
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -172,6 +173,14 @@ export default {
|
||||
this.value.storageClassName = pvcResource.spec.storageClassName;
|
||||
this.value.volumeMode = pvcResource.spec.volumeMode;
|
||||
this.value.shareable = false;
|
||||
|
||||
// Adopt the volume's default high-performance profile (if any) as a starting point.
|
||||
const ann = pvcResource.metadata?.annotations || {};
|
||||
|
||||
this.value.cache = ann[HCI_ANNOTATIONS.DISK_CACHE_MODE] || '';
|
||||
this.value.io = ann[HCI_ANNOTATIONS.DISK_IO_MODE] || '';
|
||||
this.value.dedicatedIOThread = ann[HCI_ANNOTATIONS.DISK_DEDICATED_IOTHREAD] === 'true';
|
||||
|
||||
this.update();
|
||||
},
|
||||
|
||||
@@ -379,5 +388,11 @@ export default {
|
||||
class="mb-20"
|
||||
:label="value.volumeBackups.error.message"
|
||||
/>
|
||||
|
||||
<DiskPerformanceOptions
|
||||
:value="value"
|
||||
:mode="mode"
|
||||
@update="update"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -15,6 +15,7 @@ import LabelValue from '@shell/components/LabelValue';
|
||||
import { ucFirst } from '@shell/utils/string';
|
||||
import { GIBIBYTE } from '../../../../utils/unit';
|
||||
import { EMPTY_IMAGE } from '../../../../utils/vm';
|
||||
import DiskPerformanceOptions from '../DiskPerformanceOptions';
|
||||
|
||||
export default {
|
||||
name: 'HarvesterEditVMImage',
|
||||
@@ -22,7 +23,7 @@ export default {
|
||||
emits: ['update'],
|
||||
|
||||
components: {
|
||||
UnitInput, LabeledInput, LabeledSelect, InputOrDisplay, LabelValue, Banner
|
||||
UnitInput, LabeledInput, LabeledSelect, InputOrDisplay, LabelValue, Banner, DiskPerformanceOptions
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -482,5 +483,11 @@ export default {
|
||||
color="error"
|
||||
:label="t('harvester.virtualMachine.volume.vmImageVolumeTip', {diskSize: diskSize, imageVirtualSize: imageVirtualSize})"
|
||||
/>
|
||||
|
||||
<DiskPerformanceOptions
|
||||
:value="value"
|
||||
:mode="mode"
|
||||
@update="update"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -9,6 +9,7 @@ import { formatSi, parseSi } from '@shell/utils/units';
|
||||
import { VOLUME_TYPE, InterfaceOption } from '../../../../config/harvester-map';
|
||||
import { _VIEW } from '@shell/config/query-params';
|
||||
import LabelValue from '@shell/components/LabelValue';
|
||||
import DiskPerformanceOptions from '../DiskPerformanceOptions';
|
||||
import { ucFirst } from '@shell/utils/string';
|
||||
import { LVM_DRIVER } from '../../../../models/harvester/storage.k8s.io.storageclass';
|
||||
import { DATA_ENGINE_V2 } from '../../../../models/harvester/persistentvolumeclaim';
|
||||
@@ -24,7 +25,7 @@ export default {
|
||||
emits: ['update'],
|
||||
|
||||
components: {
|
||||
InputOrDisplay, Loading, LabeledInput, LabeledSelect, UnitInput, LabelValue
|
||||
InputOrDisplay, Loading, LabeledInput, LabeledSelect, UnitInput, LabelValue, DiskPerformanceOptions
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -362,6 +363,11 @@ export default {
|
||||
</InputOrDisplay>
|
||||
</div>
|
||||
</div>
|
||||
<DiskPerformanceOptions
|
||||
:value="value"
|
||||
:mode="mode"
|
||||
@update="update"
|
||||
/>
|
||||
<div class="row mb-20">
|
||||
<div
|
||||
v-if="value.volumeEncryptionFeatureEnabled && isView"
|
||||
|
||||
+1
-1
@@ -333,7 +333,7 @@ $xml-height: 350px;
|
||||
min-height: $xml-height;
|
||||
font-family: monospace;
|
||||
|
||||
& .code-mirror .CodeMirror {
|
||||
& .code-mirror .cm-editor {
|
||||
min-height: $xml-height;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -742,6 +742,25 @@ export default {
|
||||
name="basics"
|
||||
:label="t('harvester.virtualMachine.detail.tabs.basics')"
|
||||
>
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="osType"
|
||||
label-key="harvester.virtualMachine.osType"
|
||||
:options="OS"
|
||||
:disabled="!isCreate"
|
||||
:tooltip="isCreate ? t('harvester.virtualMachine.osTypeTooltip') : null"
|
||||
/>
|
||||
</div>
|
||||
<div class="col span-6">
|
||||
<CpuModel
|
||||
v-model:value="cpuModel"
|
||||
:mode="mode"
|
||||
@update:value="updateCpuModel"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CpuMemory
|
||||
class="mb-20"
|
||||
:cpu="cpu"
|
||||
@@ -753,6 +772,87 @@ export default {
|
||||
@updateCpuMemory="updateCpuMemory"
|
||||
/>
|
||||
|
||||
<div class="mb-20">
|
||||
<Checkbox
|
||||
v-if="value.cpuPinningFeatureEnabled"
|
||||
v-model:value="cpuPinning"
|
||||
:disabled="!enableCpuPinningCheckbox"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.cpuPinning.tooltip"
|
||||
label-key="harvester.virtualMachine.cpuPinning.label"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="installUSBTablet"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.usbTip"
|
||||
label-key="harvester.virtualMachine.enableUsb"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="tpmEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.systemOptions.tpm"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
||||
v-model:value="tpmPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.tpmPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="efiEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.efiEnabled')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
||||
v-model:value="efiPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.efiPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="efiEnabled"
|
||||
v-model:value="secureBoot"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.systemOptions.secureBoot')"
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Banner
|
||||
v-if="showCpuPinningBanner"
|
||||
:color="mode === 'create' ? 'info' : 'warning'"
|
||||
>
|
||||
<MessageLink
|
||||
v-if="mode === 'create'"
|
||||
:to="to"
|
||||
prefix-label="harvester.virtualMachine.cpuPinning.cpuManager.prefix"
|
||||
middle-label="harvester.virtualMachine.cpuPinning.cpuManager.middle"
|
||||
suffix-label="harvester.virtualMachine.cpuPinning.cpuManager.suffix"
|
||||
/>
|
||||
<span v-if="mode==='edit'">
|
||||
{{ t('harvester.virtualMachine.cpuPinning.restartVMMessage') }}
|
||||
</span>
|
||||
</Banner>
|
||||
|
||||
<SSHKey
|
||||
v-model:value="sshKey"
|
||||
class="mb-20"
|
||||
@@ -772,6 +872,9 @@ export default {
|
||||
>
|
||||
<Volume
|
||||
v-model:value="diskRows"
|
||||
v-model:block-multi-queue="blockMultiQueue"
|
||||
v-model:io-threads-policy="ioThreadsPolicy"
|
||||
v-model:io-thread-count="ioThreadCount"
|
||||
:mode="mode"
|
||||
:custom-volume-mode="customVolumeMode"
|
||||
:namespace="value.metadata.namespace"
|
||||
@@ -788,6 +891,7 @@ export default {
|
||||
>
|
||||
<Network
|
||||
v-model:value="networkRows"
|
||||
v-model:network-boot-first="networkBootFirst"
|
||||
:mode="mode"
|
||||
:is-single="isSingle"
|
||||
/>
|
||||
@@ -965,18 +1069,6 @@ export default {
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="osType"
|
||||
label-key="harvester.virtualMachine.osType"
|
||||
:options="OS"
|
||||
:disabled="!isCreate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledSelect
|
||||
v-model:value="maintenanceStrategy"
|
||||
@@ -986,6 +1078,9 @@ export default {
|
||||
:mode="mode"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<Reserved
|
||||
:reserved-memory="reservedMemory"
|
||||
@@ -995,16 +1090,6 @@ export default {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<CpuModel
|
||||
v-model:value="cpuModel"
|
||||
:mode="mode"
|
||||
@update:value="updateCpuModel"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-20">
|
||||
<a
|
||||
v-if="showAdvanced"
|
||||
@@ -1071,7 +1156,19 @@ export default {
|
||||
@updateUserData="updateUserData"
|
||||
@updateNetworkData="updateNetworkData"
|
||||
@updateDataTemplateId="updateDataTemplateId"
|
||||
/>
|
||||
>
|
||||
<template #after-user-data>
|
||||
<Checkbox
|
||||
v-model:value="installAgent"
|
||||
class="check mb-20"
|
||||
type="checkbox"
|
||||
:disabled="isWindows"
|
||||
label-key="harvester.virtualMachine.installAgent"
|
||||
:mode="mode"
|
||||
@update:value="updateAgent"
|
||||
/>
|
||||
</template>
|
||||
</CloudConfig>
|
||||
|
||||
<WindowsSysprep
|
||||
v-if="isWindows"
|
||||
@@ -1080,95 +1177,6 @@ export default {
|
||||
:mode="mode"
|
||||
:namespace="value.metadata.namespace"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.cpuPinningFeatureEnabled"
|
||||
v-model:value="cpuPinning"
|
||||
:disabled="!enableCpuPinningCheckbox"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.cpuPinning.tooltip"
|
||||
label-key="harvester.virtualMachine.cpuPinning.label"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="installUSBTablet"
|
||||
class="check mt-20"
|
||||
type="checkbox"
|
||||
tooltip-key="harvester.virtualMachine.usbTip"
|
||||
label-key="harvester.virtualMachine.enableUsb"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="installAgent"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:disabled="isWindows"
|
||||
label-key="harvester.virtualMachine.installAgent"
|
||||
:mode="mode"
|
||||
@update:value="updateAgent"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="tpmEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
label-key="harvester.virtualMachine.advancedOptions.tpm"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.tpmPersistentStateFeatureEnabled && tpmEnabled"
|
||||
v-model:value="tpmPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.tpmPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-model:value="efiEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.efiEnabled')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="value.efiPersistentStateFeatureEnabled && efiEnabled"
|
||||
v-model:value="efiPersistentStateEnabled"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.efiPersistentState')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Checkbox
|
||||
v-if="efiEnabled"
|
||||
v-model:value="secureBoot"
|
||||
class="check"
|
||||
type="checkbox"
|
||||
:label="t('harvester.virtualMachine.advancedOptions.secureBoot')"
|
||||
:mode="mode"
|
||||
/>
|
||||
|
||||
<Banner
|
||||
v-if="showCpuPinningBanner"
|
||||
color="warning"
|
||||
>
|
||||
<MessageLink
|
||||
v-if="mode === 'create'"
|
||||
:to="to"
|
||||
prefix-label="harvester.virtualMachine.advancedOptions.cpuManager.prefix"
|
||||
middle-label="harvester.virtualMachine.advancedOptions.cpuManager.middle"
|
||||
suffix-label="harvester.virtualMachine.advancedOptions.cpuManager.suffix"
|
||||
/>
|
||||
<span v-if="mode==='edit'">
|
||||
{{ t('harvester.virtualMachine.cpuPinning.restartVMMessage') }}
|
||||
</span>
|
||||
</Banner>
|
||||
</Tab>
|
||||
</Tabbed>
|
||||
|
||||
|
||||
@@ -100,8 +100,7 @@ export default {
|
||||
},
|
||||
|
||||
vmiIp() {
|
||||
const vmiResources = this.$store.getters[`${ this.inStore }/all`](HCI.VMI);
|
||||
const resource = vmiResources.find((VMI) => VMI.id === this.value) || null;
|
||||
const resource = this.$store.getters[`${ this.inStore }/byId`](HCI.VMI, this.value);
|
||||
const networksName = this.row.networksName || [];
|
||||
const vmiNetworks = resource?.spec?.networks || [];
|
||||
|
||||
|
||||
@@ -20,7 +20,9 @@ export default {
|
||||
|
||||
computed: {
|
||||
vmiResource() {
|
||||
return this.$store.getters['harvester/byId'](HCI.VMI, this.vmResource?.id) || null;
|
||||
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||
|
||||
return this.$store.getters[`${ inStore }/byId`](HCI.VMI, this.vmResource?.id) || null;
|
||||
},
|
||||
migrationState() {
|
||||
return this.vmiResource?.migrationState?.status || '';
|
||||
|
||||
@@ -6,6 +6,9 @@ import harvesterCommonStore from './store/harvester-common';
|
||||
import harvesterStore from './store/harvester-store';
|
||||
import customValidators from './validators';
|
||||
import { PRODUCT_NAME } from './config/harvester';
|
||||
import {
|
||||
hostResolvesL10nGlobals, resolveL10nGlobals, standaloneProductName, PRODUCT_NAME_GLOBAL
|
||||
} from './utils/l10n-globals';
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import './styles/vue-flow.scss';
|
||||
|
||||
@@ -17,6 +20,15 @@ export default function (plugin: IPlugin) {
|
||||
// Auto-import model, detail, edit from the folders
|
||||
importTypes(plugin);
|
||||
|
||||
if (isSingleVirtualCluster) {
|
||||
// Standalone: the server-flavor setting picks the product name, see config/harvester-cluster
|
||||
plugin.register('l10n-global', PRODUCT_NAME_GLOBAL, standaloneProductName);
|
||||
} else if (!hostResolvesL10nGlobals(plugin.environment?.version)) {
|
||||
// Hosts older than Rancher 2.16 would show `[[Harvester]]` literally, so resolve the tokens here.
|
||||
// Mutating the module in place also updates the copy that importTypes registered.
|
||||
resolveL10nGlobals(require('./l10n/en-us.yaml'));
|
||||
}
|
||||
|
||||
// Provide plugin metadata from package.json
|
||||
plugin.metadata = require('./package.json');
|
||||
|
||||
|
||||
+178
-59
@@ -25,8 +25,8 @@ generic:
|
||||
|
||||
unsupported:
|
||||
serverVersion: 'Current version: <code>{serverVersion}</code>'
|
||||
description: Harvester ui only supports Harvester cluster version greater or equal to 1.3.0.
|
||||
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 <a target="_blank" href="https://docs.harvesterhci.io/" rel="noopener noreferrer nofollow">Harvester Docs</a>
|
||||
description: '[[Harvester]] ui only supports [[Harvester]] cluster version greater or equal to 1.3.0.'
|
||||
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 <a target="_blank" href="https://docs.harvesterhci.io/" rel="noopener noreferrer nofollow">[[Harvester]] Docs</a>
|
||||
|
||||
nav:
|
||||
group:
|
||||
@@ -84,11 +84,13 @@ dialog:
|
||||
|
||||
harvester:
|
||||
branding:
|
||||
primeLabel: '{vendor}'
|
||||
primeEmptyLabel: ''
|
||||
logos:
|
||||
tip: 'Upload a logo to replace the Harvester logo in the top-level navigation header. Image height should be 21 pixels with a max width of 200 pixels. Max file size is 20KB. Accepted formats: JPEG, PNG, SVG.'
|
||||
tip: 'Upload a logo to replace the [[Harvester]] logo in the top-level navigation header. Image height should be 21 pixels with a max width of 200 pixels. Max file size is 20KB. Accepted formats: JPEG, PNG, SVG.'
|
||||
favicon:
|
||||
tip: 'Upload an icon to replace the Harvester favicon in the browser tab. Max file size is 20KB'
|
||||
productLabel: 'Harvester'
|
||||
tip: 'Upload an icon to replace the [[Harvester]] favicon in the browser tab. Max file size is 20KB'
|
||||
productLabel: '[[Harvester]]'
|
||||
modal:
|
||||
backup:
|
||||
success: 'Backup { backUpName } has been initiated.'
|
||||
@@ -180,7 +182,7 @@ harvester:
|
||||
delete: Delete
|
||||
bundle:
|
||||
title: Generate a Support Bundle
|
||||
titleDescription: Collect system-related logs in Harvester to assist with troubleshooting and support.
|
||||
titleDescription: Collect system-related logs in [[Harvester]] to assist with troubleshooting and support.
|
||||
tip: Each field below specifies an aspect of the support bundle. For detailed explanations, please refer to the <a href="{doc}" target="_blank">documentation</a>.
|
||||
url: Issue URL
|
||||
description: Description
|
||||
@@ -284,6 +286,7 @@ harvester:
|
||||
createTemplate: Generate Template
|
||||
enableMaintenance: Enable Maintenance Mode
|
||||
disableMaintenance: Disable Maintenance Mode
|
||||
clearMaintenance: Clear Maintenance Mode Error
|
||||
enableCPUManager: Enable CPU Manager
|
||||
disableCPUManager: Disable CPU Manager
|
||||
cordon: Cordon
|
||||
@@ -333,7 +336,7 @@ harvester:
|
||||
attachedVM: Attached Virtual Machine
|
||||
cpuManager: CPU<br>Manager
|
||||
diskState: Disk
|
||||
routeConnectivityTooltip: Connectivity between the VM network and the management network, which the Harvester nodes are connected to.
|
||||
routeConnectivityTooltip: Connectivity between the VM network and the management network, which the [[Harvester]] nodes are connected to.
|
||||
fingerprint: Fingerprint
|
||||
value: Value
|
||||
actions: Actions
|
||||
@@ -498,7 +501,7 @@ harvester:
|
||||
aclEmptyError: The fields in subnet access control list rule can not be empty.
|
||||
dashboard:
|
||||
label: Dashboard
|
||||
header: "Harvester Cluster: {cluster}"
|
||||
header: "[[Harvester]] Cluster: {cluster}"
|
||||
hardwareResourceGauge:
|
||||
cpu: CPU
|
||||
memory: Memory
|
||||
@@ -684,6 +687,7 @@ harvester:
|
||||
virtualMachine:
|
||||
label: Virtual Machines
|
||||
osType: OS Type
|
||||
osTypeTooltip: Selecting an image with an OS label on the Volumes tab may change the OS Type selection.
|
||||
cpuModel:
|
||||
label: CPU Model
|
||||
fetchError: 'Failed to load CPU model configuration: {error}'
|
||||
@@ -755,6 +759,10 @@ harvester:
|
||||
tooltip: Enable CPU Pinning brings better performance and reduce latency for the virtual machine
|
||||
restartVMMessage: Changing the CPU Pinning setting requires a virtual machine reboot for the change to take effect
|
||||
migrationMessage: This virtual machine can only be migrated to a target node that has CPU Manager enabled, as CPU Pinning is configured.
|
||||
cpuManager:
|
||||
prefix: You must enable CPU Manager for at least one node in
|
||||
middle: 'host page'
|
||||
suffix: to enable CPU Pinning for VM
|
||||
restartNow: |-
|
||||
{restart, select,
|
||||
true {Restart}
|
||||
@@ -764,13 +772,9 @@ harvester:
|
||||
genericLoginError: Authentication failed. Please re-log in and try again.
|
||||
installAgent: Install guest agent
|
||||
enableUsb: Enable USB Tablet
|
||||
advancedOptions:
|
||||
systemOptions:
|
||||
tpm: Enable TPM
|
||||
tpmPersistentState: TPM Persistent State
|
||||
cpuManager:
|
||||
prefix: You must enable CPU Manager for at least one node in
|
||||
middle: 'host page'
|
||||
suffix: to enable CPU Pinning for VM
|
||||
efiEnabled: Booting in EFI mode
|
||||
efiPersistentState: EFI Persistent State
|
||||
secureBoot: Secure Boot
|
||||
@@ -798,6 +802,56 @@ harvester:
|
||||
setFirst: Set as root volume
|
||||
saveVolume: Update Volume
|
||||
encryption: Encryption
|
||||
performance:
|
||||
title: Storage Performance Options
|
||||
expand: Show high-performance options
|
||||
collapse: Hide high-performance options
|
||||
profile:
|
||||
label: Performance Profile
|
||||
tip: "\"High Performance\" applies a tuned preset (no host cache, native AIO, a dedicated I/O thread on the virtio bus). Choose \"Custom\" to set each option yourself."
|
||||
default: Default (Balanced)
|
||||
highPerformance: High Performance
|
||||
custom: Custom
|
||||
highProfileTip: This disk will use the virtio bus with host cache disabled, native AIO and a dedicated I/O thread.
|
||||
cacheMode:
|
||||
label: Cache Mode
|
||||
tip: "How the host caches disk I/O. \"None\" (host cache disabled) is best for high-throughput guests on block storage; \"WriteBack\" favours performance; \"WriteThrough\" favours durability."
|
||||
default: Default (hypervisor)
|
||||
none: None (no host cache)
|
||||
writeback: WriteBack
|
||||
writethrough: WriteThrough
|
||||
filesystemWarning: "\"None\" (O_DIRECT) requires storage that supports direct I/O. It is recommended only for Block volume mode; on Filesystem volumes the VM may fail to start."
|
||||
ioMode:
|
||||
label: I/O Mode
|
||||
tip: "How QEMU submits I/O. \"Native\" (Linux AIO) offers the lowest overhead but requires host cache set to \"None\"; \"Threads\" uses a host thread pool."
|
||||
default: Default (hypervisor)
|
||||
native: Native (AIO)
|
||||
threads: Threads
|
||||
nativeRequiresNoCacheTip: Native I/O mode requires cache mode "None"; it has been set for you.
|
||||
dedicatedIOThread:
|
||||
label: Dedicated I/O Thread
|
||||
tip: Allocate an exclusive libvirt I/O thread to this disk instead of sharing one. Useful for disks with heavy I/O. Enabling this on any disk turns on the VM's I/O threads policy.
|
||||
busTip: High-performance features work best on the virtio bus.
|
||||
diskPerformance:
|
||||
title: High Performance (I/O Threads and Multi-Queue)
|
||||
description: These settings apply to all volumes in the Virtual Machine and complement the per-volume options above.
|
||||
expand: Show VM-wide high-performance options
|
||||
collapse: Hide VM-wide high-performance options
|
||||
blockMultiQueue:
|
||||
label: Virtio Block Multi-Queue
|
||||
tip: Map disk I/O to multiple queues so it is processed across multiple CPUs. Applies to virtio disks and requires a fixed CPU allocation ([[Harvester]] always sets one).
|
||||
noVirtioTip: Add at least one disk on the virtio bus to enable Block Multi-Queue.
|
||||
ioThreadsPolicy:
|
||||
label: I/O Threads Policy
|
||||
tip: "How libvirt allocates I/O threads. \"Shared\" uses one thread for all disks; \"Auto\" pools threads round-robin (up to ~2x vCPUs); \"Supplemental Pool\" lets you pick a fixed thread count and adds matching CPUs to the pod."
|
||||
default: "Disabled (default)"
|
||||
shared: Shared
|
||||
auto: Auto
|
||||
supplementalPool: Supplemental Pool
|
||||
autoEnabledTip: A disk requests a dedicated I/O thread, so the policy is enabled (defaults to "Shared").
|
||||
ioThreadCount:
|
||||
label: I/O Thread Count
|
||||
tip: Number of I/O threads for the supplemental pool. 4-8 is a common range depending on workload.
|
||||
shareable:
|
||||
label: Shareable
|
||||
tip: Allow multiple virtual machines to attach and write to this volume simultaneously.
|
||||
@@ -819,6 +873,12 @@ harvester:
|
||||
title: Network
|
||||
addNetwork: Add Network
|
||||
addPort: Add Port
|
||||
networkBoot:
|
||||
label: Enable network boot (PXE)
|
||||
tip: Adds this interface to the VM boot order so the guest firmware can boot from the network. Requires a DHCP/TFTP (PXE) server reachable on the selected network; the management network does not provide one.
|
||||
order: Network boot order
|
||||
first: Before volumes
|
||||
last: After volumes
|
||||
cloudConfig:
|
||||
title: Cloud Configuration
|
||||
createTemplateTitle: 'Create {name}'
|
||||
@@ -879,7 +939,7 @@ harvester:
|
||||
displayNamePlaceholder: Virtual machine alias name
|
||||
displayName: Display Name
|
||||
filesystem:
|
||||
description: Harvester supports filesystem volumes for VM via virtiofs.
|
||||
description: '[[Harvester]] supports filesystem volumes for VM via virtiofs.'
|
||||
type: Filesystem Type
|
||||
volume: Volume
|
||||
resource: Resource
|
||||
@@ -962,6 +1022,51 @@ harvester:
|
||||
tips: Press the record button to capture your keyboard inputs.
|
||||
send: Send
|
||||
preferredKeys: Preferred Custom Shortcut Keys
|
||||
settings:
|
||||
label: Settings
|
||||
viewMode:
|
||||
label: Display
|
||||
scale: Scale the display to fit the window
|
||||
none: Manual zoom
|
||||
zoom: Zoom
|
||||
viewOnly: View only
|
||||
quality: JPEG quality
|
||||
compression: Compression level
|
||||
fullscreen:
|
||||
enter: Full Screen
|
||||
exit: Exit Full Screen
|
||||
ctrlAltDel: Ctrl+Alt+Del
|
||||
confirm:
|
||||
ctrlAltDel:
|
||||
title: Send Ctrl+Alt+Del?
|
||||
message: Windows opens its sign-in or security screen. Most Linux systems restart the virtual machine.
|
||||
button: Send
|
||||
softReboot:
|
||||
title: Soft reboot this virtual machine?
|
||||
message: The guest operating system is asked to restart. Unsaved work inside the virtual machine is lost.
|
||||
button: Soft Reboot
|
||||
takeOver:
|
||||
label: Take Over
|
||||
title: Take over this console?
|
||||
confirm: The other VNC session connected to this virtual machine will be disconnected.
|
||||
failure:
|
||||
inUse: This console is in use
|
||||
unavailable: Unable to connect
|
||||
dropped: Disconnected
|
||||
error: Connection failed
|
||||
failureDetail:
|
||||
inUse: Another VNC session is connected to this virtual machine. Retry once it is released, or take over the console to disconnect the other session.
|
||||
unavailable: The console is not available. Check that the virtual machine is running, then retry.
|
||||
dropped: The console connection was closed. Another VNC session may have opened this console.
|
||||
status:
|
||||
connecting: Connecting
|
||||
connected: Connected
|
||||
connectedViewOnly: Connected (view only)
|
||||
disconnected: Disconnected
|
||||
failed: Connection failed
|
||||
reconnecting: 'Reconnecting {retryTimes} of {maximumRetryTimes}'
|
||||
credentialsRequired: This console requires credentials that the dashboard cannot provide.
|
||||
inUse: Another VNC session may be using this console. Retrying until it is released.
|
||||
terminationGracePeriodSeconds:
|
||||
label: Termination Grace Period
|
||||
affinity:
|
||||
@@ -995,6 +1100,8 @@ harvester:
|
||||
createWithDataVolumeTooltip: Create Volume with Kubevirt/Containerized Data Importer way. It can fill accessMode/volumeMode automatically.
|
||||
showAdvanced: Show Advanced Options
|
||||
hideAdvanced: Hide Advanced Options
|
||||
performance:
|
||||
pvcTip: These high-performance options are saved as defaults on the volume and applied when it is attached to a virtual machine as a disk.
|
||||
source: Source
|
||||
kind: Kind
|
||||
sourceOptions:
|
||||
@@ -1086,8 +1193,8 @@ harvester:
|
||||
selectExisting: Select Existing Image
|
||||
createRepository: Creating Upgrade Repository
|
||||
succeeded: Succeeded
|
||||
releaseTip: Please read the upgrade documentation carefully. You can view details on the <a href="{url}" target="_blank">Harvester Release Notes</a>.
|
||||
checkReady: I have read and understood the upgrade instructions related to this Harvester version.
|
||||
releaseTip: Please read the upgrade documentation carefully. You can view details on the <a href="{url}" target="_blank">[[Harvester]] Release Notes</a>.
|
||||
checkReady: I have read and understood the upgrade instructions related to this [[Harvester]] version.
|
||||
pending: Pending
|
||||
upload:
|
||||
duplicatedFile: The file you are trying to upload already exists.
|
||||
@@ -1096,7 +1203,7 @@ harvester:
|
||||
os: OS
|
||||
kubernetes: Kubernetes
|
||||
monitoringChart: Monitoring Chart
|
||||
harvesterChart: Harvester Chart
|
||||
harvesterChart: '[[Harvester]] Chart'
|
||||
success: Success
|
||||
fail: Fail
|
||||
ongoing: On-going
|
||||
@@ -1136,7 +1243,7 @@ harvester:
|
||||
maxFailure:
|
||||
label: Max Failure
|
||||
count: Count
|
||||
tooltip: Max number of consecutive failed backups that could be tolerated. If reach this threshold, Harvester controller will suspend the schedule job. This value should less than retain count
|
||||
tooltip: Max number of consecutive failed backups that could be tolerated. If reach this threshold, [[Harvester]] controller will suspend the schedule job. This value should less than retain count
|
||||
virtualMachine:
|
||||
title: Virtual Machine Name
|
||||
placeholder: Select a virtual machine
|
||||
@@ -1150,7 +1257,7 @@ harvester:
|
||||
title: Restore Virtual Machine
|
||||
refreshInterval:
|
||||
label: Refresh Interval
|
||||
tip: The interval for the backup target to sync data to harvester cluster. Set to 0 to disable refresh mechanism.
|
||||
tip: The interval for the backup target to sync data to [[Harvester]] cluster. Set to 0 to disable refresh mechanism.
|
||||
backupTargetTip: The endpoint used to access the backupstore. NFS and S3 are supported.
|
||||
message:
|
||||
noSetting:
|
||||
@@ -1169,7 +1276,7 @@ harvester:
|
||||
actionLabel: Test connection
|
||||
waitingLabel: Testing connection...
|
||||
successLabel: Connection tested
|
||||
successMessage: 'Harvester can successfully connect to the endpoint {endpoint}'
|
||||
successMessage: '[[Harvester]] can successfully connect to the endpoint {endpoint}'
|
||||
restore:
|
||||
backup: Backup
|
||||
deletePreviousVolumes: Delete Previous Volumes
|
||||
@@ -1380,7 +1487,7 @@ harvester:
|
||||
placeholder: Select a provider network
|
||||
networkPolicy:
|
||||
label: Policies
|
||||
banner: The network policies must be used for VMs attached to overlay networks. Please read the <a href="{url}" target="_blank">harvester document</a> how the network policy works.
|
||||
banner: The network policies must be used for VMs attached to overlay networks. Please read the <a href="{url}" target="_blank">[[Harvester]] documentation</a> on how network policies work.
|
||||
network:
|
||||
label: Virtual Machine Networks
|
||||
tabs:
|
||||
@@ -1489,7 +1596,7 @@ harvester:
|
||||
autoRotateRKE2Certs:
|
||||
expiringInHours: Expiring in
|
||||
httpProxy:
|
||||
warning: 'WARNING: <br/> If you configure "http-proxy" and "https-proxy", you must also put Harvester node's CIDR into "no-proxy", otherwise the Harvester cluster will be broken.'
|
||||
warning: 'WARNING: <br/> If you configure "http-proxy" and "https-proxy", you must also put [[Harvester]] node's CIDR into "no-proxy", otherwise the [[Harvester]] cluster will be broken.'
|
||||
supportBundleImage:
|
||||
imagePullPolicy: Pull Policy
|
||||
repo: Repository
|
||||
@@ -1541,7 +1648,7 @@ harvester:
|
||||
strategyType: Strategy Type
|
||||
concurrency: Concurrency
|
||||
harvesterMonitoring:
|
||||
label: Harvester Monitoring
|
||||
label: '[[Harvester]] Monitoring'
|
||||
section:
|
||||
prometheus: Prometheus
|
||||
prometheusNodeExporter: Prometheus Node Exporter
|
||||
@@ -1556,10 +1663,10 @@ harvester:
|
||||
url: URL
|
||||
insecureSkipTLSVerify: Insecure Skip TLS Verify
|
||||
tip:
|
||||
prefix: Harvester secures cluster registration via TLS by default. If opt out "Insecure Skip TLS Verify", you must provide custom CA certificates using the
|
||||
prefix: '[[Harvester]] secures cluster registration via TLS by default. If opt out "Insecure Skip TLS Verify", you must provide custom CA certificates using the'
|
||||
middle: 'additional-ca'
|
||||
suffix: setting.
|
||||
message: To completely unset the imported Harvester cluster, please also remove it on the Rancher Dashboard UI via the <code> Virtualization Management </code> page.
|
||||
message: To completely unset the imported [[Harvester]] cluster, please also remove it on the Rancher Dashboard UI via the <code> Virtualization Management </code> page.
|
||||
ntpServers:
|
||||
isNotIPV4: The address you entered is not IPv4 or host. Please enter a valid IPv4 address or a host address.
|
||||
isDuplicate: There are duplicate NTP server configurations.
|
||||
@@ -1589,19 +1696,19 @@ harvester:
|
||||
networkData: Network Data
|
||||
|
||||
support:
|
||||
title: Harvester Support
|
||||
title: '[[Harvester]] Support'
|
||||
kubeconfig:
|
||||
title: Download KubeConfig
|
||||
titleDescription: Download kubeconfig for debugging.
|
||||
internal:
|
||||
rancher:
|
||||
title: Access Embedded Rancher UI
|
||||
titleDescription: You can only use the embedded Rancher UI for debugging and validation purposes. For more information about how Harvester integrates with Rancher, see the <a target="_blank" href="{url}" rel="noopener noreferrer nofollow">documentation</a>.
|
||||
titleDescription: You can only use the embedded Rancher UI for debugging and validation purposes. For more information about how [[Harvester]] integrates with Rancher, see the <a target="_blank" href="{url}" rel="noopener noreferrer nofollow">documentation</a>.
|
||||
longhorn:
|
||||
title: Access Embedded Longhorn UI
|
||||
titleDescription: We only support to use the embedded Longhorn UI for debugging and validation purpose.
|
||||
community:
|
||||
learnMore: Find out more about SUSE Harvester support
|
||||
learnMore: Find out more about [[Harvester]] support
|
||||
pricing: Contact us for pricing
|
||||
|
||||
namespace:
|
||||
@@ -1821,17 +1928,19 @@ harvester:
|
||||
|
||||
addons:
|
||||
descriptions:
|
||||
'harvester-system/vm-import-controller': vm-import-controller is an add-on to help migrate virtual machine workloads from other source clusters to an existing Harvester cluster.
|
||||
'harvester-system/pcidevices-controller': pcidevices-controller is an add-on to help discover PCI devices for nodes in your cluster and allow users to prepare devices for PCI Passthrough, for use with Harvester virtual machine and guest clusters.
|
||||
'cattle-logging-system/rancher-logging': rancher-logging is an add-on to collect versatile logs, events, and audits from the Harvester cluster and route them to many kinds of servers based on flows.
|
||||
'harvester-system/vm-import-controller': vm-import-controller is an add-on to help migrate virtual machine workloads from other source clusters to an existing [[Harvester]] cluster.
|
||||
'harvester-system/pcidevices-controller': pcidevices-controller is an add-on to help discover PCI devices for nodes in your cluster and allow users to prepare devices for PCI Passthrough, for use with [[Harvester]] virtual machine and guest clusters.
|
||||
'cattle-logging-system/rancher-logging': rancher-logging is an add-on to collect versatile logs, events, and audits from the [[Harvester]] cluster and route them to many kinds of servers based on flows.
|
||||
'harvester-system/rancher-vcluster': rancher-vcluster deploys a virtual cluster (vcluster) with Rancher installed.
|
||||
'cattle-monitoring-system/rancher-monitoring': rancher-monitoring is an add-on that collects Harvester cluster and virtual machine metrics and allows you to view the metrics on an embedded dashboard and send alert(s) to remote servers.
|
||||
'vm-import-controller': vm-import-controller is an add-on to help migrate virtual machine workloads from other source clusters to an existing Harvester cluster.
|
||||
'pcidevices-controller': pcidevices-controller is an add-on to help discover PCI devices for nodes in your cluster and allow users to prepare devices for PCI Passthrough, for use with Harvester virtual machines and guest clusters.
|
||||
'nvidia-driver-toolkit': 'nvidia-driver-toolkit is an add-on to enable vGPU devices and assign them to Harvester virtual machines.'
|
||||
'rancher-logging': rancher-logging is an add-on to collect versatile logs, events, and audits from the Harvester cluster and route them to many kinds of servers based on flows.
|
||||
'rancher-monitoring': rancher-monitoring is an add-on to collect Harvester cluster and virtual machine metrics, view them on the embedded dashboard, and send alert(s) to remote servers.
|
||||
'cattle-monitoring-system/rancher-monitoring': rancher-monitoring is an add-on that collects [[Harvester]] cluster and virtual machine metrics and allows you to view the metrics on an embedded dashboard and send alert(s) to remote servers.
|
||||
'vm-import-controller': vm-import-controller is an add-on to help migrate virtual machine workloads from other source clusters to an existing [[Harvester]] cluster.
|
||||
'pcidevices-controller': pcidevices-controller is an add-on to help discover PCI devices for nodes in your cluster and allow users to prepare devices for PCI Passthrough, for use with [[Harvester]] virtual machines and guest clusters.
|
||||
'nvidia-driver-toolkit': 'nvidia-driver-toolkit is an add-on to enable vGPU devices and assign them to [[Harvester]] virtual machines.'
|
||||
'rancher-logging': rancher-logging is an add-on to collect versatile logs, events, and audits from the [[Harvester]] cluster and route them to many kinds of servers based on flows.
|
||||
'rancher-monitoring': rancher-monitoring is an add-on to collect [[Harvester]] cluster and virtual machine metrics, view them on the embedded dashboard, and send alert(s) to remote servers.
|
||||
'rancher-vcluster': rancher-vcluster deploys a virtual cluster (vcluster) with Rancher installed.
|
||||
'k3k': k3k is an add-on to deploy the k3k controller.
|
||||
'rancher-k3k': rancher-k3k deploys a k3k virtual cluster with Rancher installed.
|
||||
'harvester-seeder': harvester-seeder is an add-on that uses IPMI and Redfish to discover hardware information and perform out-of-band operations.
|
||||
'harvester-system/harvester-seeder': harvester-seeder is an add-on that uses IPMI and Redfish to discover hardware information and perform out-of-band operations.
|
||||
'harvester-csi-driver-lvm': harvester-csi-driver-lvm is an add-on allowing users to create PVC through the LVM with local devices.
|
||||
@@ -1897,7 +2006,7 @@ harvester:
|
||||
providerSelect: Provider
|
||||
createNew: Create new provider
|
||||
requirementsTitle: Requirements
|
||||
requirementsText: "To migrate virtual machines from VMware, you will need a vCenter Server running version 6.5 or higher with a user account that has at least read permissions, and the source environment must be network-accessible from Harvester Node."
|
||||
requirementsText: "To migrate virtual machines from VMware, you will need a vCenter Server running version 6.5 or higher with a user account that has at least read permissions, and the source environment must be network-accessible from [[Harvester]] Node."
|
||||
name: Name
|
||||
urlLabel: vCenter/ESXi URL
|
||||
urlPlaceholder: "https://vcenter.example.com/sdk"
|
||||
@@ -1950,7 +2059,7 @@ harvester:
|
||||
datastore: Datastore
|
||||
dashboard:
|
||||
title: Virtual Machine Migration Overview
|
||||
description: "Migrate virtual machines from VMware vSphere to Harvester using cold migration for data consistency. Create a migration plan to select VMs, map networks and storage, and prepare a migration to Harvester."
|
||||
description: "Migrate virtual machines from VMware vSphere to [[Harvester]] using cold migration for data consistency. Create a migration plan to select VMs, map networks and storage, and prepare a migration to [[Harvester]]."
|
||||
createPlan: Create Migration
|
||||
tableTitle: Migrations
|
||||
columns:
|
||||
@@ -1970,22 +2079,22 @@ harvester:
|
||||
checkMigratedVm: Click to check migrated VM details
|
||||
configureMappings:
|
||||
title: Set Mappings
|
||||
description: Map VMware networks and datastores to Harvester and Longhorn target resources
|
||||
description: Map VMware networks and datastores to [[Harvester]] and Longhorn target resources
|
||||
save: Save Mappings and Continue
|
||||
noTemplate: Start from scratch
|
||||
removeMap: Remove mapping
|
||||
networkMapping:
|
||||
title: Network Mapping
|
||||
description: Map VMware port groups to Harvester networks
|
||||
placeholder: Choose a Harvester network
|
||||
description: Map VMware port groups to [[Harvester]] networks
|
||||
placeholder: Choose a [[Harvester]] network
|
||||
template: Use existing network mapping as template
|
||||
options:
|
||||
podNetworking: Management Network
|
||||
ignored: Ignored (No NIC will be created)
|
||||
storageMapping:
|
||||
title: Storage Mapping
|
||||
description: Map VMware datastores to Harvester storage classes
|
||||
placeholder: Choose a Harvester Storage Class
|
||||
description: Map VMware datastores to [[Harvester]] storage classes
|
||||
placeholder: Choose a [[Harvester]] Storage Class
|
||||
template: Use existing storage mapping as template
|
||||
storageDefaults:
|
||||
title: 'Storage defaults — {name}'
|
||||
@@ -2136,6 +2245,14 @@ harvester:
|
||||
hostname: Hostname
|
||||
rancherVersion: Rancher Version
|
||||
password: Bootstrap Password
|
||||
rancherK3k:
|
||||
accessRancher: Access the Rancher Dashboard
|
||||
hostname: Hostname
|
||||
version: Rancher Version
|
||||
password: Bootstrap Password
|
||||
passwordTooltip: The initial password in Rancher for the first time login.
|
||||
enable:
|
||||
title: Enable K3k
|
||||
switchFailed: "{action} {name} failed!"
|
||||
nvidiaDriverToolkit:
|
||||
titles:
|
||||
@@ -2296,7 +2413,7 @@ harvester:
|
||||
vGpuDevices: vGPU Devices
|
||||
showMore: Show More
|
||||
parentSriov: Filter By Parent SR-IOV GPU
|
||||
noPermission: Please contact your system administrator to add Harvester add-ons first.
|
||||
noPermission: Please contact your system administrator to add [[Harvester]] add-ons first.
|
||||
goSetting:
|
||||
prefix: The nvidia-driver-toolkit add-on is not enabled, click
|
||||
middle: here
|
||||
@@ -2332,7 +2449,7 @@ harvester:
|
||||
|
||||
vgpu:
|
||||
label: vGPU Devices
|
||||
noPermission: Please contact system administrator to add Harvester add-ons first.
|
||||
noPermission: Please contact system administrator to add [[Harvester]] add-ons first.
|
||||
detachWarning:
|
||||
title: Cannot Disable vGPU
|
||||
message: Please detach the device from the VM and save it first before disabling this vGPU device.
|
||||
@@ -2353,7 +2470,7 @@ harvester:
|
||||
|
||||
usb:
|
||||
label: USB Devices
|
||||
noPermission: Please contact system admin to add Harvester add-ons first
|
||||
noPermission: Please contact system admin to add [[Harvester]] add-ons first
|
||||
goSetting:
|
||||
prefix: The pcidevices-controller add-on is not enabled, click
|
||||
middle: here
|
||||
@@ -2414,7 +2531,7 @@ typeDescription:
|
||||
# Should fit on one line.
|
||||
# If you link to anything external, it MUST have
|
||||
# target="_blank" rel="noopener noreferrer nofollow"
|
||||
harvester: "Branding allows administrators to globally re-brand the UI by customizing the Harvester product name, logos and color scheme."
|
||||
harvester: "Branding allows administrators to globally re-brand the UI by customizing the [[Harvester]] product name, logos and color scheme."
|
||||
|
||||
advancedSettings:
|
||||
tags:
|
||||
@@ -2429,18 +2546,19 @@ advancedSettings:
|
||||
descriptions:
|
||||
'harv-vlan': Default Network Interface name of the VLAN network.
|
||||
'harv-backup-target': Custom backup target to store virtual machine backups.
|
||||
'branding': Branding allows administrators to globally re-brand the UI by customizing the Harvester product name, logos, and color scheme.
|
||||
'branding': Branding allows administrators to globally re-brand the UI by customizing the [[Harvester]] product name, logos, and color scheme.
|
||||
'harv-csi-driver-config': Configure additional information for CSI drivers.
|
||||
'harv-csi-online-expand-validation': Allow online volume expansion for specific CSI drivers.
|
||||
'harv-containerd-registry': Containerd Registry Configuration to connect private registries.
|
||||
'harv-log-level': Configure Harvester server log level. Defaults to Info.
|
||||
'harv-server-version': Harvester server version.
|
||||
'harv-upgrade-checker-enabled': Specifies whether to enable Harvester upgrade check or not. Default is True.
|
||||
'harv-upgrade-checker-url': Default Harvester upgrade check url. Only used when the <code>upgrade-checker-enabled</code> is equal to True.
|
||||
'harv-ui-source': Configure how to load the UI source. The `External` option is used to load the UI from a ui-index URL, while the `Bundled` option loads the UI from the local Harvester server.
|
||||
'harv-log-level': Configure [[Harvester]] server log level. Defaults to Info.
|
||||
'harv-server-version': '[[Harvester]] server version.'
|
||||
'harv-server-flavor': "Indicates the [[Harvester]] edition: Prime or Community."
|
||||
'harv-upgrade-checker-enabled': Specifies whether to enable [[Harvester]] upgrade check or not. Default is True.
|
||||
'harv-upgrade-checker-url': Default [[Harvester]] upgrade check url. Only used when the <code>upgrade-checker-enabled</code> is equal to True.
|
||||
'harv-ui-source': Configure how to load the UI source. The `External` option is used to load the UI from a ui-index URL, while the `Bundled` option loads the UI from the local [[Harvester]] server.
|
||||
'harv-ui-index': 'HTML index location for the UI.'
|
||||
'harv-cluster-registration-url': Registration URL for multi-cluster management.
|
||||
'harv-http-proxy': 'HTTP proxy for Harvester to access external services.'
|
||||
'harv-http-proxy': 'HTTP proxy for [[Harvester]] to access external services.'
|
||||
'harv-additional-ca': 'Custom CA root certificates for TLS validation.'
|
||||
'harv-overcommit-config': 'Resource overcommit configuration.'
|
||||
'harv-support-bundle-timeout': 'Support bundle timeout configuration in minutes, use 0 to disable the timeout.'
|
||||
@@ -2452,13 +2570,13 @@ advancedSettings:
|
||||
'harv-storage-network': 'Longhorn storage-network setting.'
|
||||
'harv-rwx-network': 'Configure RWX network behavior for shared or dedicated storage network usage.'
|
||||
'harv-support-bundle-namespaces': Select additional namespaces to include in the support bundle.
|
||||
'harv-auto-disk-provision-paths': Specify the disks(using glob pattern) that Harvester will automatically add as virtual machine storage.
|
||||
'harv-auto-disk-provision-paths': Specify the disks(using glob pattern) that [[Harvester]] will automatically add as virtual machine storage.
|
||||
'harv-support-bundle-image': Support bundle image configuration. Find different versions in <a href="https://hub.docker.com/r/rancher/support-bundle-kit/tags" target="_blank">rancher/support-bundle-kit</a>.
|
||||
'harv-release-download-url': This setting allows you to configure the <code>upgrade release download</code> URL address. Harvester will get the ISO URL and checksum value from the (<code>$URL</code>/<code>$VERSION</code>/version.yaml) file hosted by the configured URL.
|
||||
'harv-release-download-url': This setting allows you to configure the <code>upgrade release download</code> URL address. [[Harvester]] will get the ISO URL and checksum value from the (<code>$URL</code>/<code>$VERSION</code>/version.yaml) file hosted by the configured URL.
|
||||
'harv-default-vm-termination-grace-period-seconds': Configure the virtual machine termination grace period for virtual machine stop.
|
||||
'harv-ntp-servers': Configure NTP server. You can configure multiple IPv4 addresses or host addresses.
|
||||
'harv-auto-rotate-rke2-certs': The certificate rotation mechanism relies on Rancher. Harvester will automatically update certificates generation to trigger rotation.
|
||||
'harv-kubeconfig-default-token-ttl-minutes': 'TTL (in minutes) applied on Harvester administration kubeconfig files. Default is 0, which means to never expire.'
|
||||
'harv-auto-rotate-rke2-certs': The certificate rotation mechanism relies on Rancher. [[Harvester]] will automatically update certificates generation to trigger rotation.
|
||||
'harv-kubeconfig-default-token-ttl-minutes': 'TTL (in minutes) applied on [[Harvester]] administration kubeconfig files. Default is 0, which means to never expire.'
|
||||
'harv-longhorn-v2-data-engine-enabled': 'Enable the Longhorn V2 data engine. Default is false. <ul><li>Changing this setting will restart RKE2 on all nodes. This will not affect running VM workloads.</li><li>If you see "not enough hugepages-2Mi capacity" errors when enabling this setting, wait a minute for the error to clear. If the error remains, reboot the affected node.</li></ul>'
|
||||
'harv-longhorn-v2-data-engine-hugepage-enabled': 'Enable hugepages when using the Longhorn V2 data engine. Default is true. Disabling hugepages reduces memory pressure on low-spec nodes and increases deployment flexibility. However, performance may be lower compared to running with hugepages.'
|
||||
'harv-longhorn-v2-data-engine-memory-size': 'Configure the amount of memory allocated to the SPDK target daemon when using the Longhorn V2 data engine. Default is 2048 MiB.'
|
||||
@@ -2470,6 +2588,7 @@ advancedSettings:
|
||||
'harv-kubevirt-migration': 'Configure cluster-wide KubeVirt live migration parameters.'
|
||||
'harv-instance-manager-resources': 'Configure resource percentage reservations for Longhorn instance manager V1 and V2. Valid instance manager CPU range between 0 - 40.'
|
||||
'harv-cluster-pod-security-standard': 'Enforce Kubernetes Pod Security Standards (PSS) at the cluster level.'
|
||||
'harv-maintenance-mode-drain-timeout': 'Maintenance mode drain timeout in minutes. Use 0 to disable the timeout.'
|
||||
|
||||
typeLabel:
|
||||
kubevirt.io.virtualmachine: |-
|
||||
|
||||
@@ -72,7 +72,7 @@ export default {
|
||||
/>
|
||||
|
||||
<a
|
||||
v-if="scope.row.metadata.name === 'rancher-vcluster' && scope.row.spec.enabled"
|
||||
v-if="['rancher-vcluster', 'rancher-k3k'].includes(scope.row.metadata.name) && scope.row.spec.enabled"
|
||||
v-tooltip="t('harvester.addons.rancherVcluster.accessRancher')"
|
||||
class="ml-5"
|
||||
rel="nofollow noopener noreferrer"
|
||||
|
||||
@@ -151,7 +151,8 @@ export default {
|
||||
},
|
||||
|
||||
rows() {
|
||||
const matchVMIs = this.allVMIs.filter((VMI) => !this.allVMs.find((VM) => VM.id === VMI.id));
|
||||
const vmIds = new Set(this.allVMs.map((VM) => VM.id));
|
||||
const matchVMIs = this.allVMIs.filter((VMI) => !vmIds.has(VMI.id));
|
||||
|
||||
return [...this.allVMs, ...matchVMIs];
|
||||
},
|
||||
@@ -160,7 +161,11 @@ export default {
|
||||
* We want to show the progress bar only for Backup's restore; snapshot's restore is immediate.
|
||||
*/
|
||||
hasBackUpRestoreInProgress() {
|
||||
return !!this.rows.find((r) => r.restoreResource && !r.restoreResource.fromSnapshot && !r.restoreResource.isComplete);
|
||||
return this.rows.some((r) => {
|
||||
const restore = r.restoreResource;
|
||||
|
||||
return restore && !restore.fromSnapshot && !restore.isComplete;
|
||||
});
|
||||
},
|
||||
|
||||
vmRestartRequiredNames() {
|
||||
|
||||
@@ -160,6 +160,7 @@ export default {
|
||||
imageId: '',
|
||||
diskRows: [],
|
||||
networkRows: [],
|
||||
networkBootFirst: true,
|
||||
filesystemRows: [],
|
||||
machineType: '',
|
||||
machineTypes: [],
|
||||
@@ -195,6 +196,10 @@ export default {
|
||||
cpuPinning: false,
|
||||
cpuModel: '',
|
||||
sysprep: { secretName: '', xmlContent: '' },
|
||||
// KubeVirt high-performance VM-level features
|
||||
blockMultiQueue: false,
|
||||
ioThreadsPolicy: '',
|
||||
ioThreadCount: 2,
|
||||
};
|
||||
},
|
||||
|
||||
@@ -380,6 +385,7 @@ export default {
|
||||
const diskRows = this.getDiskRows(vm, volumeBackups);
|
||||
|
||||
const networkRows = this.getNetworkRows(vm, { fromTemplate, init });
|
||||
const networkBootFirst = this.isNetworkBootFirst(spec);
|
||||
const hasCreateVolumes = this.getHasCreatedVolumes(spec) || [];
|
||||
|
||||
let { userData = undefined, networkData = undefined } = this.getCloudInitNoCloud(spec);
|
||||
@@ -409,6 +415,10 @@ export default {
|
||||
const cpuPinning = this.isCpuPinning(spec);
|
||||
const cpuModel = spec.template.spec.domain.cpu?.model || '';
|
||||
|
||||
const blockMultiQueue = spec.template.spec.domain?.devices?.blockMultiQueue || false;
|
||||
const ioThreadsPolicy = spec.template.spec.domain?.ioThreadsPolicy || '';
|
||||
const ioThreadCount = spec.template.spec.domain?.ioThreads?.supplementalPoolThreadCount || 2;
|
||||
|
||||
const secretRef = this.getSecret(spec);
|
||||
const accessCredentials = this.getAccessCredentials(spec);
|
||||
|
||||
@@ -447,8 +457,13 @@ export default {
|
||||
this['cpuPinning'] = cpuPinning;
|
||||
this['cpuModel'] = cpuModel;
|
||||
|
||||
this['blockMultiQueue'] = blockMultiQueue;
|
||||
this['ioThreadsPolicy'] = ioThreadsPolicy;
|
||||
this['ioThreadCount'] = ioThreadCount;
|
||||
|
||||
this['hasCreateVolumes'] = hasCreateVolumes;
|
||||
this['networkRows'] = networkRows;
|
||||
this['networkBootFirst'] = networkBootFirst;
|
||||
this['imageId'] = imageId;
|
||||
|
||||
this['diskRows'] = diskRows;
|
||||
@@ -503,17 +518,20 @@ export default {
|
||||
}
|
||||
|
||||
out.push({
|
||||
id: randomStr(5),
|
||||
source: SOURCE_TYPE.IMAGE,
|
||||
name: 'disk-0',
|
||||
accessMode: READ_WRITE_MANY, // root disk only support LHv1 volume, should be RWX
|
||||
id: randomStr(5),
|
||||
source: SOURCE_TYPE.IMAGE,
|
||||
name: 'disk-0',
|
||||
accessMode: READ_WRITE_MANY, // root disk only support LHv1 volume, should be RWX
|
||||
bus,
|
||||
volumeName: '',
|
||||
volumeName: '',
|
||||
size,
|
||||
type,
|
||||
storageClassName: '',
|
||||
image: this.imageId,
|
||||
volumeMode: VOLUME_MODE.BLOCK,
|
||||
storageClassName: '',
|
||||
image: this.imageId,
|
||||
volumeMode: VOLUME_MODE.BLOCK,
|
||||
cache: '',
|
||||
io: '',
|
||||
dedicatedIOThread: false,
|
||||
isEncrypted,
|
||||
volumeBackups,
|
||||
});
|
||||
@@ -603,22 +621,25 @@ export default {
|
||||
const volumeBackups = volBackups?.find((vBackup) => vBackup.volumeName === DISK.name) || null;
|
||||
|
||||
return {
|
||||
id: randomStr(5),
|
||||
id: randomStr(5),
|
||||
bootOrder,
|
||||
source,
|
||||
name: DISK.name,
|
||||
name: DISK.name,
|
||||
realName,
|
||||
bus,
|
||||
volumeName,
|
||||
container,
|
||||
accessMode,
|
||||
size: `${ formatSize }${ GIBIBYTE }`,
|
||||
volumeMode: volumeMode || this.customVolumeMode,
|
||||
size: `${ formatSize }${ GIBIBYTE }`,
|
||||
volumeMode: volumeMode || this.customVolumeMode,
|
||||
image,
|
||||
type,
|
||||
storageClassName,
|
||||
hotpluggable,
|
||||
shareable: DISK.shareable || false,
|
||||
cache: DISK?.cache || '',
|
||||
io: DISK?.io || '',
|
||||
dedicatedIOThread: DISK?.dedicatedIOThread || false,
|
||||
shareable: DISK.shareable || false,
|
||||
volumeStatus,
|
||||
dataSource,
|
||||
namespace,
|
||||
@@ -658,12 +679,29 @@ export default {
|
||||
model: I.model,
|
||||
networkName: isPod ? MANAGEMENT_NETWORK : network?.multus?.networkName,
|
||||
staticIp: annotations[`${ staticIpPrefix }${ I.name }`] || '',
|
||||
networkBoot: !!I.bootOrder,
|
||||
};
|
||||
});
|
||||
|
||||
return out;
|
||||
},
|
||||
|
||||
/**
|
||||
* Network boot devices are placed either before or after all volumes in the boot sequence.
|
||||
* Derive which one from an existing spec, so a round trip through the form keeps it.
|
||||
*/
|
||||
isNetworkBootFirst(spec) {
|
||||
const devices = spec?.template?.spec?.domain?.devices || {};
|
||||
const nicOrders = (devices.interfaces || []).map((I) => I.bootOrder).filter(Boolean);
|
||||
const diskOrders = (devices.disks || []).map((D) => D.bootOrder).filter(Boolean);
|
||||
|
||||
if (nicOrders.length === 0 || diskOrders.length === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return Math.min(...nicOrders) < Math.min(...diskOrders);
|
||||
},
|
||||
|
||||
parseVM() {
|
||||
this.userData = this.getUserData({ osType: this.osType, installAgent: this.installAgent });
|
||||
this.parseOther();
|
||||
@@ -876,9 +914,10 @@ export default {
|
||||
const disks = [];
|
||||
const volumes = [];
|
||||
const volumeClaimTemplates = [];
|
||||
const bootOrderOffset = this.networkBootFirst ? this.networkRows.filter((R) => R.networkBoot).length : 0;
|
||||
|
||||
disk.forEach( (R, index) => {
|
||||
const _disk = this.parseDisk(R, index);
|
||||
const _disk = this.parseDisk(R, index + bootOrderOffset);
|
||||
|
||||
disks.push(_disk);
|
||||
|
||||
@@ -973,9 +1012,25 @@ export default {
|
||||
// `shareable` is an attachment-level opt-in, remove the field
|
||||
// inherited from the old spec when the disk row no longer requests it
|
||||
mergedDisks.forEach((disk) => {
|
||||
if (disk.shareable && !disks.find((D) => D.name === disk.name)?.shareable) {
|
||||
const parsed = disks.find((D) => D.name === disk.name);
|
||||
|
||||
if (disk.shareable && !parsed?.shareable) {
|
||||
delete disk.shareable;
|
||||
}
|
||||
|
||||
// High-performance fields are only serialized when requested (see
|
||||
// parseDisk). When editing, mergeDeviceList would otherwise keep the
|
||||
// previous spec's cache/io/dedicatedIOThread even after the row is
|
||||
// switched back to "Default" or the dedicated I/O thread is unchecked,
|
||||
// silently preserving stale values — strip them so the disk matches
|
||||
// what the row actually requests.
|
||||
if (parsed) {
|
||||
['cache', 'io', 'dedicatedIOThread'].forEach((field) => {
|
||||
if (!parsed[field] && field in disk) {
|
||||
delete disk[field];
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
let spec = {
|
||||
@@ -1012,6 +1067,35 @@ export default {
|
||||
delete spec.template.spec.volumes;
|
||||
}
|
||||
|
||||
// KubeVirt high-performance VM-level features (I/O threads & block multi-queue).
|
||||
const domainRef = spec.template.spec.domain;
|
||||
const hasDedicatedIOThread = mergedDisks.some((D) => D.dedicatedIOThread);
|
||||
// If any disk requests a dedicated I/O thread, KubeVirt requires a policy;
|
||||
// default it to "shared" so the dedicated thread is honored.
|
||||
let ioThreadsPolicy = this.ioThreadsPolicy;
|
||||
|
||||
if (hasDedicatedIOThread && !ioThreadsPolicy) {
|
||||
ioThreadsPolicy = 'shared';
|
||||
}
|
||||
|
||||
if (ioThreadsPolicy) {
|
||||
domainRef.ioThreadsPolicy = ioThreadsPolicy;
|
||||
} else {
|
||||
delete domainRef.ioThreadsPolicy;
|
||||
}
|
||||
|
||||
if (ioThreadsPolicy === 'supplementalPool') {
|
||||
domainRef.ioThreads = { supplementalPoolThreadCount: Number(this.ioThreadCount) || 1 };
|
||||
} else {
|
||||
delete domainRef.ioThreads;
|
||||
}
|
||||
|
||||
if (this.blockMultiQueue) {
|
||||
domainRef.devices.blockMultiQueue = true;
|
||||
} else {
|
||||
delete domainRef.devices.blockMultiQueue;
|
||||
}
|
||||
|
||||
if (this.resourceType === HCI.VM) {
|
||||
if (!this.isSingle) {
|
||||
spec = this.multiVMScheduler(spec);
|
||||
@@ -1091,9 +1175,11 @@ export default {
|
||||
const networks = [];
|
||||
const interfaces = [];
|
||||
|
||||
let bootOrder = this.networkBootFirst ? 1 : this.diskRows.length + 1;
|
||||
|
||||
networkRow.forEach( (R) => {
|
||||
const _network = this.parseNetwork(R);
|
||||
const _interface = this.parseInterface(R);
|
||||
const _interface = this.parseInterface(R, R.networkBoot ? bootOrder++ : undefined);
|
||||
|
||||
networks.push(_network);
|
||||
interfaces.push(_interface);
|
||||
@@ -1259,6 +1345,19 @@ export default {
|
||||
|
||||
if (R.type === HARD_DISK) {
|
||||
out.disk = { bus: R.bus };
|
||||
|
||||
// KubeVirt high-performance per-disk features. `cache`, `io` and
|
||||
// `dedicatedIOThread` live at the Disk level (siblings of `disk`), not
|
||||
// inside the DiskTarget. See disks_and_volumes.md#high-performance-features.
|
||||
if (R.cache) {
|
||||
out.cache = R.cache;
|
||||
}
|
||||
if (R.io) {
|
||||
out.io = R.io;
|
||||
}
|
||||
if (R.dedicatedIOThread) {
|
||||
out.dedicatedIOThread = true;
|
||||
}
|
||||
} else if (R.type === CD_ROM) {
|
||||
out.cdrom = { bus: R.bus };
|
||||
}
|
||||
@@ -1317,8 +1416,9 @@ export default {
|
||||
case SOURCE_TYPE.IMAGE: {
|
||||
const image = this.images.find( (I) => R.image === I.id);
|
||||
|
||||
out.spec.storageClassName = R.realName ? R.storageClassName : (R.storageClassName || image?.storageClassName);
|
||||
|
||||
if (image) {
|
||||
out.spec.storageClassName = image.storageClassName;
|
||||
out.metadata.annotations = { [HCI_ANNOTATIONS.IMAGE_ID]: image.id };
|
||||
} else {
|
||||
out.metadata.annotations = { [HCI_ANNOTATIONS.IMAGE_ID]: '' };
|
||||
@@ -1335,7 +1435,7 @@ export default {
|
||||
return arr.map( (id) => this.getSSHValue(id)).filter( (O) => O !== undefined);
|
||||
},
|
||||
|
||||
parseInterface(R) {
|
||||
parseInterface(R, bootOrder) {
|
||||
const _interface = {};
|
||||
const type = R.type;
|
||||
|
||||
@@ -1345,6 +1445,10 @@ export default {
|
||||
_interface.macAddress = R.macAddress;
|
||||
}
|
||||
|
||||
if (bootOrder) {
|
||||
_interface.bootOrder = bootOrder;
|
||||
}
|
||||
|
||||
_interface.model = R.model;
|
||||
_interface.name = R.name;
|
||||
|
||||
@@ -1852,6 +1956,11 @@ export default {
|
||||
delete merged['bridge'];
|
||||
}
|
||||
|
||||
// boot order is owned by the form, don't inherit a stale one from the old spec
|
||||
if (!iface.bootOrder) {
|
||||
delete merged.bootOrder;
|
||||
}
|
||||
|
||||
return merged;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,398 @@
|
||||
import { reactive } from 'vue';
|
||||
import VirtVm from '../kubevirt.io.virtualmachine';
|
||||
import { POD, PVC } from '@shell/config/types';
|
||||
import { HCI } from '../../types';
|
||||
|
||||
// The Steve base model and the shell resource class pull in most of the dashboard, none of that is needed here
|
||||
jest.mock('../harvester', () => ({ __esModule: true, default: class {} }));
|
||||
jest.mock('@shell/plugins/dashboard-store/resource-class', () => ({
|
||||
colorForState: (state) => (state === 'Running' ? 'text-success' : 'text-info'),
|
||||
stateSort: (color, display) => `${ color.replace(/^text-/, '') } ${ display }`,
|
||||
}));
|
||||
|
||||
const VM_ID = 'ns1/vm1';
|
||||
|
||||
// Creates a VM model with mocked store getters. Like the real store, `all` returns the same array that is mutated in place.
|
||||
// Reads from the global `$rootGetters` are recorded in `globalReads`.
|
||||
function createVm({
|
||||
vm = {}, vmi, pods = [], pvcs = [], restores = [], backups = [], claims = ['disk-pvc'], printableStatus
|
||||
} = {}) {
|
||||
const lists = reactive({
|
||||
[POD]: pods,
|
||||
[PVC]: pvcs,
|
||||
[HCI.RESTORE]: restores,
|
||||
[HCI.BACKUP]: backups,
|
||||
});
|
||||
const byId = { [HCI.VMI]: vmi ? [vmi] : [] };
|
||||
|
||||
const getters = {
|
||||
all: (type) => lists[type] || [],
|
||||
byId: (type, id) => (byId[type] || lists[type] || []).find((x) => x.id === id),
|
||||
schemaFor: () => undefined,
|
||||
};
|
||||
const globalReads = [];
|
||||
const rootGetters = new Proxy({ 'harvester-common/getFeatureEnabled': () => false }, {
|
||||
get(target, key) {
|
||||
globalReads.push(key);
|
||||
|
||||
return target[key];
|
||||
}
|
||||
});
|
||||
|
||||
const obj = Object.create(VirtVm.prototype);
|
||||
|
||||
Object.assign(obj, {
|
||||
id: VM_ID,
|
||||
type: HCI.VM,
|
||||
metadata: {
|
||||
name: 'vm1', namespace: 'ns1', annotations: {}
|
||||
},
|
||||
spec: {
|
||||
runStrategy: 'Always',
|
||||
template: {
|
||||
spec: {
|
||||
domain: { cpu: { cores: 1 }, resources: { limits: { memory: '1Gi' } } },
|
||||
volumes: claims.map((c) => ({ name: c, persistentVolumeClaim: { claimName: c } })),
|
||||
}
|
||||
}
|
||||
},
|
||||
status: {
|
||||
created: true, ready: true, printableStatus: printableStatus || 'Running', conditions: []
|
||||
},
|
||||
...vm,
|
||||
});
|
||||
Object.defineProperty(obj, '$rootGetters', { value: rootGetters });
|
||||
Object.defineProperty(obj, '$getters', { value: getters });
|
||||
Object.defineProperty(obj, 't', { value: (k) => k });
|
||||
|
||||
return {
|
||||
vm: obj, lists, globalReads
|
||||
};
|
||||
}
|
||||
|
||||
const readyVmi = (extra = {}) => ({
|
||||
id: VM_ID,
|
||||
metadata: { name: 'vm1', namespace: 'ns1' },
|
||||
status: {
|
||||
phase: 'Running',
|
||||
conditions: [{ type: 'Ready', status: 'True' }],
|
||||
...extra
|
||||
}
|
||||
});
|
||||
|
||||
const pvc = (name, encrypted, ns = 'ns1') => ({
|
||||
id: `${ ns }/${ name }`,
|
||||
metadata: { name, namespace: ns },
|
||||
isEncrypted: encrypted,
|
||||
});
|
||||
|
||||
describe('class VirtVm', () => {
|
||||
describe('restoreResource', () => {
|
||||
it('should distinguish snapshots from backups and follow backup updates', () => {
|
||||
const { vm, lists } = createVm({
|
||||
vm: {
|
||||
metadata: {
|
||||
namespace: 'ns1', name: 'vm1', annotations: { 'restore.harvesterhci.io/name': 'r1' }
|
||||
}
|
||||
},
|
||||
restores: [{
|
||||
id: 'ns1/r1', isComplete: false, spec: { virtualMachineBackupNamespace: 'ns1', virtualMachineBackupName: 'b1' }
|
||||
}],
|
||||
backups: [
|
||||
{ id: 'ns2/b1', spec: { type: 'snapshot' } },
|
||||
{ id: 'ns1/b1', spec: { type: 'backup' } },
|
||||
],
|
||||
});
|
||||
|
||||
expect(vm.restoreResource.fromSnapshot).toBe(false);
|
||||
expect(vm.restoreState).toBe(false);
|
||||
|
||||
lists[HCI.BACKUP][1].spec.type = 'snapshot';
|
||||
expect(vm.restoreResource.fromSnapshot).toBe(true);
|
||||
|
||||
lists[HCI.BACKUP].splice(1, 1);
|
||||
expect(vm.restoreResource.fromSnapshot).toBe(false);
|
||||
|
||||
lists[HCI.RESTORE][0].isComplete = true;
|
||||
expect(vm.restoreState).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('encryptedVolumeType', () => {
|
||||
it('should be none without volumes', () => {
|
||||
const { vm } = createVm({ claims: [] });
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('none');
|
||||
});
|
||||
|
||||
it('should be none if no PVC is encrypted', () => {
|
||||
const { vm } = createVm({ pvcs: [pvc('disk-pvc', false)] });
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('none');
|
||||
});
|
||||
|
||||
it('should be all if every PVC is encrypted', () => {
|
||||
const { vm } = createVm({
|
||||
claims: ['a', 'b'],
|
||||
pvcs: [pvc('a', true), pvc('b', true), pvc('other', false)]
|
||||
});
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('all');
|
||||
});
|
||||
|
||||
it('should be partial if some PVCs are encrypted', () => {
|
||||
const { vm } = createVm({
|
||||
claims: ['a', 'b'],
|
||||
pvcs: [pvc('a', true), pvc('b', false)]
|
||||
});
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('partial');
|
||||
});
|
||||
|
||||
it('should follow PVCs that are added to the store later', () => {
|
||||
const { vm, lists } = createVm({ claims: ['a'], pvcs: [] });
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('none');
|
||||
|
||||
lists[PVC].push(pvc('a', true));
|
||||
|
||||
expect(vm.encryptedVolumeType).toBe('all');
|
||||
});
|
||||
});
|
||||
|
||||
describe('actualState', () => {
|
||||
it('should be Off if the VM is halted', () => {
|
||||
const { vm } = createVm({
|
||||
vm: {
|
||||
spec: { runStrategy: 'Halted', template: { spec: { volumes: [], domain: {} } } },
|
||||
status: { created: false, conditions: [] }
|
||||
}
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Off');
|
||||
});
|
||||
|
||||
it('should be Running if the VMI is running and ready', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi() });
|
||||
|
||||
expect(vm.actualState).toBe('Running');
|
||||
});
|
||||
|
||||
it('should be Not Ready if the VMI is running but not ready', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi({ conditions: [{ type: 'Ready', status: 'False' }] }) });
|
||||
|
||||
expect(vm.actualState).toBe('Not Ready');
|
||||
});
|
||||
|
||||
it('should be Paused if the VMI has the Paused condition', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi({ conditions: [{ type: 'Ready', status: 'True' }, { type: 'Paused', status: 'True' }] }) });
|
||||
|
||||
expect(vm.actualState).toBe('Paused');
|
||||
});
|
||||
|
||||
it('should be Stopping if the VM is not expected to run anymore but the VMI exists', () => {
|
||||
const { vm } = createVm({
|
||||
vm: { spec: { runStrategy: 'Halted', template: { spec: { volumes: [], domain: {} } } } },
|
||||
vmi: readyVmi()
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Stopping');
|
||||
});
|
||||
|
||||
it('should be Starting while the launcher pod is not ready', () => {
|
||||
const { vm } = createVm({
|
||||
vmi: readyVmi({ phase: 'Scheduling', conditions: [] }),
|
||||
pods: [{
|
||||
metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] },
|
||||
getPodStatus: { status: 'POD_NOT_SCHEDULABLE' }
|
||||
}]
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Starting');
|
||||
});
|
||||
|
||||
it('should be Unschedulable if the VM is starting and has an unschedulable condition', () => {
|
||||
const { vm } = createVm({
|
||||
vmi: readyVmi({ phase: 'Pending', conditions: [] }),
|
||||
vm: { status: { created: true, conditions: [{ reason: 'Unschedulable', message: 'no node' }] } }
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Unschedulable');
|
||||
expect(vm.isUnschedulable.message).toBe('no node');
|
||||
});
|
||||
|
||||
it('should not be Unschedulable without an unschedulable condition', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi() });
|
||||
|
||||
expect(vm.isUnschedulable).toBeNull();
|
||||
expect(vm.actualState).toBe('Running');
|
||||
});
|
||||
|
||||
it('should not be Unschedulable if the VM is neither starting nor stopping', () => {
|
||||
const { vm } = createVm({
|
||||
vm: {
|
||||
spec: { runStrategy: 'Halted', template: { spec: { volumes: [], domain: {} } } },
|
||||
status: { created: false, conditions: [{ reason: 'Unschedulable' }] }
|
||||
}
|
||||
});
|
||||
|
||||
expect(vm.isUnschedulable).toBeNull();
|
||||
expect(vm.actualState).toBe('Off');
|
||||
});
|
||||
|
||||
it('should be Terminating if the VM is being deleted', () => {
|
||||
const { vm } = createVm({
|
||||
vmi: readyVmi(),
|
||||
vm: {
|
||||
metadata: {
|
||||
name: 'vm1', namespace: 'ns1', annotations: {}, deletionTimestamp: 'now'
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Terminating');
|
||||
});
|
||||
|
||||
it('should be VM error if the VM has a failure condition', () => {
|
||||
const { vm } = createVm({ vm: { status: { created: true, conditions: [{ type: 'Failure', message: 'boom' }] } } });
|
||||
|
||||
expect(vm.actualState).toBe('VM error');
|
||||
});
|
||||
|
||||
it('should be Restoring while a restore is in progress', () => {
|
||||
const { vm } = createVm({
|
||||
vmi: readyVmi(),
|
||||
vm: {
|
||||
metadata: {
|
||||
name: 'vm1', namespace: 'ns1', annotations: { 'restore.harvesterhci.io/name': 'r1' }
|
||||
}
|
||||
},
|
||||
restores: [{ id: 'ns1/r1', isComplete: false }]
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Restoring');
|
||||
});
|
||||
|
||||
it('should not be Restoring if the restore of the annotation does not exist', () => {
|
||||
const { vm } = createVm({
|
||||
vmi: readyVmi(),
|
||||
vm: {
|
||||
metadata: {
|
||||
name: 'vm1', namespace: 'ns1', annotations: { 'restore.harvesterhci.io/name': 'other' }
|
||||
}
|
||||
},
|
||||
restores: [{ id: 'ns1/r1', isComplete: false }]
|
||||
});
|
||||
|
||||
expect(vm.actualState).toBe('Running');
|
||||
});
|
||||
});
|
||||
|
||||
describe('stateSort', () => {
|
||||
it('should be built from the same state as stateDisplay and stateColor', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi() });
|
||||
|
||||
expect(vm.stateSort).toBe(`${ vm.stateColor.replace(/^text-/, '') } ${ vm.stateDisplay }`);
|
||||
});
|
||||
|
||||
it('should evaluate the state only once', () => {
|
||||
const { vm } = createVm({ vmi: readyVmi() });
|
||||
const spy = jest.spyOn(vm, 'actualState', 'get');
|
||||
|
||||
expect(vm.stateSort).toBe('success Running');
|
||||
expect(spy).toHaveBeenCalledTimes(1);
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('podResource', () => {
|
||||
it('should find the launcher pod by owner name', () => {
|
||||
const pod = { metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] } };
|
||||
const { vm } = createVm({ vmi: readyVmi(), pods: [pod] });
|
||||
|
||||
expect(vm.podResource).toStrictEqual(pod);
|
||||
});
|
||||
|
||||
it('should return the last pod if several pods have the same owner', () => {
|
||||
// e.g. the source and the target pod while the VM migrates
|
||||
const source = {
|
||||
metadata: {
|
||||
name: 'launcher-source', namespace: 'ns1', ownerReferences: [{ name: 'vm1' }]
|
||||
}
|
||||
};
|
||||
const target = {
|
||||
metadata: {
|
||||
name: 'launcher-target', namespace: 'ns1', ownerReferences: [{ name: 'vm1' }]
|
||||
}
|
||||
};
|
||||
const { vm } = createVm({ vmi: readyVmi(), pods: [source, target] });
|
||||
|
||||
expect(vm.podResource.metadata.name).toBe('launcher-target');
|
||||
});
|
||||
|
||||
it('should find pods that are added to the store later', () => {
|
||||
const { vm, lists } = createVm({ vmi: readyVmi(), pods: [] });
|
||||
|
||||
expect(vm.podResource).toBeUndefined();
|
||||
|
||||
const pod = { metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] } };
|
||||
|
||||
lists[POD].push(pod);
|
||||
|
||||
expect(vm.podResource).toStrictEqual(pod);
|
||||
});
|
||||
|
||||
it('should not return a pod of a VM with the same name in another namespace', () => {
|
||||
const other = { metadata: { namespace: 'ns2', ownerReferences: [{ name: 'vm1' }] } };
|
||||
const mine = { metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] } };
|
||||
const { vm } = createVm({ vmi: readyVmi(), pods: [mine, other] });
|
||||
|
||||
expect(vm.podResource).toStrictEqual(mine);
|
||||
});
|
||||
|
||||
it('should not return pods that were removed from the store', () => {
|
||||
const pod = { metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] } };
|
||||
const { vm, lists } = createVm({ vmi: readyVmi(), pods: [pod] });
|
||||
|
||||
expect(vm.podResource).toStrictEqual(pod);
|
||||
|
||||
lists[POD].splice(0, 1);
|
||||
|
||||
expect(vm.podResource).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('store', () => {
|
||||
it('should read the data of the VM from the store the VM lives in, not from a fixed one', () => {
|
||||
// The VM model is used with the `harvester` store (Harvester product) and the `cluster` store (Rancher explorer)
|
||||
const pod = { metadata: { namespace: 'ns1', ownerReferences: [{ name: 'vm1' }] } };
|
||||
const { vm, globalReads } = createVm({
|
||||
vmi: readyVmi(),
|
||||
pods: [pod],
|
||||
pvcs: [pvc('disk-pvc', false)],
|
||||
restores: [{ id: 'ns1/r1', isComplete: true }],
|
||||
vm: {
|
||||
metadata: {
|
||||
name: 'vm1', namespace: 'ns1', annotations: { 'restore.harvesterhci.io/name': 'r1' }
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
expect(vm.vmi.id).toBe(VM_ID);
|
||||
expect(vm.podResource).toStrictEqual(pod);
|
||||
expect(vm.volumes).toHaveLength(1);
|
||||
expect(vm.restoreResource.id).toBe('ns1/r1');
|
||||
expect(vm.actualState).toBe('Running');
|
||||
expect(globalReads.filter((key) => /^(harvester|cluster)\//.test(key))).toStrictEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRestartRequired', () => {
|
||||
it('should reflect the RestartRequired condition', () => {
|
||||
const { vm } = createVm({ vm: { status: { conditions: [{ type: 'RestartRequired', status: 'True' }] } } });
|
||||
|
||||
expect(vm.isRestartRequired).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,95 @@
|
||||
import { reactive } from 'vue';
|
||||
import VirtVmInstance from '../kubevirt.io.virtualmachineinstance';
|
||||
import { HCI } from '../../types';
|
||||
import { HCI as HCI_ANNOTATIONS } from '../../config/labels-annotations';
|
||||
|
||||
jest.mock('../harvester', () => ({ __esModule: true, default: class {} }));
|
||||
jest.mock('@shell/plugins/dashboard-store/resource-class', () => ({ colorForState: () => 'text-info' }));
|
||||
|
||||
function migration(namespace, timestamp, phase = 'Running') {
|
||||
return {
|
||||
metadata: { namespace, creationTimestamp: timestamp },
|
||||
spec: { vmiName: 'vm1' },
|
||||
status: { phase },
|
||||
};
|
||||
}
|
||||
|
||||
function createVmi(migrations) {
|
||||
const list = reactive(migrations);
|
||||
const vmi = Object.create(VirtVmInstance.prototype);
|
||||
|
||||
Object.assign(vmi, {
|
||||
metadata: {
|
||||
namespace: 'ns1',
|
||||
name: 'vm1',
|
||||
annotations: { [HCI_ANNOTATIONS.MIGRATION_STATE]: 'Migrating' },
|
||||
},
|
||||
$getters: { all: (type) => type === HCI.VMIM ? list : [] },
|
||||
});
|
||||
|
||||
return { vmi, list };
|
||||
}
|
||||
|
||||
describe('class VirtVmInstance', () => {
|
||||
it('should select the newest migration in the VMI namespace regardless of list order', () => {
|
||||
const { vmi } = createVmi([
|
||||
migration('ns1', '2026-01-03T00:00:00Z'),
|
||||
migration('ns2', '2026-01-04T00:00:00Z', 'Failed'),
|
||||
migration('ns1', '2026-01-01T00:00:00Z', 'Failed'),
|
||||
]);
|
||||
|
||||
expect(vmi.vmimResource.metadata.creationTimestamp).toBe('2026-01-03T00:00:00Z');
|
||||
expect(vmi.migrationState.status).toBe('Migrating');
|
||||
});
|
||||
|
||||
it('should follow additions, timestamp changes, phase changes and removals in the same list', () => {
|
||||
const { vmi, list } = createVmi([]);
|
||||
|
||||
expect(vmi.vmimResource).toStrictEqual([]);
|
||||
expect(vmi.migrationState).toBeNull();
|
||||
|
||||
list.push(migration('ns1', '2026-01-01T00:00:00Z'));
|
||||
expect(vmi.migrationState.status).toBe('Migrating');
|
||||
|
||||
list.push(migration('ns1', '2026-01-02T00:00:00Z', 'Failed'));
|
||||
expect(vmi.migrationState.status).toBe('Failed');
|
||||
|
||||
list[0].metadata.creationTimestamp = '2026-01-03T00:00:00Z';
|
||||
expect(vmi.vmimResource).toBe(list[0]);
|
||||
expect(vmi.migrationState.status).toBe('Migrating');
|
||||
|
||||
list[0].status.phase = 'Failed';
|
||||
expect(vmi.migrationState.status).toBe('Failed');
|
||||
|
||||
list.splice(0, 2);
|
||||
expect(vmi.migrationState).toBeNull();
|
||||
});
|
||||
|
||||
it('should follow a migration reassigned to another VMI or namespace', () => {
|
||||
const { vmi, list } = createVmi([migration('ns1', '2026-01-01T00:00:00Z')]);
|
||||
|
||||
expect(vmi.migrationState.status).toBe('Migrating');
|
||||
|
||||
list[0].spec.vmiName = 'vm2';
|
||||
expect(vmi.migrationState).toBeNull();
|
||||
|
||||
list[0].spec.vmiName = 'vm1';
|
||||
list[0].metadata.namespace = 'ns2';
|
||||
expect(vmi.migrationState).toBeNull();
|
||||
});
|
||||
|
||||
it('should invalidate the index when the store replaces properties on an existing migration', () => {
|
||||
const { vmi, list } = createVmi([migration('ns1', '2026-01-01T00:00:00Z')]);
|
||||
|
||||
expect(vmi.migrationState.status).toBe('Migrating');
|
||||
|
||||
const existing = list[0];
|
||||
|
||||
for (const key of Object.keys(existing)) {
|
||||
delete existing[key];
|
||||
}
|
||||
Object.assign(existing, migration('ns2', '2026-01-02T00:00:00Z', 'Failed'));
|
||||
|
||||
expect(vmi.migrationState).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -23,6 +23,13 @@ const ALLOW_SYSTEM_LABEL_KEYS = [
|
||||
|
||||
const HEALTHY = 'healthy';
|
||||
const WARNING = 'warning';
|
||||
const MAINTENANCE_MODE = 'MaintenanceMode';
|
||||
const MAINTENANCE_ERROR = 'Error';
|
||||
const MAINTENANCE_ENTERING_REASONS = ['Validating', 'Draining', 'Evacuating'];
|
||||
const MAINTENANCE_COMPLETED = 'Completed';
|
||||
// Legacy `harvesterhci.io/maintain-status` annotation values (clusters < v1.10)
|
||||
const LEGACY_MAINTENANCE_RUNNING = 'running';
|
||||
const LEGACY_MAINTENANCE_COMPLETED = 'completed';
|
||||
|
||||
export default class HciNode extends HarvesterResource {
|
||||
get _availableActions() {
|
||||
@@ -58,6 +65,14 @@ export default class HciNode extends HarvesterResource {
|
||||
total: 1
|
||||
};
|
||||
|
||||
const clearMaintenance = {
|
||||
action: 'clearMaintenanceMode',
|
||||
enabled: this.hasAction('clearMaintenanceMode'),
|
||||
icon: 'icon icon-fw icon-close',
|
||||
label: this.t('harvester.action.clearMaintenance'),
|
||||
total: 1
|
||||
};
|
||||
|
||||
const enableCPUManager = {
|
||||
action: 'enableCPUManager',
|
||||
enabled: this.cpuPinningFeatureEnabled && this.hasAction('enableCPUManager') && !this.isCPUManagerEnableInProgress && !this.isCPUManagerEnabled && !this.isEtcd, // witness node doesn't have CPU manager
|
||||
@@ -103,6 +118,7 @@ export default class HciNode extends HarvesterResource {
|
||||
uncordon,
|
||||
enableMaintenance,
|
||||
disableMaintenance,
|
||||
clearMaintenance,
|
||||
enableCPUManager,
|
||||
disableCPUManager,
|
||||
shutDown,
|
||||
@@ -198,6 +214,10 @@ export default class HciNode extends HarvesterResource {
|
||||
}
|
||||
|
||||
get stateDisplay() {
|
||||
if (this.isMaintenanceModeError) {
|
||||
return super.stateDisplay;
|
||||
}
|
||||
|
||||
if (this.isEnteringMaintenance) {
|
||||
return 'Entering maintenance mode';
|
||||
}
|
||||
@@ -246,6 +266,10 @@ export default class HciNode extends HarvesterResource {
|
||||
}
|
||||
|
||||
get stateDescription() {
|
||||
if (this.isMaintenanceModeError) {
|
||||
return super.stateDescription;
|
||||
}
|
||||
|
||||
const currentIP = this.metadata?.annotations?.[HCI_ANNOTATIONS.CURRENT_IP];
|
||||
const initIP = this.metadata?.annotations?.[HCI_ANNOTATIONS.INIT_IP];
|
||||
|
||||
@@ -325,7 +349,11 @@ export default class HciNode extends HarvesterResource {
|
||||
}
|
||||
|
||||
disableMaintenanceMode() {
|
||||
this.doAction('disableMaintenanceMode', {});
|
||||
this.doActionGrowl('disableMaintenanceMode', {});
|
||||
}
|
||||
|
||||
clearMaintenanceMode() {
|
||||
this.doActionGrowl('clearMaintenanceMode', {});
|
||||
}
|
||||
|
||||
enableCPUManager() {
|
||||
@@ -343,11 +371,32 @@ export default class HciNode extends HarvesterResource {
|
||||
);
|
||||
}
|
||||
|
||||
get maintenanceModeCondition() {
|
||||
return (this.status?.conditions || []).find(
|
||||
(c) => c.type === MAINTENANCE_MODE
|
||||
);
|
||||
}
|
||||
|
||||
get maintenanceModeConditionsEnabled() {
|
||||
return this.$rootGetters['harvester-common/getFeatureEnabled']('maintenanceModeConditions');
|
||||
}
|
||||
|
||||
// Clusters < v1.10 only expose the `harvesterhci.io/maintain-status` annotation
|
||||
get legacyMaintenanceStatus() {
|
||||
return this.metadata?.annotations?.[HCI_ANNOTATIONS.MAINTENANCE_STATUS];
|
||||
}
|
||||
|
||||
get isMaintenanceModeError() {
|
||||
return this.maintenanceModeConditionsEnabled && this.maintenanceModeCondition?.reason === MAINTENANCE_ERROR;
|
||||
}
|
||||
|
||||
get isMigratable() {
|
||||
const states = ['in-progress', 'unavailable'];
|
||||
|
||||
const engaged = this.maintenanceModeConditionsEnabled ? this.maintenanceModeCondition?.status === 'True' : !!this.legacyMaintenanceStatus;
|
||||
|
||||
return (
|
||||
!this.metadata?.annotations?.[HCI_ANNOTATIONS.MAINTENANCE_STATUS] &&
|
||||
!engaged &&
|
||||
!this.isUnSchedulable &&
|
||||
!states.includes(this.state)
|
||||
);
|
||||
@@ -362,17 +411,26 @@ export default class HciNode extends HarvesterResource {
|
||||
}
|
||||
|
||||
get isEnteringMaintenance() {
|
||||
if (!this.maintenanceModeConditionsEnabled) {
|
||||
return this.legacyMaintenanceStatus === LEGACY_MAINTENANCE_RUNNING;
|
||||
}
|
||||
|
||||
const cond = this.maintenanceModeCondition;
|
||||
|
||||
return (
|
||||
this.metadata?.annotations?.[HCI_ANNOTATIONS.MAINTENANCE_STATUS] ===
|
||||
'running'
|
||||
cond?.status === 'True' &&
|
||||
MAINTENANCE_ENTERING_REASONS.includes(cond?.reason)
|
||||
);
|
||||
}
|
||||
|
||||
get isMaintenance() {
|
||||
return (
|
||||
this.metadata?.annotations?.[HCI_ANNOTATIONS.MAINTENANCE_STATUS] ===
|
||||
'completed'
|
||||
);
|
||||
if (!this.maintenanceModeConditionsEnabled) {
|
||||
return this.legacyMaintenanceStatus === LEGACY_MAINTENANCE_COMPLETED;
|
||||
}
|
||||
|
||||
const cond = this.maintenanceModeCondition;
|
||||
|
||||
return cond?.status === 'True' && cond?.reason === MAINTENANCE_COMPLETED;
|
||||
}
|
||||
|
||||
get cpuPinningFeatureEnabled() {
|
||||
|
||||
@@ -326,7 +326,7 @@ export default class HciPv extends HarvesterResource {
|
||||
}
|
||||
|
||||
get relatedPV() {
|
||||
return this.$rootGetters['harvester/all'](PV).find((pv) => pv.metadata?.name === this.spec?.volumeName);
|
||||
return this.$rootGetters['harvester/byId'](PV, this.spec?.volumeName);
|
||||
}
|
||||
|
||||
get volumeProvider() {
|
||||
|
||||
@@ -5,12 +5,14 @@ import HarvesterResource from './harvester';
|
||||
import { HCI } from '../types';
|
||||
|
||||
const HARVESTER_NVIDIA_DRIVER_TOOLKIT = 'harvester-system/nvidia-driver-toolkit';
|
||||
const RANCHER_VCLUSTER = 'harvester-system/rancher-vcluster';
|
||||
const RANCHER_K3K_ADDON = 'rancher-k3k/rancher-k3k';
|
||||
|
||||
export default class HciAddonConfig extends HarvesterResource {
|
||||
get availableActions() {
|
||||
const out = super._availableActions;
|
||||
|
||||
if (this.id === 'harvester-system/rancher-vcluster') {
|
||||
if (this.id === RANCHER_VCLUSTER || this.id === RANCHER_K3K_ADDON) {
|
||||
const rancherDashboard = {
|
||||
action: 'goToRancher',
|
||||
enabled: this.spec.enabled,
|
||||
@@ -57,6 +59,15 @@ export default class HciAddonConfig extends HarvesterResource {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.spec.enabled && this.id === RANCHER_K3K_ADDON) {
|
||||
this.$dispatch('promptModal', {
|
||||
resources: [this],
|
||||
component: 'HarvesterEnableK3k',
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.spec.enabled = !this.spec.enabled;
|
||||
await this.save();
|
||||
} catch (err) {
|
||||
@@ -69,18 +80,19 @@ export default class HciAddonConfig extends HarvesterResource {
|
||||
}
|
||||
|
||||
goToRancher() {
|
||||
const valuesContent = jsyaml.load(this.spec.valuesContent);
|
||||
|
||||
window.open(
|
||||
`https://${ valuesContent.hostname }`,
|
||||
this.rancherHostname,
|
||||
'_blank',
|
||||
);
|
||||
}
|
||||
|
||||
get rancherHostname() {
|
||||
const valuesContent = jsyaml.load(this.spec.valuesContent);
|
||||
const valuesContent = jsyaml.load(this.spec.valuesContent) || {};
|
||||
|
||||
return `https://${ valuesContent.hostname }`;
|
||||
// rancher-k3k nests the hostname under `rancher`, rancher-vcluster keeps it at the top level
|
||||
const hostname = this.id === RANCHER_K3K_ADDON ? valuesContent.rancher?.hostname : valuesContent.hostname;
|
||||
|
||||
return `https://${ hostname }`;
|
||||
}
|
||||
|
||||
get stateColor() {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { load } from 'js-yaml';
|
||||
import { omitBy, pickBy } from 'lodash';
|
||||
import { PRODUCT_NAME as HARVESTER_PRODUCT } from '../config/harvester';
|
||||
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { colorForState, stateSort } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { POD, NODE, PVC } from '@shell/config/types';
|
||||
import { findBy } from '@shell/utils/array';
|
||||
import { parseSi } from '@shell/utils/units';
|
||||
@@ -14,6 +14,7 @@ import { BACKUP_TYPE } from '../config/types';
|
||||
import { HCI } from '../types';
|
||||
import HarvesterResource from './harvester';
|
||||
import { getVmCPUMemoryValues } from '../utils/cpuMemory';
|
||||
import { sharedComputed } from '../utils/shared-computed';
|
||||
import { isBackupTargetSettingUnavailable } from '../utils/setting';
|
||||
|
||||
export const OFF = 'Off';
|
||||
@@ -81,42 +82,48 @@ const VMIPhase = {
|
||||
Unknown: 'Unknown'
|
||||
};
|
||||
|
||||
let productInStore;
|
||||
// Index of the pods (namespace/ownerName -> pod), shared by all rows. `podList` must be the store list, not a copy.
|
||||
// If several pods have the same owner (e.g. while a VM migrates), the last one wins.
|
||||
function getPodOwnerIndex(podList) {
|
||||
return sharedComputed(podList, 'podOwnerIndex', (pods) => {
|
||||
const map = new Map(); // namespace/ownerName -> pod
|
||||
|
||||
let _podOwnerMap = null;
|
||||
let _podOwnerMapSource = null;
|
||||
for (const pod of pods) {
|
||||
const refName = pod.metadata?.ownerReferences?.[0]?.name;
|
||||
|
||||
function getPodByOwnerName(rootGetters, inStore, ownerName) {
|
||||
const podList = rootGetters[`${ inStore }/all`](POD);
|
||||
if (refName) {
|
||||
map.set(`${ pod.metadata.namespace }/${ refName }`, pod);
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
});
|
||||
}
|
||||
|
||||
// `getters` are the getters of the store of the VM (`this.$getters`)
|
||||
function getPodByOwnerName(getters, namespace, ownerName) {
|
||||
const podList = getters['all'](POD);
|
||||
|
||||
if (!Array.isArray(podList)) {
|
||||
return undefined;
|
||||
}
|
||||
// if not equals (usually means the pod list has been updated), we need to rebuild the map, otherwise we can reuse the map for better performance
|
||||
if (_podOwnerMapSource !== podList) {
|
||||
_podOwnerMap = new Map(); // use Map to store ownerReference name and pod mapping
|
||||
for (const pod of podList) {
|
||||
const refName = pod.metadata?.ownerReferences?.[0]?.name;
|
||||
|
||||
if (refName) {
|
||||
_podOwnerMap.set(refName, pod);
|
||||
}
|
||||
}
|
||||
_podOwnerMapSource = podList;
|
||||
}
|
||||
|
||||
return _podOwnerMap.get(ownerName);
|
||||
return getPodOwnerIndex(podList).get(`${ namespace }/${ ownerName }`);
|
||||
}
|
||||
|
||||
function getPvcsByNames(rootGetters, inStore, names) {
|
||||
const pvcList = rootGetters[`${ inStore }/all`](PVC);
|
||||
// A VM only uses PVCs of its own namespace, so look them up by id instead of scanning all PVCs
|
||||
function getPvcsByNames(getters, namespace, names) {
|
||||
const out = [];
|
||||
|
||||
if (!Array.isArray(pvcList)) {
|
||||
return [];
|
||||
for (const name of new Set(names)) {
|
||||
const pvc = getters['byId'](PVC, `${ namespace }/${ name }`);
|
||||
|
||||
if (pvc) {
|
||||
out.push(pvc);
|
||||
}
|
||||
}
|
||||
const uniqueNames = new Set(names);
|
||||
|
||||
return pvcList.filter((pvc) => uniqueNames.has(pvc.metadata?.name));
|
||||
return out;
|
||||
}
|
||||
|
||||
const IgnoreMessages = ['pod has unbound immediate PersistentVolumeClaims'];
|
||||
@@ -135,7 +142,8 @@ export default class VirtVm extends HarvesterResource {
|
||||
clone.action = 'goToCloneVM';
|
||||
}
|
||||
|
||||
const canCreateVMSSchedule = !!this.$getters?.['schemaFor']?.(HCI.SCHEDULE_VM_BACKUP)?.collectionMethods?.find((x) => ['post'].includes(x.toLowerCase()));
|
||||
const scheduleSchema = this.$getters?.['schemaFor']?.(HCI.SCHEDULE_VM_BACKUP);
|
||||
const canCreateVMSSchedule = !!scheduleSchema && sharedComputed(scheduleSchema, 'canPost', (schema) => !!schema.collectionMethods?.find((x) => ['post'].includes(x.toLowerCase())));
|
||||
|
||||
return [
|
||||
{
|
||||
@@ -288,14 +296,6 @@ export default class VirtVm extends HarvesterResource {
|
||||
];
|
||||
}
|
||||
|
||||
get productInStore() {
|
||||
if (!productInStore) {
|
||||
productInStore = this.$rootGetters['currentProduct'].inStore;
|
||||
}
|
||||
|
||||
return productInStore;
|
||||
}
|
||||
|
||||
applyDefaults(resources = this, realMode) {
|
||||
const spec = {
|
||||
runStrategy: 'RerunOnFailure',
|
||||
@@ -729,14 +729,13 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get podResource() {
|
||||
const inStore = this.productInStore;
|
||||
const vmiResource = this.$rootGetters[`${ inStore }/byId`](HCI.VMI, this.id);
|
||||
const vmiResource = this.$getters['byId'](HCI.VMI, this.id);
|
||||
|
||||
if (!vmiResource?.metadata?.name) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return getPodByOwnerName(this.$rootGetters, inStore, vmiResource.metadata.name);
|
||||
return getPodByOwnerName(this.$getters, vmiResource.metadata.namespace, vmiResource.metadata.name);
|
||||
}
|
||||
|
||||
get isPaused() {
|
||||
@@ -764,8 +763,7 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get nsResourceQuota() {
|
||||
const inStore = this.productInStore;
|
||||
const allResQuotas = this.$rootGetters[`${ inStore }/all`](HCI.RESOURCE_QUOTA);
|
||||
const allResQuotas = this.$getters['all'](HCI.RESOURCE_QUOTA);
|
||||
|
||||
return allResQuotas.find( (RQ) => RQ.namespace === this.metadata.namespace);
|
||||
}
|
||||
@@ -775,15 +773,13 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get vmi() {
|
||||
const inStore = this.productInStore;
|
||||
|
||||
return this.$rootGetters[`${ inStore }/byId`](HCI.VMI, this.id);
|
||||
return this.$getters['byId'](HCI.VMI, this.id);
|
||||
}
|
||||
|
||||
get volumes() {
|
||||
const volumeClaimNames = this.spec.template.spec.volumes?.map((v) => v.persistentVolumeClaim?.claimName).filter((v) => !!v) || [];
|
||||
|
||||
return getPvcsByNames(this.$rootGetters, this.productInStore, volumeClaimNames);
|
||||
return getPvcsByNames(this.$getters, this.metadata.namespace, volumeClaimNames);
|
||||
}
|
||||
|
||||
get lvmVolumes() {
|
||||
@@ -807,13 +803,15 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get encryptedVolumeType() {
|
||||
if (!this.volumes || this.volumes.length === 0) {
|
||||
const volumes = this.volumes;
|
||||
|
||||
if (!volumes || volumes.length === 0) {
|
||||
return 'none';
|
||||
}
|
||||
|
||||
if (this.volumes.every((vol) => vol.isEncrypted)) {
|
||||
if (volumes.every((vol) => vol.isEncrypted)) {
|
||||
return 'all';
|
||||
} else if (this.volumes.some((vol) => vol.isEncrypted)) {
|
||||
} else if (volumes.some((vol) => vol.isEncrypted)) {
|
||||
return 'partial';
|
||||
} else {
|
||||
return 'none';
|
||||
@@ -918,15 +916,14 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get isUnschedulable() {
|
||||
if (this.isStopping || this.isStarting) {
|
||||
const condition = this.status?.conditions?.find((c) => c.reason === UNSCHEDULABLE);
|
||||
// Check the cheap condition first
|
||||
const condition = this.status?.conditions?.find((c) => c.reason === UNSCHEDULABLE);
|
||||
|
||||
if (!!condition) {
|
||||
return {
|
||||
status: UNSCHEDULABLE,
|
||||
message: condition.message || 'VM is unschedulable',
|
||||
};
|
||||
}
|
||||
if (condition && (this.isStopping || this.isStarting)) {
|
||||
return {
|
||||
status: UNSCHEDULABLE,
|
||||
message: condition.message || 'VM is unschedulable',
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -971,16 +968,14 @@ export default class VirtVm extends HarvesterResource {
|
||||
`metadata.annotations."${ HCI_ANNOTATIONS.RESTORE_NAME }"`
|
||||
) }`;
|
||||
|
||||
const inStore = this.productInStore;
|
||||
|
||||
const res = this.$rootGetters[`${ inStore }/byId`](HCI.RESTORE, id);
|
||||
const res = this.$getters['byId'](HCI.RESTORE, id);
|
||||
|
||||
if (res) {
|
||||
const allBackups = this.$rootGetters[`${ inStore }/all`](HCI.BACKUP);
|
||||
const backupId = `${ res.spec?.virtualMachineBackupNamespace }/${ res.spec?.virtualMachineBackupName }`;
|
||||
const backup = this.$getters['byId'](HCI.BACKUP, backupId);
|
||||
|
||||
res.fromSnapshot = !!allBackups
|
||||
.filter((b) => b.spec?.type !== BACKUP_TYPE.BACKUP)
|
||||
.find((s) => s.id === `${ res.spec?.virtualMachineBackupNamespace }/${ res.spec?.virtualMachineBackupName }`);
|
||||
// Snapshots and backups are told apart by spec.type
|
||||
res.fromSnapshot = !!backup && backup.spec?.type !== BACKUP_TYPE.BACKUP;
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -1005,11 +1000,13 @@ export default class VirtVm extends HarvesterResource {
|
||||
}
|
||||
|
||||
get restoreState() {
|
||||
if (!this.restoreResource) {
|
||||
const restore = this.restoreResource;
|
||||
|
||||
if (!restore) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.restoreResource?.isComplete;
|
||||
return restore.isComplete;
|
||||
}
|
||||
|
||||
get actualState() {
|
||||
@@ -1110,6 +1107,13 @@ export default class VirtVm extends HarvesterResource {
|
||||
return colorForState(state);
|
||||
}
|
||||
|
||||
// Evaluate actualState once, the base implementation does it in stateColor and stateDisplay
|
||||
get stateSort() {
|
||||
const state = this.actualState;
|
||||
|
||||
return stateSort(colorForState(state), state);
|
||||
}
|
||||
|
||||
get networkIps() {
|
||||
let networkData = '';
|
||||
const out = [];
|
||||
@@ -1160,7 +1164,6 @@ export default class VirtVm extends HarvesterResource {
|
||||
|
||||
get rootImageId() {
|
||||
let imageId = '';
|
||||
const inStore = this.productInStore;
|
||||
|
||||
const volumes = this.spec.template.spec.volumes || [];
|
||||
|
||||
@@ -1170,7 +1173,7 @@ export default class VirtVm extends HarvesterResource {
|
||||
});
|
||||
|
||||
if (!isNoExistingVolume) {
|
||||
const existingVolume = this.$rootGetters[`${ inStore }/byId`](PVC, `${ this.metadata.namespace }/${ firstVolumeName }`);
|
||||
const existingVolume = this.$getters['byId'](PVC, `${ this.metadata.namespace }/${ firstVolumeName }`);
|
||||
|
||||
if (existingVolume) {
|
||||
return existingVolume?.metadata?.annotations?.[
|
||||
@@ -1366,7 +1369,12 @@ export default class VirtVm extends HarvesterResource {
|
||||
get isBackupTargetUnavailable() {
|
||||
const backupTargetSetting = this.$rootGetters['harvester/byId'](HCI.SETTING, 'backup-target');
|
||||
|
||||
return isBackupTargetSettingUnavailable(backupTargetSetting);
|
||||
// sharedComputed needs an object as key
|
||||
if (!backupTargetSetting) {
|
||||
return isBackupTargetSettingUnavailable(backupTargetSetting);
|
||||
}
|
||||
|
||||
return sharedComputed(backupTargetSetting, 'unavailable', isBackupTargetSettingUnavailable);
|
||||
}
|
||||
|
||||
setInstanceLabels(val) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { colorForState } from '@shell/plugins/dashboard-store/resource-class';
|
||||
import { NODE } from '@shell/config/types';
|
||||
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
||||
import { getLatestMigration } from '@pkg/utils/vm';
|
||||
import { HCI } from '../types';
|
||||
import HarvesterResource from './harvester';
|
||||
|
||||
@@ -45,32 +46,25 @@ export default class VirtVmInstance extends HarvesterResource {
|
||||
return colorForState(state);
|
||||
}
|
||||
|
||||
// The newest migration of this VMI, an empty array if there is none
|
||||
get vmimResource() {
|
||||
const all = this.$rootGetters['harvester/all'](HCI.VMIM) || [];
|
||||
const vmimList = all.filter((vmim) => vmim.spec?.vmiName === this.metadata?.name);
|
||||
const all = this.$getters['all'](HCI.VMIM) || [];
|
||||
|
||||
if (vmimList.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
vmimList.sort((a, b) => {
|
||||
return a?.metadata?.creationTimestamp > b?.metadata?.creationTimestamp ? -1 : 1;
|
||||
});
|
||||
|
||||
return vmimList[0];
|
||||
return getLatestMigration(all, this.metadata?.namespace, this.metadata?.name) || [];
|
||||
}
|
||||
|
||||
get migrationState() {
|
||||
const state = this.metadata?.annotations?.[HCI_ANNOTATIONS.MIGRATION_STATE];
|
||||
const migration = this.vmimResource;
|
||||
|
||||
if (this.vmimResource?.status?.phase === VMIPhase.Failed) {
|
||||
if (migration?.status?.phase === VMIPhase.Failed) {
|
||||
return {
|
||||
type: 'migration',
|
||||
status: VMIPhase.Failed
|
||||
};
|
||||
}
|
||||
|
||||
if (this.vmimResource?.status?.phase && state) {
|
||||
if (migration?.status?.phase && state) {
|
||||
return {
|
||||
type: 'migration',
|
||||
status: state
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import ManagementSetting from '@shell/models/management.cattle.io.setting';
|
||||
import { HCI_SETTING } from '../../config/settings';
|
||||
|
||||
export default class HarvesterManagementSetting extends ManagementSetting {
|
||||
get _availableActions() {
|
||||
const actions = super._availableActions;
|
||||
|
||||
if (this.$rootGetters['isStandaloneHarvester'] && this.id === HCI_SETTING.UI_PL) {
|
||||
return actions.filter((action) => !['goToClone', 'promptRemove'].includes(action.action));
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "harvester",
|
||||
"description": "Rancher UI Extension for Harvester",
|
||||
"version": "1.10.0-dev",
|
||||
"version": "1.10.0-rc1",
|
||||
"private": false,
|
||||
"rancher": {
|
||||
"annotations": {
|
||||
|
||||
@@ -232,6 +232,7 @@ export default {
|
||||
this.imageValue.spec.targetStorageClassName = 'longhorn-static';
|
||||
|
||||
res = await this.imageValue.save();
|
||||
res.notifyGeneratedName?.();
|
||||
|
||||
this.value.spec.image = res.id;
|
||||
}
|
||||
@@ -253,6 +254,7 @@ export default {
|
||||
this.value.metadata.annotations = { [HCI_ANNOTATIONS.SKIP_SINGLE_REPLICA_DETACHED_VOL]: JSON.stringify(this.skipSingleReplicaDetachedVol) };
|
||||
}
|
||||
await this.value.save();
|
||||
this.value.notifyGeneratedName?.();
|
||||
this.done();
|
||||
buttonCb(true);
|
||||
} catch (e) {
|
||||
@@ -290,6 +292,7 @@ export default {
|
||||
|
||||
const res = await this.imageValue.save();
|
||||
|
||||
res.notifyGeneratedName?.();
|
||||
this.uploadImageId = res.id;
|
||||
this.uploadController = new AbortController();
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ export default {
|
||||
return {
|
||||
vendor: getVendor(),
|
||||
uiPLSetting: {},
|
||||
privateLabelDraft: null,
|
||||
uiLogoDarkSetting: {},
|
||||
uiLogoDark: '',
|
||||
uiLogoLightSetting: {},
|
||||
@@ -81,6 +82,17 @@ export default {
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
isHarvesterPrime() {
|
||||
return !!this.$store.getters['harvester-common/isHarvesterPrime'];
|
||||
},
|
||||
privateLabel: {
|
||||
get() {
|
||||
return this.privateLabelDraft ?? (this.isHarvesterPrime ? this.$store.getters['harvester-common/privateLabel'] : this.uiPLSetting.value);
|
||||
},
|
||||
set(value) {
|
||||
this.privateLabelDraft = value;
|
||||
}
|
||||
},
|
||||
mode() {
|
||||
const schema = this.$store.getters[`management/schemaFor`](MANAGEMENT.SETTING);
|
||||
|
||||
@@ -112,7 +124,7 @@ export default {
|
||||
this.errors.push(e);
|
||||
},
|
||||
async save(btnCB) {
|
||||
this.uiPLSetting.value = this.uiPLSetting.value.replaceAll(/[\<>&=#()"]/gm, '');
|
||||
this.uiPLSetting.value = (this.privateLabel || '').replaceAll(/[\<>&=#()"]/gm, '');
|
||||
if (this.customizeLogo) {
|
||||
this.uiLogoLightSetting.value = this.uiLogoLight;
|
||||
this.uiLogoDarkSetting.value = this.uiLogoDark;
|
||||
@@ -169,7 +181,7 @@ export default {
|
||||
<div class="row mb-20">
|
||||
<div class="col span-6">
|
||||
<LabeledInput
|
||||
v-model:value="uiPLSetting.value"
|
||||
v-model:value="privateLabel"
|
||||
:label="t('branding.uiPL.label')"
|
||||
:mode="mode"
|
||||
:maxlength="100"
|
||||
@@ -198,7 +210,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.logos.uploadLight')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
@@ -221,7 +234,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.logos.uploadDark')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
@@ -262,7 +276,8 @@ export default {
|
||||
<FileSelector
|
||||
:byte-limit="20000"
|
||||
:read-as-data-url="true"
|
||||
class="role-secondary"
|
||||
variant="secondary"
|
||||
size="large"
|
||||
:label="t('branding.favicon.upload')"
|
||||
:mode="mode"
|
||||
@error="setError"
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
<script>
|
||||
import { defineAsyncComponent } from 'vue';
|
||||
import Loading from '@shell/components/Loading';
|
||||
import TabTitle from '@shell/components/TabTitle';
|
||||
import { HCI } from '../../../../../types';
|
||||
import NovncConsoleWrapper from '../../../../../components/novnc/NovncConsoleWrapper.vue';
|
||||
|
||||
export default {
|
||||
components: { NovncConsoleWrapper, Loading },
|
||||
components: {
|
||||
NovncConsoleWrapper: defineAsyncComponent({
|
||||
loader: () => import('../../../../../components/novnc/NovncConsoleWrapper.vue'),
|
||||
loadingComponent: Loading,
|
||||
}),
|
||||
Loading,
|
||||
TabTitle
|
||||
},
|
||||
|
||||
async fetch() {
|
||||
this.rows = await this.$store.dispatch('harvester/findAll', { type: HCI.VMI });
|
||||
@@ -28,17 +36,21 @@ export default {
|
||||
|
||||
mounted() {
|
||||
window.addEventListener('beforeunload', () => {
|
||||
this.$refs.console.close();
|
||||
this.$refs.console?.close();
|
||||
});
|
||||
},
|
||||
|
||||
head() {
|
||||
return { title: this.vmi?.metadata?.name };
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<TabTitle
|
||||
v-if="vmi?.metadata?.name"
|
||||
:breadcrumb="false"
|
||||
:show-child="false"
|
||||
>
|
||||
{{ vmi.metadata.name }}
|
||||
</TabTitle>
|
||||
<Loading v-if="$fetchState.pending" />
|
||||
<NovncConsoleWrapper
|
||||
v-else
|
||||
|
||||
@@ -12,6 +12,7 @@ import { PRODUCT_NAME } from '@pkg/harvester/config/harvester';
|
||||
import { currentRouter, currentRoute } from '@pkg/harvester/utils/router';
|
||||
import { decodeSecretValue } from '@pkg/harvester/utils/forklift';
|
||||
import { HCI } from '@pkg/harvester/types';
|
||||
import { preventImplicitSubmit } from '@pkg/harvester/utils/wizard';
|
||||
|
||||
const store = useStore();
|
||||
const route = currentRoute();
|
||||
@@ -258,6 +259,7 @@ init();
|
||||
:title="wizardTitle"
|
||||
finish-mode="finish"
|
||||
class="wizard"
|
||||
@keydown.enter.capture="preventImplicitSubmit"
|
||||
@cancel="onCancel"
|
||||
@finish="onFinish"
|
||||
>
|
||||
|
||||
@@ -10,6 +10,7 @@ import ReviewMigrationStep from '@pkg/harvester/components/vm-migration/ReviewMi
|
||||
import { PRODUCT_NAME } from '@pkg/harvester/config/harvester';
|
||||
import { currentRouter } from '@pkg/harvester/utils/router';
|
||||
import { exceptionToErrorsArray, stringify } from '@shell/utils/error';
|
||||
import { preventImplicitSubmit } from '@pkg/harvester/utils/wizard';
|
||||
|
||||
const store = useStore();
|
||||
const { t } = useI18n(store);
|
||||
@@ -269,6 +270,7 @@ const onCancel = () => {
|
||||
finish-mode="finish"
|
||||
finish-button-mode="createAndStart"
|
||||
class="wizard"
|
||||
@keydown.enter.capture="preventImplicitSubmit"
|
||||
@cancel="onCancel"
|
||||
@finish="onFinish"
|
||||
>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import Parse from 'url-parse';
|
||||
import { MANAGEMENT } from '@shell/config/types';
|
||||
import { SETTING } from '@shell/config/settings';
|
||||
import { HCI } from '../types';
|
||||
import { PRODUCT_NAME } from '../config/harvester';
|
||||
import { featureEnabled, getVersion } from '../utils/feature-flags';
|
||||
@@ -64,6 +66,23 @@ const mutations = {
|
||||
};
|
||||
|
||||
const getters = {
|
||||
isHarvesterPrime: (_state, _getters, _rootState, rootGetters) => {
|
||||
const setting = rootGetters['harvester/byId']?.(HCI.SETTING, 'server-flavor');
|
||||
|
||||
return (setting?.value || setting?.default) === 'prime';
|
||||
},
|
||||
|
||||
privateLabel: (_state, getters, _rootState, rootGetters) => {
|
||||
const setting = rootGetters['management/byId']?.(MANAGEMENT.SETTING, SETTING.PL);
|
||||
const value = setting?.value || '';
|
||||
|
||||
if (getters.isHarvesterPrime && value === (setting?.default || 'Harvester')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return value;
|
||||
},
|
||||
|
||||
getBundleId(state) {
|
||||
return state.latestBundleId;
|
||||
},
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { featureEnabled } from '../feature-flags';
|
||||
|
||||
describe('featureEnabled', () => {
|
||||
it('should enable a feature from the version it was released in', () => {
|
||||
expect(featureEnabled('hotplugNic', 'v1.7.0')).toBe(true);
|
||||
expect(featureEnabled('hotplugNic', 'v1.8.2')).toBe(true);
|
||||
});
|
||||
|
||||
it('should not enable a feature before the version it was released in', () => {
|
||||
expect(featureEnabled('hotplugNic', 'v1.6.1')).toBe(false);
|
||||
expect(featureEnabled('hotplugCdRom', 'v1.7.1')).toBe(false);
|
||||
});
|
||||
|
||||
it('should ignore pre-release suffixes of the server version', () => {
|
||||
expect(featureEnabled('hotplugCdRom', 'v1.8.0-rc1')).toBe(true);
|
||||
expect(featureEnabled('hotplugCdRom', 'v1.8.0-dev-20260101')).toBe(true);
|
||||
});
|
||||
|
||||
it('should enable vncPreserveSession only from Harvester v1.7.0, whose KubeVirt honours it', () => {
|
||||
expect(featureEnabled('vncPreserveSession', 'v1.6.1')).toBe(false);
|
||||
expect(featureEnabled('vncPreserveSession', 'v1.7.0')).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false for unknown features', () => {
|
||||
expect(featureEnabled('doesNotExist', 'v1.8.0')).toBe(false);
|
||||
});
|
||||
|
||||
it('should not enable anything for versions that are no longer supported', () => {
|
||||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||
|
||||
expect(featureEnabled('cpuPinning', 'v1.2.0')).toBe(false);
|
||||
|
||||
spy.mockRestore();
|
||||
});
|
||||
|
||||
it('should return the same result for repeated calls with different arguments', () => {
|
||||
expect(featureEnabled('hotplugNic', 'v1.6.0')).toBe(false);
|
||||
expect(featureEnabled('hotplugNic', 'v1.7.0')).toBe(true);
|
||||
expect(featureEnabled('hotplugNic', 'v1.6.0')).toBe(false);
|
||||
expect(featureEnabled('hotplugNic', 'v1.7.0')).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,101 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { load } from 'js-yaml';
|
||||
import { hostResolvesL10nGlobals, resolveL10nGlobals, setStandalonePrime, standaloneProductName } from '../l10n-globals';
|
||||
|
||||
describe('hostResolvesL10nGlobals', () => {
|
||||
it('should be true from Rancher 2.16', () => {
|
||||
expect(hostResolvesL10nGlobals('v2.16.0')).toBe(true);
|
||||
expect(hostResolvesL10nGlobals('v2.17.1')).toBe(true);
|
||||
});
|
||||
|
||||
it('should be true for 2.16 head builds', () => {
|
||||
expect(hostResolvesL10nGlobals('v2.16.0-68ddd75-head')).toBe(true);
|
||||
expect(hostResolvesL10nGlobals('v2.16-136b11a0062247c1b28f107d82283bdb29bc07ae-head')).toBe(true);
|
||||
});
|
||||
|
||||
it('should be false before Rancher 2.16', () => {
|
||||
expect(hostResolvesL10nGlobals('v2.15.1')).toBe(false);
|
||||
expect(hostResolvesL10nGlobals('v2.14.6')).toBe(false);
|
||||
});
|
||||
|
||||
it('should be false when the Rancher version is missing or unknown', () => {
|
||||
expect(hostResolvesL10nGlobals('')).toBe(false);
|
||||
expect(hostResolvesL10nGlobals(undefined)).toBe(false);
|
||||
expect(hostResolvesL10nGlobals('dev')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('standaloneProductName', () => {
|
||||
it('should be Harvester when the server flavor is not prime', () => {
|
||||
setStandalonePrime(false);
|
||||
|
||||
expect(standaloneProductName()).toBe('Harvester');
|
||||
});
|
||||
|
||||
it('should be SUSE Virtualization when the server flavor is prime', () => {
|
||||
setStandalonePrime(true);
|
||||
|
||||
expect(standaloneProductName()).toBe('SUSE Virtualization');
|
||||
setStandalonePrime(false);
|
||||
});
|
||||
|
||||
it('should go back to Harvester when the server flavor changes from prime', () => {
|
||||
setStandalonePrime(true);
|
||||
setStandalonePrime(false);
|
||||
|
||||
expect(standaloneProductName()).toBe('Harvester');
|
||||
});
|
||||
});
|
||||
|
||||
describe('resolveL10nGlobals', () => {
|
||||
it('should replace tokens with their name when no value is given', () => {
|
||||
const translations = { support: { title: '[[Harvester]] Support' } };
|
||||
|
||||
resolveL10nGlobals(translations);
|
||||
|
||||
expect(translations).toStrictEqual({ support: { title: 'Harvester Support' } });
|
||||
});
|
||||
|
||||
it('should replace every token in a string with the given value', () => {
|
||||
const translations = { message: 'The [[Harvester]] UI only supports [[Harvester]] v1.3.0 and later' };
|
||||
|
||||
resolveL10nGlobals(translations, { Harvester: 'SUSE Virtualization' });
|
||||
|
||||
expect(translations.message).toBe('The SUSE Virtualization UI only supports SUSE Virtualization v1.3.0 and later');
|
||||
});
|
||||
|
||||
it('should keep an escaped token as a literal', () => {
|
||||
const translations = { message: 'Use \\[[Harvester]] in a string' };
|
||||
|
||||
resolveL10nGlobals(translations);
|
||||
|
||||
expect(translations.message).toBe('Use [[Harvester]] in a string');
|
||||
});
|
||||
|
||||
it('should leave strings without tokens and non-string values untouched', () => {
|
||||
const translations = {
|
||||
plain: 'harvester-seeder is an add-on',
|
||||
count: 3,
|
||||
nested: { link: '<a href="https://harvesterhci.io/">site</a>' },
|
||||
};
|
||||
|
||||
resolveL10nGlobals(translations);
|
||||
|
||||
expect(translations).toStrictEqual({
|
||||
plain: 'harvester-seeder is an add-on',
|
||||
count: 3,
|
||||
nested: { link: '<a href="https://harvesterhci.io/">site</a>' },
|
||||
});
|
||||
});
|
||||
|
||||
it('should leave no token in the extension translations', () => {
|
||||
const translations = load(fs.readFileSync(path.join(__dirname, '../../l10n/en-us.yaml'), 'utf8'));
|
||||
|
||||
expect(JSON.stringify(translations)).toContain('[[Harvester]]');
|
||||
|
||||
resolveL10nGlobals(translations);
|
||||
|
||||
expect(JSON.stringify(translations)).not.toContain('[[');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import { primeBrandUpdater } from '../prime-brand';
|
||||
|
||||
describe('primeBrandUpdater', () => {
|
||||
it('should switch the brand to suse on Prime', () => {
|
||||
const setting = { value: 'harvester' };
|
||||
|
||||
primeBrandUpdater()(setting, true);
|
||||
|
||||
expect(setting.value).toBe('suse');
|
||||
});
|
||||
|
||||
it('should keep the brand of the server when not on Prime', () => {
|
||||
const setting = { value: 'harvester' };
|
||||
|
||||
primeBrandUpdater()(setting, false);
|
||||
|
||||
expect(setting.value).toBe('harvester');
|
||||
});
|
||||
|
||||
it('should put the brand of the server back when the flavor stops being Prime', () => {
|
||||
const setting = { value: 'harvester' };
|
||||
const update = primeBrandUpdater();
|
||||
|
||||
update(setting, true);
|
||||
update(setting, false);
|
||||
|
||||
expect(setting.value).toBe('harvester');
|
||||
});
|
||||
|
||||
it('should switch the brand to suse again when the server sends its brand back on Prime', () => {
|
||||
const setting = { value: 'harvester' };
|
||||
const update = primeBrandUpdater();
|
||||
|
||||
update(setting, true);
|
||||
setting.value = 'harvester';
|
||||
update(setting, true);
|
||||
|
||||
expect(setting.value).toBe('suse');
|
||||
});
|
||||
|
||||
it('should keep an empty brand of the server when not on Prime', () => {
|
||||
const setting = { value: '' };
|
||||
const update = primeBrandUpdater();
|
||||
|
||||
update(setting, true);
|
||||
update(setting, false);
|
||||
|
||||
expect(setting.value).toBe('');
|
||||
});
|
||||
|
||||
it('should do nothing before the setting is loaded', () => {
|
||||
expect(() => primeBrandUpdater()(undefined, true)).not.toThrow();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { isValidCIDR } from '../regular';
|
||||
|
||||
describe('isValidCIDR', () => {
|
||||
it.each([
|
||||
'10.0.0.0/16',
|
||||
'192.168.1.0/24',
|
||||
'0.0.0.0/0',
|
||||
'255.255.255.255/32',
|
||||
'172.16.100.9/12',
|
||||
])('should accept the IPv4 CIDR %s', (cidr) => {
|
||||
expect(isValidCIDR(cidr)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['a short form', '10.1/16'],
|
||||
['a single number', '10/8'],
|
||||
['an integer address', '167772160/8'],
|
||||
['a hex address', '0x0a.0.0.0/8'],
|
||||
['an extra part', '10.0.0.0/24/1'],
|
||||
['an IPv6 range', 'fd00::/64'],
|
||||
['an IPv4-mapped IPv6 range', '::ffff:10.0.0.0/120'],
|
||||
['a prefix over 32', '10.0.0.0/33'],
|
||||
['an octet over 255', '10.0.0.256/24'],
|
||||
['zero-padded octets', '010.001.000.000/16'],
|
||||
['a zero-padded octet', '192.168.001.0/24'],
|
||||
['a zero-padded prefix', '10.0.0.0/08'],
|
||||
['no prefix', '10.0.0.0'],
|
||||
['an empty value', ''],
|
||||
])('should reject %s (%s)', (_, cidr) => {
|
||||
expect(isValidCIDR(cidr)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { reactive } from 'vue';
|
||||
import { sharedComputed } from '../shared-computed';
|
||||
|
||||
describe('sharedComputed', () => {
|
||||
it('should run the function once per source and key, not once per call', () => {
|
||||
const source = reactive([1, 2, 3]);
|
||||
const fn = jest.fn((list) => list.length);
|
||||
|
||||
expect(sharedComputed(source, 'length', fn)).toBe(3);
|
||||
expect(sharedComputed(source, 'length', fn)).toBe(3);
|
||||
expect(fn).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should run the function again after reactive data it read changed', () => {
|
||||
const source = reactive([1, 2, 3]);
|
||||
const fn = jest.fn((list) => list.length);
|
||||
|
||||
expect(sharedComputed(source, 'length', fn)).toBe(3);
|
||||
|
||||
source.push(4);
|
||||
|
||||
expect(sharedComputed(source, 'length', fn)).toBe(4);
|
||||
expect(fn).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('should keep the values of different keys and different sources apart', () => {
|
||||
const one = reactive([1]);
|
||||
const two = reactive([1, 2]);
|
||||
|
||||
expect(sharedComputed(one, 'length', (list) => list.length)).toBe(1);
|
||||
expect(sharedComputed(two, 'length', (list) => list.length)).toBe(2);
|
||||
expect(sharedComputed(one, 'first', (list) => list[0])).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,21 @@
|
||||
import Feature from '@shell/models/management.cattle.io.feature';
|
||||
import { MANAGEMENT } from '@shell/config/types';
|
||||
import { CONFIGURABLE_TABLES } from '@shell/store/features';
|
||||
import { tableViewsOffFeature } from '../table-views';
|
||||
|
||||
describe('tableViewsOffFeature', () => {
|
||||
it('should be the table views feature of the management store', () => {
|
||||
const feature = tableViewsOffFeature();
|
||||
|
||||
expect(feature.type).toBe(MANAGEMENT.FEATURE);
|
||||
expect(feature.id).toBe(CONFIGURABLE_TABLES);
|
||||
});
|
||||
|
||||
it('should be read as disabled by the shell', () => {
|
||||
const feature = new Feature(tableViewsOffFeature(), {
|
||||
getters: {}, rootGetters: {}, dispatch: jest.fn(), rootState: {}
|
||||
});
|
||||
|
||||
expect(feature.enabled).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { reactive } from 'vue';
|
||||
import { getLatestMigration } from '../vm';
|
||||
|
||||
const migration = (namespace, timestamp, vmiName = 'vm1') => ({
|
||||
metadata: { namespace, creationTimestamp: timestamp },
|
||||
spec: { vmiName },
|
||||
});
|
||||
|
||||
describe('getLatestMigration', () => {
|
||||
it('should return the newest migration of the VMI in its namespace, regardless of list order', () => {
|
||||
const newest = migration('ns1', '2026-01-03T00:00:00Z');
|
||||
const list = [
|
||||
migration('ns1', '2026-01-01T00:00:00Z'),
|
||||
newest,
|
||||
migration('ns2', '2026-01-09T00:00:00Z'),
|
||||
migration('ns1', '2026-02-01T00:00:00Z', 'vm2'),
|
||||
];
|
||||
|
||||
expect(getLatestMigration(list, 'ns1', 'vm1')).toBe(newest);
|
||||
});
|
||||
|
||||
it('should return the first one of several migrations with the same timestamp, as the lookup before the index did', () => {
|
||||
const first = { ...migration('ns1', '2026-01-03T00:00:00Z'), id: 'first' };
|
||||
const second = { ...migration('ns1', '2026-01-03T00:00:00Z'), id: 'second' };
|
||||
|
||||
expect(getLatestMigration([first, second], 'ns1', 'vm1')).toBe(first);
|
||||
});
|
||||
|
||||
it('should return undefined if there is no migration or no VMI name', () => {
|
||||
const list = [migration('ns1', '2026-01-01T00:00:00Z')];
|
||||
|
||||
expect(getLatestMigration(list, 'ns2', 'vm1')).toBeUndefined();
|
||||
expect(getLatestMigration(list, 'ns1', undefined)).toBeUndefined();
|
||||
expect(getLatestMigration([], 'ns1', 'vm1')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should follow changes of a reactive store list', () => {
|
||||
const list = reactive([]);
|
||||
const first = migration('ns1', '2026-01-01T00:00:00Z');
|
||||
|
||||
expect(getLatestMigration(list, 'ns1', 'vm1')).toBeUndefined();
|
||||
|
||||
list.push(first);
|
||||
expect(getLatestMigration(list, 'ns1', 'vm1')).toStrictEqual(first);
|
||||
|
||||
list.push(migration('ns1', '2026-01-02T00:00:00Z'));
|
||||
expect(getLatestMigration(list, 'ns1', 'vm1').metadata.creationTimestamp).toBe('2026-01-02T00:00:00Z');
|
||||
|
||||
list.splice(0, 2);
|
||||
expect(getLatestMigration(list, 'ns1', 'vm1')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { preventImplicitSubmit } from '../wizard';
|
||||
|
||||
function keydown(target) {
|
||||
return { target, preventDefault: jest.fn() };
|
||||
}
|
||||
|
||||
describe('preventImplicitSubmit', () => {
|
||||
it('should stop Enter in a text field from submitting the wizard', () => {
|
||||
const event = keydown(document.createElement('input'));
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should leave Enter in a dropdown alone, which uses it to pick an option', () => {
|
||||
const select = document.createElement('div');
|
||||
const input = document.createElement('input');
|
||||
|
||||
select.className = 'v-select';
|
||||
select.appendChild(input);
|
||||
|
||||
const event = keydown(input);
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(['textarea', 'button'])('should leave Enter on a %s alone', (tag) => {
|
||||
const event = keydown(document.createElement(tag));
|
||||
|
||||
preventImplicitSubmit(event);
|
||||
|
||||
expect(event.preventDefault).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -1,3 +1,5 @@
|
||||
import { FAVORITE_TYPES } from '@shell/store/prefs';
|
||||
|
||||
/**
|
||||
* Dynamically toggles SideNav entries based on the enabled status of a specific Addon.
|
||||
*
|
||||
@@ -26,10 +28,13 @@ export function registerAddonSideNav(store, productName, {
|
||||
|
||||
// Toggle the trigger a few times so an early kick (fired before the SideNav
|
||||
// has mounted on first login) is retried once the component is listening.
|
||||
// Use the prefs/load mutation (in-memory only)
|
||||
[0, 600, 1500].forEach((delay) => {
|
||||
setTimeout(() => {
|
||||
store.dispatch('type-map/addFavorite', TRIGGER);
|
||||
setTimeout(() => store.dispatch('type-map/removeFavorite', TRIGGER), 300);
|
||||
const base = (store.getters['prefs/get'](FAVORITE_TYPES) || []).filter((t) => t !== TRIGGER);
|
||||
|
||||
store.commit('prefs/load', { key: FAVORITE_TYPES, value: [...base, TRIGGER] });
|
||||
setTimeout(() => store.commit('prefs/load', { key: FAVORITE_TYPES, value: [...base] }), 300);
|
||||
}, delay);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -34,7 +34,7 @@ function getLatestCompatibleVersion(version) {
|
||||
return compatible[0] || getLatestVersion();
|
||||
}
|
||||
|
||||
export const featureEnabled = (featureKey, serverVersion) => {
|
||||
function resolveFeatureEnabled(featureKey, serverVersion) {
|
||||
const minSupportedVersion = '1.3.0';
|
||||
|
||||
const version = getVersion(serverVersion);
|
||||
@@ -59,4 +59,17 @@ export const featureEnabled = (featureKey, serverVersion) => {
|
||||
}
|
||||
|
||||
return releasedFeatures.includes(featureKey);
|
||||
}
|
||||
|
||||
// Cache the result, models ask for the same few flags for every row
|
||||
const _featureEnabledCache = new Map();
|
||||
|
||||
export const featureEnabled = (featureKey, serverVersion) => {
|
||||
const cacheKey = `${ featureKey }|${ serverVersion }`;
|
||||
|
||||
if (!_featureEnabledCache.has(cacheKey)) {
|
||||
_featureEnabledCache.set(cacheKey, resolveFeatureEnabled(featureKey, serverVersion));
|
||||
}
|
||||
|
||||
return _featureEnabledCache.get(cacheKey);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import semver from 'semver';
|
||||
|
||||
// Rancher 2.16 resolves `[[name]]` tokens in translations from values registered as 'l10n-global'
|
||||
export const L10N_GLOBALS_MIN_RANCHER_VERSION = '2.16.0';
|
||||
|
||||
// Name of the product name token, `[[Harvester]]`, and its value on Prime
|
||||
export const PRODUCT_NAME_GLOBAL = 'Harvester';
|
||||
export const PRIME_PRODUCT_NAME = 'SUSE Virtualization';
|
||||
|
||||
const TOKEN = /(\\?)\[\[([\w-]+)\]\]/g;
|
||||
|
||||
// Standalone has no Rancher Prime, the server-flavor setting decides instead
|
||||
let standalonePrime = false;
|
||||
|
||||
export function setStandalonePrime(isPrime) {
|
||||
standalonePrime = !!isPrime;
|
||||
}
|
||||
|
||||
export function standaloneProductName() {
|
||||
return standalonePrime ? PRIME_PRODUCT_NAME : PRODUCT_NAME_GLOBAL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the host Rancher resolves `[[name]]` tokens itself.
|
||||
* A missing or unknown version counts as an older host.
|
||||
*/
|
||||
export function hostResolvesL10nGlobals(version) {
|
||||
const v = semver.coerce(version);
|
||||
|
||||
return !!v && semver.gte(v, L10N_GLOBALS_MIN_RANCHER_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace `[[name]]` tokens in every string of `translations`, in place, the same way Rancher 2.16 does:
|
||||
* a known name gets its value, an unknown one falls back to the name and `\[[name]]` stays a literal `[[name]]`
|
||||
*/
|
||||
export function resolveL10nGlobals(translations, values = {}) {
|
||||
Object.keys(translations || {}).forEach((key) => {
|
||||
const value = translations[key];
|
||||
|
||||
if (typeof value === 'string') {
|
||||
translations[key] = value.replace(TOKEN, (_, escaped, name) => (escaped ? `[[${ name }]]` : (values[name] ?? name)));
|
||||
} else if (value && typeof value === 'object') {
|
||||
resolveL10nGlobals(value, values);
|
||||
}
|
||||
});
|
||||
|
||||
return translations;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { BRAND } from '@shell/config/types';
|
||||
|
||||
/**
|
||||
* Standalone Prime takes the SUSE theme of Rancher Prime: the `ui-brand` setting decides the stylesheet the shell
|
||||
* loads, and only the `suse` brand has one. Returns an updater that switches the copy of the setting in the store,
|
||||
* the server keeps its value, and puts the server's brand back when the flavor stops being Prime.
|
||||
*/
|
||||
export function primeBrandUpdater() {
|
||||
let serverBrand;
|
||||
|
||||
return (brandSetting, isPrime) => {
|
||||
if (!brandSetting) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (brandSetting.value !== BRAND.SUSE) {
|
||||
serverBrand = brandSetting.value;
|
||||
}
|
||||
|
||||
const brand = isPrime ? BRAND.SUSE : (serverBrand ?? brandSetting.value);
|
||||
|
||||
if (brandSetting.value !== brand) {
|
||||
brandSetting.value = brand;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,4 +1,13 @@
|
||||
|
||||
/**
|
||||
* IPv4 CIDR such as 10.0.0.0/16. Unlike the shell's isValidCIDR since 3.0.14, it rejects the short forms
|
||||
* (10.1/16), extra parts (10.0.0.0/24/1), zero-padded octets (010.0.0.0/8) and IPv6, which the network settings
|
||||
* don't support
|
||||
*/
|
||||
export function isValidCIDR(cidr) {
|
||||
return /^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\/(3[0-2]|[12]?[0-9])$/.test(cidr || '');
|
||||
}
|
||||
|
||||
export function isValidMac(value) {
|
||||
return /^[A-Fa-f0-9]{2}(-[A-Fa-f0-9]{2}){5}$|^[A-Fa-f0-9]{2}(:[A-Fa-f0-9]{2}){5}$/.test(value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { computed } from 'vue';
|
||||
|
||||
// Caches a value that all rows derive from the same shared store object (e.g. a lookup index of a whole list).
|
||||
// The WeakMap is keyed by that object, so the value is dropped together with it. The value is a `computed`, so it is
|
||||
// derived again after the reactive data it read changed.
|
||||
const _computedsBySource = new WeakMap();
|
||||
|
||||
/**
|
||||
* Runs `fn(source)` once per source object instead of once per call, and again when its reactive data changed.
|
||||
* `key` tells apart several shared computeds of the same source. For a list, `source` must be the store list, not a copy.
|
||||
*/
|
||||
export function sharedComputed(source, key, fn) {
|
||||
let perSource = _computedsBySource.get(source);
|
||||
|
||||
if (!perSource) {
|
||||
perSource = new Map();
|
||||
_computedsBySource.set(source, perSource);
|
||||
}
|
||||
|
||||
if (!perSource.has(key)) {
|
||||
perSource.set(key, computed(() => fn(source)));
|
||||
}
|
||||
|
||||
return perSource.get(key).value;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user