@@ -40,22 +40,22 @@ type KafkaSchemaReconciler struct {
4040}
4141
4242func (r * KafkaSchemaReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
43- log := log .FromContext (ctx )
43+ logger := log .FromContext (ctx )
4444
4545 schema := & kafkaschemaoperatorv2beta1.KafkaSchema {}
4646 err := r .Get (ctx , req .NamespacedName , schema )
4747 if err != nil {
4848 if errors .IsNotFound (err ) {
49- log .Info ("Schema resource not found. Ignoring since object must be deleted" )
49+ logger .Info ("Schema resource not found. Ignoring since object must be deleted" )
5050 return ctrl.Result {}, nil
5151 }
52- log .Error (err , "Failed to get Schema resource" )
52+ logger .Error (err , "Failed to get Schema resource" )
5353 return ctrl.Result {}, err
5454 }
5555
56- srClient , err := schemareg .NewClient (& schema .SchemaRegistry , log )
56+ srClient , err := schemareg .NewClient (& schema .SchemaRegistry , logger )
5757 if err != nil {
58- log .Error (err , "Failed to instantiate Schema Registry Client" )
58+ logger .Error (err , "Failed to instantiate Schema Registry Client" )
5959 return ctrl.Result {}, err
6060 }
6161
@@ -75,23 +75,23 @@ func (r *KafkaSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
7575 controllerutil .RemoveFinalizer (schema , schemaFinilizers )
7676 err = r .Update (ctx , schema )
7777 if err != nil {
78- log .Error (err , "Failed to delete KafkaSchema from kubernetes: " + schema .Name )
78+ logger .Error (err , "Failed to delete KafkaSchema from kubernetes: " + schema .Name )
7979 return ctrl.Result {}, err
8080 }
81- log .Info ("KafkaSchema CR was deleted: " + schema .Name )
81+ logger .Info ("KafkaSchema CR was deleted: " + schema .Name )
8282
8383 err := srClient .DeleteSubject (schemaKey )
8484 if err != nil {
85- log .Error (err , "Failed to delete subject for key schema from registry: " + schemaKey )
85+ logger .Error (err , "Failed to delete subject for key schema from registry: " + schemaKey )
8686 return ctrl.Result {}, err
8787 }
8888
8989 err = srClient .DeleteSubject (schemaValue )
9090 if err != nil {
91- log .Error (err , "Failed to delete subject for value schema from registry: " + schemaValue )
91+ logger .Error (err , "Failed to delete subject for value schema from registry: " + schemaValue )
9292 return ctrl.Result {}, err
9393 }
94- log .Info ("Schema was removed from registry" )
94+ logger .Info ("Schema was removed from registry" )
9595 return ctrl.Result {}, nil
9696 }
9797 return ctrl.Result {}, nil
@@ -101,60 +101,59 @@ func (r *KafkaSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
101101 controllerutil .AddFinalizer (schema , schemaFinilizers )
102102 err = r .Update (ctx , schema )
103103 if err != nil {
104- log .Info ("Failed to update finalizers for CR: " + schema .Name )
104+ logger .Info ("Failed to update finalizers for CR: " + schema .Name )
105105 return ctrl.Result {}, err
106106 }
107- log .Info ("Finalizers are set for CR: " + schema .Name )
107+ logger .Info ("Finalizers are set for CR: " + schema .Name )
108108 }
109109
110110 err = srClient .RegisterSchema (
111111 schemaKey ,
112112 schemareg.RegisterSchemaReq {
113- Schema : `{\ "type\ ": \ "` + schema .Spec .SchemaSerializer + `\ "}` ,
113+ Schema : `{"type": "` + schema .Spec .SchemaSerializer + `"}` ,
114114 })
115115 if err != nil {
116- log .Error (err , "Failed to update schema registry" )
116+ logger .Error (err , "Failed to update schema registry" )
117117 return reconcileResult , err
118118 }
119- log .Info ("Schema key was published: " + schemaKey )
120-
121- cfgData := schema .Spec .Data .Schema
122- cfgData = strings .ReplaceAll (cfgData , "\n " , "" )
123- cfgData = strings .ReplaceAll (cfgData , "\t " , "" )
124- cfgData = strings .ReplaceAll (cfgData , " " , "" )
125- cfgData = strings .ReplaceAll (cfgData , `"` , `\"` )
126- cfgData = strings .Replace (cfgData , `\"{` , `"{` , 1 )
127- cfgData = strings .Replace (cfgData , `}\"` , `}"` , - 1 )
119+ logger .Info ("Schema key was published: " + schemaKey )
128120
129121 err = srClient .RegisterSchema (
130122 schemaValue ,
131123 schemareg.RegisterSchemaReq {
132- Schema : cfgData ,
124+ Schema : schema . Spec . Data . Schema ,
133125 SchemaType : strings .ToUpper (schema .Spec .Data .Format ),
134126 })
135127 if err != nil {
136- log .Error (err , "Failed to update schema registry" )
128+ logger .Error (err , "Failed to update schema registry" )
137129 return reconcileResult , err
138130 }
139131
140- var schemaCompatibilityPayload strings.Builder
141- schemaCompatibilityPayload .WriteString (`{"compatibility": "` )
142- schemaCompatibilityPayload .WriteString (schema .Spec .Data .Compatibility )
143- schemaCompatibilityPayload .WriteString (`"}` )
132+ err = srClient .SetCompatibilityMode (
133+ schemaValue ,
134+ schemareg.SetCompatibilityModeReq {
135+ Compatibility : schema .Spec .Data .Compatibility ,
136+ },
137+ )
144138
145- err = srClient .SetCompatibilityMode (schemaValue , schemaCompatibilityPayload .String ())
146139 if err != nil {
147- log .Error (err , "Failed to update schema compatibility for value" )
140+ logger .Error (err , "Failed to update schema compatibility for value" )
148141 return reconcileResult , err
149142 }
150143
151- err = srClient .SetCompatibilityMode (schemaKey , schemaCompatibilityPayload .String ())
144+ err = srClient .SetCompatibilityMode (
145+ schemaKey ,
146+ schemareg.SetCompatibilityModeReq {
147+ Compatibility : schema .Spec .Data .Compatibility ,
148+ },
149+ )
150+
152151 if err != nil {
153- log .Error (err , "Failed to update schema compatibility for key" )
152+ logger .Error (err , "Failed to update schema compatibility for key" )
154153 return reconcileResult , err
155154 }
156155
157- log .Info ("Schema value was published: " + schemaValue )
156+ logger .Info ("Schema value was published: " + schemaValue )
158157 return reconcileResult , nil
159158}
160159
0 commit comments