feat: SB Enhancements (NS selection and timeout) (#345)

* feat: add namespace field
* feat: add optional inputs
* feat: refine code
* feat: add feature flag
* refactor: fix lint error
* feat: filter default namespaces
* refactor: hide tips with feature flag
* refactor: use UnitInput
* feat: load default value from settings
* refactor: fix API url
* refactor: no available namespaces
* chore: update subject-case rule
---------
Signed-off-by: Yi-Ya Chen <yiya.chen@suse.com>
This commit is contained in:
Yiya Chen 2025-07-01 09:38:22 +08:00 committed by GitHub
parent fcef0391bb
commit be421054d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 329 additions and 118 deletions

View File

@ -24,7 +24,7 @@ module.exports = {
], ],
'type-case': [2, 'always', 'lower-case'], 'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'], 'type-empty': [2, 'never'],
'subject-case': [2, 'always', 'lower-case'], 'subject-case': [0, 'never'],
'subject-empty': [2, 'never'], 'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'], 'subject-full-stop': [2, 'never', '.'],
'subject-max-length': [2, 'always', 72], 'subject-max-length': [2, 'always', 72],

View File

@ -3,6 +3,9 @@ import { NAMESPACE } from '@shell/config/types';
import CreateEditView from '@shell/mixins/create-edit-view'; import CreateEditView from '@shell/mixins/create-edit-view';
import LabeledSelect from '@shell/components/form/LabeledSelect'; import LabeledSelect from '@shell/components/form/LabeledSelect';
const SELECT_ALL = 'select_all';
const UNSELECT_ALL = 'unselect_all';
export default { export default {
name: 'HarvesterBundleNamespaces', name: 'HarvesterBundleNamespaces',
@ -11,47 +14,76 @@ export default {
mixins: [CreateEditView], mixins: [CreateEditView],
async fetch() { async fetch() {
this.loading = true;
await this.$store.dispatch('harvester/findAll', { type: NAMESPACE }); await this.$store.dispatch('harvester/findAll', { type: NAMESPACE });
try {
const url = this.$store.getters['harvester-common/getHarvesterClusterUrl']('v1/harvester/namespaces?link=supportbundle');
const response = await this.$store.dispatch('harvester/request', { url });
this.defaultNamespaces = response.data || [];
} catch (error) {
this.defaultNamespaces = [];
} finally {
this.loading = false;
}
}, },
data() { data() {
let namespaces = [];
const namespacesStr = this.value?.value || this.value?.default || ''; const namespacesStr = this.value?.value || this.value?.default || '';
const namespaces = namespacesStr ? namespacesStr.split(',') : [];
if (namespacesStr) { return {
namespaces = namespacesStr.split(','); namespaces,
} defaultNamespaces: [],
loading: true
return { namespaces }; };
}, },
computed: { computed: {
allNamespaces() {
return this.$store.getters['harvester/all'](NAMESPACE).map((ns) => ns.id);
},
filteredNamespaces() {
const defaultIds = this.defaultNamespaces.map((ns) => ns.id);
return this.allNamespaces.filter((ns) => !defaultIds.includes(ns));
},
namespaceOptions() { namespaceOptions() {
return this.$store.getters['harvester/all'](NAMESPACE).map((N) => { if (this.availableNamespaces.length === 0) return [];
return {
label: N.id, const allSelected =
value: N.id this.namespaces.length === this.filteredNamespaces.length &&
}; this.filteredNamespaces.every((ns) => this.namespaces.includes(ns));
});
const controlOption = allSelected ? { label: this.t('harvester.modal.bundle.namespaces.unselectAll'), value: UNSELECT_ALL } : { label: this.t('harvester.modal.bundle.namespaces.selectAll'), value: SELECT_ALL };
return [controlOption, ...this.filteredNamespaces];
} }
}, },
methods: { methods: {
update() { update(selected) {
const namespaceStr = this.namespaces.join(','); if (selected.includes(SELECT_ALL)) {
this.namespaces = [...this.filteredNamespaces];
} else if (selected.includes(UNSELECT_ALL)) {
this.namespaces = [];
} else {
this.namespaces = selected.filter((val) => val !== SELECT_ALL && val !== UNSELECT_ALL);
}
this.value['value'] = namespaceStr; this.value.value = this.namespaces.join(',');
} }
}, },
watch: { watch: {
'value.value': { 'value.value'(newVal) {
handler(neu) { const raw = newVal || this.value.default || '';
if (neu === this.value.default || !neu) {
this.namespaces = []; this.namespaces = raw ? raw.split(',') : [];
}
},
deep: true
} }
} }
}; };
@ -62,6 +94,7 @@ export default {
<div class="col span-12"> <div class="col span-12">
<LabeledSelect <LabeledSelect
v-model:value="namespaces" v-model:value="namespaces"
:loading="loading"
:multiple="true" :multiple="true"
label-key="nameNsDescription.namespace.label" label-key="nameNsDescription.namespace.label"
:mode="mode" :mode="mode"

View File

@ -2,7 +2,8 @@
export const DOC = { export const DOC = {
CONSOLE_URL: `/host/#remote-console`, CONSOLE_URL: `/host/#remote-console`,
RANCHER_INTEGRATION_URL: `/rancher/rancher-integration`, RANCHER_INTEGRATION_URL: `/rancher/rancher-integration`,
STORAGE_NETWORK_EXAMPLE: `/advanced/storagenetwork#configuration-example`,
KSMTUNED_MODE: `/host/#ksmtuned-mode`, KSMTUNED_MODE: `/host/#ksmtuned-mode`,
UPGRADE_URL: `/upgrade/index` UPGRADE_URL: `/upgrade/index`,
STORAGE_NETWORK_EXAMPLE: `/advanced/storagenetwork#configuration-example`,
SUPPORT_BUNDLE_NAMESPACES: `/advanced/index/#support-bundle-namespaces`,
}; };

View File

@ -38,7 +38,8 @@ const FEATURE_FLAGS = {
], ],
'v1.5.1': [], 'v1.5.1': [],
'v1.6.0': [ 'v1.6.0': [
'vmMachineTypes' 'vmMachineTypes',
'customSupportBundle'
] ]
}; };

