@@ -2,9 +2,6 @@ package resources
22
33import (
44 "context"
5- "crypto/rand"
6- "fmt"
7- "math/big"
85 "strings"
96 "time"
107
@@ -127,14 +124,14 @@ func (m *manager) generateRemediationCR(name string, healthCheckOwnerRef *metav1
127124 // can't go wrong, we already checked for correct spec
128125 templateSpec , _ , _ := unstructured .NestedMap (template .Object , "spec" , "template" , "spec" )
129126 unstructured .SetNestedField (remediationCR .Object , templateSpec , "spec" )
130- crName := name
127+
131128 if annotationutils .HasMultipleTemplatesAnnotation (template ) {
132- //first part would be the node name and second part is a unique suffix seperated by '-'
133- crName = generateUniqueRemediationName (name )
129+ remediationCR .SetGenerateName (name )
134130 remediationCR .SetAnnotations (map [string ]string {annotationutils .NodeNameAnnotation : name , annotationutils .TemplateNameAnnotation : template .GetName ()})
131+ } else {
132+ remediationCR .SetName (name )
135133 }
136134
137- remediationCR .SetName (crName )
138135 remediationCR .SetNamespace (template .GetNamespace ())
139136 remediationCR .SetResourceVersion ("" )
140137 remediationCR .SetFinalizers (nil )
@@ -415,15 +412,3 @@ func createOwnerRef(obj client.Object) *metav1.OwnerReference {
415412 BlockOwnerDeletion : nil ,
416413 }
417414}
418-
419- func generateUniqueRemediationName (name string ) string {
420- const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
421- length := 6
422- bytes := make ([]byte , length )
423- for i := range bytes {
424- n , _ := rand .Int (rand .Reader , big .NewInt (int64 (len (charset ))))
425- bytes [i ] = charset [n .Int64 ()]
426- }
427- uniqueSuffix := string (bytes )
428- return fmt .Sprintf ("%s-%s" , name , uniqueSuffix )
429- }
0 commit comments