@@ -11,9 +11,9 @@ import {
1111import type { CustomScript } from './types' ;
1212
1313/**
14- * Builds a ConfigMap data key from a script definition .
15- * Format: `{ order}_{os}_{type}_{name}.{ext}`
16- * Example: `10_linux_firstboot_setup_network.sh`
14+ * Builds a ConfigMap data key matching the backend regex patterns in customize.go .
15+ * Order is zero-padded so lexicographic sorting matches numeric order (e.g. `02_` before `10_`).
16+ * @see https://github.com/kubev2v/forklift/blob/main/pkg/virt-v2v/customize/customize.go
1717 */
1818export const buildConfigMapKey = ( script : CustomScript ) : string => {
1919 const paddedOrder = String ( script . order ) . padStart ( 2 , '0' ) ;
@@ -23,19 +23,13 @@ export const buildConfigMapKey = (script: CustomScript): string => {
2323 return `${ paddedOrder } _${ osPrefix } _${ script . scriptType } _${ script . name } .${ ext } ` ;
2424} ;
2525
26- /**
27- * Converts an array of scripts to ConfigMap data entries.
28- */
2926export const scriptsToConfigMapData = ( scripts : CustomScript [ ] ) : Record < string , string > => {
3027 return scripts . reduce < Record < string , string > > ( ( data , script ) => {
3128 data [ buildConfigMapKey ( script ) ] = script . content ;
3229 return data ;
3330 } , { } ) ;
3431} ;
3532
36- /**
37- * Calculates the next order number for a new script entry.
38- */
3933export const getNextOrder = ( scripts : CustomScript [ ] ) : number => {
4034 if ( isEmpty ( scripts ) ) {
4135 return ORDER_INCREMENT ;
@@ -45,10 +39,6 @@ export const getNextOrder = (scripts: CustomScript[]): number => {
4539 return maxOrder + ORDER_INCREMENT ;
4640} ;
4741
48- /**
49- * Validates a script name for use in ConfigMap keys.
50- * Must be lowercase alphanumeric with hyphens and underscores, starting with alphanumeric.
51- */
5242export const validateScriptName = ( value : string ) : string | undefined => {
5343 if ( ! value ?. trim ( ) ) {
5444 return t ( 'Script name is required.' ) ;
@@ -63,9 +53,6 @@ export const validateScriptName = (value: string): string | undefined => {
6353 return undefined ;
6454} ;
6555
66- /**
67- * Checks if a ConfigMap contains at least one key matching the customization script naming pattern.
68- */
6956export const isScriptConfigMap = ( data : Record < string , string > | undefined ) : boolean => {
7057 if ( ! data ) {
7158 return false ;
0 commit comments