@@ -456,24 +456,35 @@ func (r *backupPolicyAndScheduleBuilder) resolveBackupMethodEnv(compSpec *appsv1
456456 continue
457457 }
458458 if v .ValueFrom != nil {
459- for _ , versionMapping := range v .ValueFrom .VersionMapping {
460- if r .matchMappingName (versionMapping .ServiceVersions , compSpec .ServiceVersion ) {
461- env = append (env , corev1.EnvVar {Name : v .Name , Value : versionMapping .MappedValue })
462- break
463- }
459+ mappedValue := findBestMatchingValue (v .ValueFrom .VersionMapping , compSpec .ServiceVersion )
460+ if mappedValue != "" {
461+ env = append (env , corev1.EnvVar {Name : v .Name , Value : mappedValue })
464462 }
465463 }
466464 }
467465 return env
468466}
469467
470- func (r * backupPolicyAndScheduleBuilder ) matchMappingName (names []string , target string ) bool {
471- for _ , name := range names {
472- if component .PrefixOrRegexMatched (target , name ) {
473- return true
468+ // findBestMatchingValue finds the best matching value for the given service version.
469+ // It prefers exact matches first, then falls back to prefix/regex matches.
470+ func findBestMatchingValue (versionMappings []dpv1alpha1.VersionMapping , serviceVersion string ) string {
471+ // First pass: look for exact match
472+ for _ , versionMapping := range versionMappings {
473+ for _ , v := range versionMapping .ServiceVersions {
474+ if v == serviceVersion {
475+ return versionMapping .MappedValue
476+ }
477+ }
478+ }
479+ // Second pass: look for prefix/regex match
480+ for _ , versionMapping := range versionMappings {
481+ for _ , v := range versionMapping .ServiceVersions {
482+ if component .PrefixOrRegexMatched (serviceVersion , v ) {
483+ return versionMapping .MappedValue
484+ }
474485 }
475486 }
476- return false
487+ return ""
477488}
478489
479490func (r * backupPolicyAndScheduleBuilder ) buildBackupTargets (targets []dpv1alpha1.BackupTarget ) ([]dpv1alpha1.BackupTarget , error ) {
0 commit comments