@@ -449,11 +449,71 @@ func GenerateCreateConditionFunc[Obj client.Object](rr *ReconcileResult[Obj]) fu
449449 }
450450 return func (conType string , status metav1.ConditionStatus , reason , message string ) {
451451 rr .Conditions = append (rr .Conditions , metav1.Condition {
452- Type : conType ,
452+ Type : ReplaceIllegalCharsInConditionType ( conType ) ,
453453 Status : status ,
454454 ObservedGeneration : gen ,
455- Reason : reason ,
455+ Reason : ReplaceIllegalCharsInConditionReason ( reason ) ,
456456 Message : message ,
457457 })
458458 }
459459}
460+
461+ // ReplaceIllegalCharsInConditionType replaces all characters in the given string that are not allowed in condition types with underscores.
462+ func ReplaceIllegalCharsInConditionType (s string ) string {
463+ if s == "" {
464+ return s
465+ }
466+
467+ result := make ([]rune , 0 , len (s ))
468+ for _ , r := range s {
469+ // Valid characters for condition types are:
470+ // - lowercase letters (a-z)
471+ // - uppercase letters (A-Z)
472+ // - digits (0-9)
473+ // - underscore (_)
474+ // - hyphen (-)
475+ // - dot (.)
476+ // All other characters are replaced with underscore
477+ if (r >= 'a' && r <= 'z' ) ||
478+ (r >= 'A' && r <= 'Z' ) ||
479+ (r >= '0' && r <= '9' ) ||
480+ r == '_' ||
481+ r == '-' ||
482+ r == '.' {
483+ result = append (result , r )
484+ } else {
485+ result = append (result , '_' )
486+ }
487+ }
488+ return string (result )
489+ }
490+
491+ // ReplaceIllegalCharsInConditionReason replaces all characters in the given string that are not allowed in condition reasons with underscores.
492+ func ReplaceIllegalCharsInConditionReason (s string ) string {
493+ if s == "" {
494+ return s
495+ }
496+
497+ result := make ([]rune , 0 , len (s ))
498+ for _ , r := range s {
499+ // Valid characters for condition types are:
500+ // - lowercase letters (a-z)
501+ // - uppercase letters (A-Z)
502+ // - digits (0-9)
503+ // - underscore (_)
504+ // - colon (:)
505+ //- comma (,)
506+ // All other characters are replaced with underscore
507+ if (r >= 'a' && r <= 'z' ) ||
508+ (r >= 'A' && r <= 'Z' ) ||
509+ (r >= '0' && r <= '9' ) ||
510+ r == '_' ||
511+ r == ':' ||
512+ r == ',' {
513+ result = append (result , r )
514+ } else {
515+ result = append (result , '_' )
516+ }
517+ }
518+ return string (result )
519+ }
0 commit comments