mergify[bot] d3b77e2e41
feat: forklift UI (#891) (#988)
* feat: forklift poc first commit



* feat: add migration and plan detail pages with progress tracking



* feat(forklift): UI based on the FIGMA



* feat(forklift): Fixed config based on new figma changes



* feat(forklift): New changes added based on new figma



* feat(forklift): Add the succeded state



* Merge the new APIs



* feat(forklift): Applied fix to select the proper data on network. Added condition to show critical



* feat(forklift): Added icons, critical state, fix grids, action button



* feat(forklift): Change to use the proper provider instead of a hardcoded



* feat(forklift): Added pagination UI



* feat(forklift): FIxed the routing for the extension



* feat(forklift): route and router doesnt work properly on extensions



* feat(forklift): fixed to fix the icon on extension



* feat(forklift): Added overflow hidden to mapping target list



* feat(forklift): Added better handling on the saving and testing



* feat(forklift): Remove test flags



* feat(forklift): Changed based on review



* feat(forklift): fixed title and button



* feat(forklift): Design changes



* feat(forklift): Changed to Wizard



* feat(forklift): added the provider wizard



* feat(forklift): Fixed some UI changes



* feat(forklift): Removed wrong configs used for testing



* feat(forklift): update size



* feat(forklift): small fixes



* feat(forklift): small fixes after Copilot



* feat(forklift): small fixes after Copilot



* feat(forklift): reverted settings.json changes



* feat(forklift): small fixes after Copilot



* feat(forklift): Fix the way it is registered



* feat(forklift): Fixed the type for VMware



* feat(forklift): small changes before rebase



* feat: Added new API for the vms



* feat: Fix some labels



* feat: Added some final fixes to structure



* feat: added loading to provider steps



* feat: added comments from copilot review



---------


(cherry picked from commit 560643d299216e679942d05803af9d1ce0f74f6a)

Signed-off-by: Marcelo Fukumoto <marcelo.fukumoto@suse.com>
Co-authored-by: marcelofukumoto <marceloyfukumoto@gmail.com>
2026-07-13 17:46:33 +08:00

81 lines
2.3 KiB
JavaScript

// Shared helpers for the Forklift VM-migration feature.
// Keep the map-spec builders here so the wizard step and the review step
// (and any future edit flow) stay in sync instead of drifting apart.
export const FORKLIFT_API_VERSION = 'forklift.konveyor.io/v1beta1';
/**
* Decode a base64 value stored in a k8s Secret, tolerating malformed input.
*/
export function decodeSecretValue(val) {
try {
return atob(val || '');
} catch (e) {
return '';
}
}
/**
* Bytes → whole GiB (rounded). Returns 0 for falsy input.
*/
export function bytesToGB(bytes) {
return Math.round((bytes || 0) / (1024 * 1024 * 1024));
}
/**
* MiB → whole GiB (rounded). Returns 0 for falsy input.
*/
export function mbToGB(mb) {
return Math.round((mb || 0) / 1024);
}
/**
* Build the `spec.map` entries for a Forklift NetworkMap from wizard entries.
* Entries without a chosen target are dropped so we never emit an invalid
* multus destination with an empty name.
*
* @param {Array} entries network mapping entries ({ name, id, target })
* @param {string} defaultNamespace namespace to use when the target has no `ns/` prefix
*/
export function buildNetworkMapEntries(entries = [], defaultNamespace) {
return entries
.filter((entry) => !!entry.target)
.map((entry) => {
const source = { name: entry.name, id: entry.id };
if (entry.target === 'pod') {
return { source, destination: { type: 'pod' } };
}
if (entry.target === 'ignored') {
return { source, destination: { type: 'ignored' } };
}
const parts = entry.target.split('/');
const name = parts.length > 1 ? parts[1] : parts[0];
const namespace = parts.length > 1 ? parts[0] : defaultNamespace;
return {
source,
destination: {
type: 'multus', name, namespace
},
};
});
}
/**
* Build the `spec.map` entries for a Forklift StorageMap from wizard entries.
* Entries without a chosen target are dropped.
*
* @param {Array} entries storage mapping entries ({ name, id, target })
*/
export function buildStorageMapEntries(entries = []) {
return entries
.filter((entry) => !!entry.target)
.map((entry) => ({
source: { name: entry.name, id: entry.id },
destination: { storageClass: entry.target },
}));
}