@@ -80,12 +80,7 @@ func (r *OLSConfigReconciler) reconcilePostgresDeployment(ctx context.Context, c
8080 PostgresCAHashKey : r .stateCache [PostgresCAHashStateCacheKey ],
8181 }
8282 updateDeploymentAnnotations (desiredDeployment , annotations )
83- templateAnnotations := map [string ]string {
84- PostgresConfigHashKey : r .stateCache [PostgresConfigHashStateCacheKey ],
85- PostgresSecretHashKey : r .stateCache [PostgresSecretHashStateCacheKey ],
86- PostgresCAHashKey : r .stateCache [PostgresCAHashStateCacheKey ],
87- }
88- updateDeploymentTemplateAnnotations (desiredDeployment , templateAnnotations )
83+ updateDeploymentTemplateAnnotations (desiredDeployment , annotations )
8984 r .logger .Info ("creating a new OLS postgres deployment" , "deployment" , desiredDeployment .Name )
9085 err = r .Create (ctx , desiredDeployment )
9186 if err != nil {
@@ -283,28 +278,24 @@ func (r *OLSConfigReconciler) reconcilePostgresNetworkPolicy(ctx context.Context
283278}
284279
285280func (r * OLSConfigReconciler ) reconcilePostgresCA (ctx context.Context , cr * olsv1alpha1.OLSConfig ) error {
286- var caConfigMap * corev1.ConfigMap
287- var servingCertSecret * corev1.Secret
288281 certBytes := []byte {}
289- hasAnyInput := false
290282
283+ // Get service CA certificate from ConfigMap
291284 tmpCM := & corev1.ConfigMap {}
292285 err := r .Client .Get (ctx , client.ObjectKey {Name : OLSCAConfigMap , Namespace : r .Options .Namespace }, tmpCM )
293286 if err != nil {
294287 if ! errors .IsNotFound (err ) {
295- return fmt .Errorf ("failed to get openshift-service-ca.crt ConfigMap: %w" , err )
288+ return fmt .Errorf ("failed to get %s ConfigMap: %w" , OLSCAConfigMap , err )
296289 }
297- r .logger .Info ("openshift-service-ca.crt ConfigMap not found, skipping CA bundle" )
290+ r .logger .Info ("CA ConfigMap not found, skipping CA bundle" , "configmap" , OLSCAConfigMap )
298291 } else {
299- caConfigMap = tmpCM
300- if caCert , exists := caConfigMap .Data ["service-ca.crt" ]; exists {
301- certBytes = append (certBytes , []byte ("service-ca.crt" )... )
292+ if caCert , exists := tmpCM .Data [PostgresServiceCACertKey ]; exists {
293+ certBytes = append (certBytes , []byte (PostgresServiceCACertKey )... )
302294 certBytes = append (certBytes , []byte (caCert )... )
303- hasAnyInput = true
304295 }
305296 }
306297
307- // Serving cert Secret
298+ // Get serving cert from Secret
308299 tmpSec := & corev1.Secret {}
309300 err = r .Client .Get (ctx , client.ObjectKey {Name : PostgresCertsSecretName , Namespace : r .Options .Namespace }, tmpSec )
310301 if err != nil {
@@ -313,23 +304,17 @@ func (r *OLSConfigReconciler) reconcilePostgresCA(ctx context.Context, cr *olsv1
313304 }
314305 r .logger .Info ("serving cert Secret not found, skipping server certificate" , "secret" , PostgresCertsSecretName )
315306 } else {
316- servingCertSecret = tmpSec
317- if tlsCert , exists := servingCertSecret .Data ["tls.crt" ]; exists {
318- certBytes = append (certBytes , []byte ("tls.crt" )... )
307+ if tlsCert , exists := tmpSec .Data [PostgresTLSCertKey ]; exists {
308+ certBytes = append (certBytes , []byte (PostgresTLSCertKey )... )
319309 certBytes = append (certBytes , tlsCert ... )
320- hasAnyInput = true
321310 }
322311 }
323312
324313 // Calculate hash based on available inputs
325- var combinedHash string
326- if ! hasAnyInput {
327- // No cert inputs available - use empty hash
328- combinedHash = ""
329- } else {
314+ combinedHash := ""
315+ if len (certBytes ) > 0 {
330316 var err error
331- combinedHash , err = hashBytes (certBytes )
332- if err != nil {
317+ if combinedHash , err = hashBytes (certBytes ); err != nil {
333318 return fmt .Errorf ("failed to generate Postgres CA hash: %w" , err )
334319 }
335320 }
@@ -345,7 +330,7 @@ func (r *OLSConfigReconciler) reconcilePostgresCA(ctx context.Context, cr *olsv1
345330 return nil
346331 }
347332
348- r .logger .Info ("Postgres CA hash updated,deployment will be updated via updatePostgresDeployment" )
333+ r .logger .Info ("Postgres CA hash updated, deployment will be updated via updatePostgresDeployment" )
349334
350335 return nil
351336}
0 commit comments