View File

@ -1,4 +1,5 @@
<script> <script>
import { NAMESPACE } from '@shell/config/types';
import { randomStr } from '@shell/utils/string'; import { randomStr } from '@shell/utils/string';
import { exceptionToErrorsArray, stringify } from '@shell/utils/error'; import { exceptionToErrorsArray, stringify } from '@shell/utils/error';
import { LabeledInput } from '@components/Form/LabeledInput'; import { LabeledInput } from '@components/Form/LabeledInput';
@ -6,7 +7,15 @@ import AsyncButton from '@shell/components/AsyncButton';
import GraphCircle from '@shell/components/graph/Circle'; import GraphCircle from '@shell/components/graph/Circle';
import { Banner } from '@components/Banner'; import { Banner } from '@components/Banner';
import AppModal from '@shell/components/AppModal'; import AppModal from '@shell/components/AppModal';
import LabeledSelect from '@shell/components/form/LabeledSelect';
import UnitInput from '@shell/components/form/UnitInput';
import { HCI } from '../types'; import { HCI } from '../types';
import { HCI_SETTING } from '../config/settings';
import { DOC } from '../config/doc-links';
import { docLink } from '../utils/feature-flags';
const SELECT_ALL = 'select_all';
const UNSELECT_ALL = 'unselect_all';
export default { export default {
name: 'SupportBundle', name: 'SupportBundle',
@ -17,14 +26,36 @@ export default {
AsyncButton, AsyncButton,
Banner, Banner,
AppModal, AppModal,
LabeledSelect,
UnitInput
},
async fetch() {
await this.$store.dispatch('harvester/findAll', { type: NAMESPACE });
try {
const url = this.$store.getters['harvester-common/getHarvesterClusterUrl']('v1/harvester/namespaces?link=supportbundle');
const response = await this.$store.dispatch('harvester/request', { url });
this.defaultNamespaces = response.data || [];
} catch (error) {
this.defaultNamespaces = [];
}
}, },
data() { data() {
return { return {
isOpen: false,
errors: [],
version: '',
clusterName: '',
url: '', url: '',
description: '', description: '',
errors: [], namespaces: [],
isOpen: false, defaultNamespaces: [],
timeout: '',
expiration: '',
nodeTimeout: '',
}; };
}, },
@ -39,23 +70,51 @@ export default {
percentage() { percentage() {
return this.$store.getters['harvester-common/getBundlePercentage']; return this.$store.getters['harvester-common/getBundlePercentage'];
} },
availableNamespaces() {
const allNamespaces = this.$store.getters['harvester/all'](NAMESPACE).map((ns) => ns.id);
const defaultNamespacesIds = this.defaultNamespaces.map((ns) => ns.id);
return allNamespaces.filter((ns) => !defaultNamespacesIds.includes(ns) || this.namespaces.includes(ns));
},
namespaceOptions() {
if (this.availableNamespaces.length === 0) return [];
const allSelected = this.namespaces.length === this.availableNamespaces.length &&
this.availableNamespaces.every((ns) => this.namespaces.includes(ns));
const controlOption = allSelected ? { label: this.t('harvester.modal.bundle.namespaces.unselectAll'), value: UNSELECT_ALL } : { label: this.t('harvester.modal.bundle.namespaces.selectAll'), value: SELECT_ALL };
return [controlOption, ...this.availableNamespaces];
},
docLink() {
const version = this.$store.getters['harvester-common/getServerVersion']();
return docLink(DOC.SUPPORT_BUNDLE_NAMESPACES, version);
},
customSupportBundleFeatureEnabled() {
return this.$store.getters['harvester-common/getFeatureEnabled']('customSupportBundle');
},
}, },
watch: { watch: {
isShowBundleModal: { isShowBundleModal: {
immediate: true,
handler(show) { handler(show) {
if (show) { this.isOpen = show;
this.$nextTick(() => {
this.isOpen = true;
});
} else {
this.isOpen = false;
this.url = '';
this.description = '';
} }
}, },
immediate: true
isOpen(newVal) {
if (newVal) {
this.loadDefaultSettings();
} else {
this.resetForm();
}
}, },
}, },
@ -65,33 +124,93 @@ export default {
close() { close() {
this.isOpen = false; this.isOpen = false;
this.$store.commit('harvester-common/toggleBundleModal', false); this.$store.commit('harvester-common/toggleBundleModal', false);
this.backUpName = ''; },
loadDefaultSettings() {
const cluster = this.$store.getters['currentCluster'];
const versionSetting = this.$store.getters['harvester/byId'](HCI.SETTING, HCI_SETTING.SERVER_VERSION);
const namespacesSetting = this.$store.getters['harvester/byId'](HCI.SETTING, HCI_SETTING.SUPPORT_BUNDLE_NAMESPACES);
const timeoutSetting = this.$store.getters['harvester/byId'](HCI.SETTING, HCI_SETTING.SUPPORT_BUNDLE_TIMEOUT);
const expirationSetting = this.$store.getters['harvester/byId'](HCI.SETTING, HCI_SETTING.SUPPORT_BUNDLE_EXPIRATION);
const nodeTimeoutSetting = this.$store.getters['harvester/byId'](HCI.SETTING, HCI_SETTING.SUPPORT_BUNDLE_NODE_COLLECTION_TIMEOUT);
this.version = versionSetting?.currentVersion || '';
this.clusterName = cluster?.id || '';
this.namespaces = (namespacesSetting?.value ?? namespacesSetting?.default ?? '').split(',').map((ns) => ns.trim()).filter((ns) => ns);
this.timeout = timeoutSetting?.value ?? timeoutSetting?.default ?? '';
this.expiration = expirationSetting?.value ?? expirationSetting?.default ?? '';
this.nodeTimeout = nodeTimeoutSetting?.value ?? nodeTimeoutSetting?.default ?? '';
this.url = '';
this.description = '';
this.errors = [];
},
resetForm() {
this.url = '';
this.description = '';
this.namespaces = [];
this.timeout = '';
this.expiration = '';
this.nodeTimeout = '';
this.errors = [];
},
updateNamespaces(selected) {
if (selected.includes(SELECT_ALL)) {
this.namespaces = [...this.availableNamespaces];
} else if (selected.includes(UNSELECT_ALL)) {
this.namespaces = [];
} else {
this.namespaces = selected.filter((val) => val !== SELECT_ALL && val !== UNSELECT_ALL);
}
},
updateNumberValue(field, value) {
if (value === '' || value === null || isNaN(value)) {
this[field] = '';
return;
}
const num = Number(value);
const isValid = Number.isInteger(num) && num >= 0;
this[field] = isValid ? String(num) : '';
},
onKeyDown(e) {
if (['e', 'E', '+', '-', '.'].includes(e.key)) {
e.preventDefault();
}
}, },
async save(buttonCb) { async save(buttonCb) {
this.errors = []; this.errors = [];
const name = `bundle-${ randomStr(5).toLowerCase() }`; const name = `bundle-${ this.clusterName }-${ this.version }-${ randomStr(5).toLowerCase() }`;
const namespace = 'harvester-system'; const namespace = 'harvester-system';
const spec = {
description: this.description.trim(),
...(this.url.trim() && { issueURL: this.url.trim() }),
...(this.namespaces.length > 0 && { extraCollectionNamespaces: this.namespaces }),
...(this.timeout !== '' && { timeout: Number(this.timeout) }),
...(this.expiration !== '' && { expiration: Number(this.expiration) }),
...(this.nodeTimeout !== '' && { nodeTimeout: Number(this.nodeTimeout) }),
};
const bundleCrd = { const bundleCrd = {
apiVersion: 'harvesterhci.io/v1beta1', apiVersion: 'harvesterhci.io/v1beta1',
type: HCI.SUPPORT_BUNDLE, type: HCI.SUPPORT_BUNDLE,
kind: 'SupportBundle', kind: 'SupportBundle',
metadata: { metadata: { name, namespace },
name, spec,
namespace
},
spec: {
issueURL: this.url,
description: this.description
}
}; };
try {
const inStore = this.$store.getters['currentProduct'].inStore; const inStore = this.$store.getters['currentProduct'].inStore;
const bundleValue = await this.$store.dispatch(`${ inStore }/create`, bundleCrd); const bundleValue = await this.$store.dispatch(`${ inStore }/create`, bundleCrd);
try {
await bundleValue.save(); await bundleValue.save();
this.$store.commit('harvester-common/setLatestBundleId', `${ namespace }/${ name }`, { root: true }); this.$store.commit('harvester-common/setLatestBundleId', `${ namespace }/${ name }`, { root: true });
@ -118,44 +237,86 @@ export default {
@close="close" @close="close"
> >
<div class="p-20"> <div class="p-20">
<h2> <h2>{{ t('harvester.modal.bundle.title') }}</h2>
{{ t('harvester.modal.bundle.title') }} <div class="content">
</h2>
<div <div
v-if="!bundlePending" v-if="bundlePending"
class="content" class="circle mb-20"
> >
<LabeledInput
v-model:value="url"
:label="t('harvester.modal.bundle.url')"
class="mb-20"
/>
<LabeledInput
v-model:value="description"
:label="t('harvester.modal.bundle.description')"
type="multiline"
:min-height="120"
required
/>
</div>
<div
v-else
class="content"
>
<div class="circle">
<GraphCircle <GraphCircle
primary-stroke-color="green" primary-stroke-color="green"
secondary-stroke-color="white" secondary-stroke-color="lightgrey"
:stroke-width="6" :stroke-width="6"
:percentage="percentage" :percentage="percentage"
:show-text="true" :show-text="true"
/> />
</div> </div>
</div> <template v-else>
<p
v-if="customSupportBundleFeatureEnabled"
v-clean-html="t('harvester.modal.bundle.tip', { doc: docLink }, true)"
class="mb-20"
/>
<LabeledInput
v-model:value="url"
:label="t('harvester.modal.bundle.url')"
class="mb-10"
/>
<LabeledInput
v-model:value="description"
required
:label="t('harvester.modal.bundle.description')"
type="multiline"
:min-height="80"
class="mb-10"
/>
<template v-if="customSupportBundleFeatureEnabled">
<LabeledSelect
v-model:value="namespaces"
:label="t('harvester.modal.bundle.namespaces.label')"
:clearable="true"
:multiple="true"
:options="namespaceOptions"
class="mb-10 label-select"
:tooltip="t('harvester.modal.bundle.namespaces.tooltip', _, true)"
@update:value="updateNamespaces"
/>
<UnitInput
v-model:value="timeout"
:label="t('harvester.modal.bundle.timeout.label')"
class="mb-10"
type="number"
:min="0"
:tooltip="t('harvester.modal.bundle.timeout.tooltip', _, true)"
:suffix="timeout > 1 ? 'Minutes' : 'Minute'"
@keydown="onKeyDown"
@update:value="val => updateNumberValue('timeout', val)"
/>
<UnitInput
v-model:value="expiration"
:label="t('harvester.modal.bundle.expiration.label')"
class="mb-10"
type="number"
:min="0"
:tooltip="t('harvester.modal.bundle.expiration.tooltip', _, true)"
:suffix="expiration > 1 ? 'Minutes' : 'Minute'"
@keydown="onKeyDown"
@update:value="val => updateNumberValue('expiration', val)"
/>
<UnitInput
v-model:value="nodeTimeout"
:label="t('harvester.modal.bundle.nodeTimeout.label')"
class="mb-10"
type="number"
:min="0"
:tooltip="t('harvester.modal.bundle.nodeTimeout.tooltip', _, true)"
:suffix="nodeTimeout > 1 ? 'Minutes' : 'Minute'"
@keydown="onKeyDown"
@update:value="val => updateNumberValue('nodeTimeout', val)"
/>
</template>
</template>
<div <div
v-for="(err, idx) in errors" v-for="(err, idx) in errors"
:key="idx" :key="idx"
@ -165,7 +326,6 @@ export default {
:label="stringify(err)" :label="stringify(err)"
/> />
</div> </div>
<div class="footer mt-20"> <div class="footer mt-20">
<button <button
class="btn btn-sm role-secondary mr-10" class="btn btn-sm role-secondary mr-10"
@ -173,7 +333,6 @@ export default {
> >
{{ t('generic.close') }} {{ t('generic.close') }}
</button> </button>
<AsyncButton <AsyncButton
type="submit" type="submit"
mode="generate" mode="generate"
@ -183,6 +342,7 @@ export default {
/> />
</div> </div>
</div> </div>
</div>
</app-modal> </app-modal>
</div> </div>
</template> </template>
@ -194,6 +354,10 @@ export default {
max-height: 100vh; max-height: 100vh;
} }
.labeled-select.taggable ::v-deep(.vs__selected-options .vs__selected.vs__selected > button) {
margin: 0 7px;
}
.bundle { .bundle {
cursor: pointer; cursor: pointer;
color: var(--primary); color: var(--primary);
@ -204,10 +368,8 @@ export default {
} }
.content { .content {
height: 218px;
.circle { .circle {
padding-top: 20px; padding: 10px 0;
height: 160px; height: 160px;
} }
} }

View File

@ -136,10 +136,24 @@ harvester:
delete: Delete delete: Delete
bundle: bundle:
title: Generate a Support Bundle title: Generate a Support Bundle
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 url: Issue URL
description: Description description: Description
requiredDesc: Description is required! namespaces:
titleDescription: Collect system-related logs in Harvester to help with troubleshooting and support. label: Namespaces
tooltip: Select additional namespaces to include in the support bundle.<br/>See docs support-bundle-namespaces for detail.
selectAll: 'Select All'
unselectAll: 'Unselect All'
timeout:
label: Timeout
tooltip: Minutes allows for completion of the support bundle generation process.<br/>See docs support-bundle-timeout for detail.
expiration:
label: Expiration
tooltip: Minutes before deleting packaged but not downloaded support bundle.<br/>See docs support-bundle-expiration for detail.
nodeTimeout:
label: Node Collection Timeout
tooltip: Minutes allowed for collecting logs/configurations on nodes.<br/>See docs support-bundle-node-collection-timeout for detail.
hotplug: hotplug:
success: 'Volume { diskName } is mounted to the virtual machine { vm }.' success: 'Volume { diskName } is mounted to the virtual machine { vm }.'
title: Add Volume title: Add Volume
@ -1597,7 +1611,7 @@ advancedSettings:
'harv-vm-force-reset-policy': Configuration for the force-reset action when a virtual machine is stuck on a node that is down. 'harv-vm-force-reset-policy': Configuration for the force-reset action when a virtual machine is stuck on a node that is down.
'harv-ssl-parameters': Custom SSL Parameters for TLS validation. 'harv-ssl-parameters': Custom SSL Parameters for TLS validation.
'harv-storage-network': 'Longhorn storage-network setting.' 'harv-storage-network': 'Longhorn storage-network setting.'
'harv-support-bundle-namespaces': Specify resources in other namespaces to be collected by the support package. '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-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.