Skip to content

Commit 82a858d

Browse files
committed
Resolving comments.
1 parent cf657e5 commit 82a858d

File tree

5 files changed

+21
-53
lines changed

5 files changed

+21
-53
lines changed

internal/controller/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ const (
171171
PostgresSecretHashKey = "hash/postgres-secret"
172172
// PostgresCAHashKey is the key of the hash value of the OLS Postgres CA certificate
173173
PostgresCAHashKey = "hash/postgres-ca"
174+
// PostgresServiceCACertKey is the key for the service CA certificate in the ConfigMap
175+
PostgresServiceCACertKey = "service-ca.crt"
176+
// PostgresTLSCertKey is the key for the TLS certificate in the Secret
177+
PostgresTLSCertKey = "tls.crt"
174178
// PostgresServiceName is the name of OLS application Postgres server service
175179
PostgresServiceName = "lightspeed-postgres-server"
176180
// PostgresSecretName is the name of OLS application Postgres secret

internal/controller/ols_app_postgres_assets.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,7 @@ func (r *OLSConfigReconciler) updatePostgresDeployment(ctx context.Context, exis
265265
}
266266
updateDeploymentAnnotations(existingDeployment, annotations)
267267
// update the deployment template annotation triggers the rolling update
268-
templateAnnotations := map[string]string{
269-
PostgresConfigHashKey: r.stateCache[PostgresConfigHashStateCacheKey],
270-
PostgresSecretHashKey: r.stateCache[PostgresSecretHashStateCacheKey],
271-
PostgresCAHashKey: r.stateCache[PostgresCAHashStateCacheKey],
272-
}
273-
updateDeploymentTemplateAnnotations(existingDeployment, templateAnnotations)
268+
updateDeploymentTemplateAnnotations(existingDeployment, annotations)
274269

275270
if _, err := setDeploymentContainerEnvs(existingDeployment, desiredDeployment.Spec.Template.Spec.Containers[0].Env, PostgresDeploymentName); err != nil {
276271
return err
@@ -462,8 +457,7 @@ func (r *OLSConfigReconciler) generatePostgresPVC(cr *olsv1alpha1.OLSConfig) (*c
462457
// Create a copy of the storage configuration to avoid modifying the original CR
463458
storage := &olsv1alpha1.Storage{}
464459
if cr.Spec.OLSConfig.Storage != nil {
465-
storage.Size = cr.Spec.OLSConfig.Storage.Size
466-
storage.Class = cr.Spec.OLSConfig.Storage.Class
460+
storage = cr.Spec.OLSConfig.Storage.DeepCopy()
467461
}
468462
if err := r.storageDefaults(storage); err != nil {
469463
return nil, err

internal/controller/ols_app_postgres_reconciliator.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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

285280
func (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
}

internal/controller/ols_app_server_deployment.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,7 @@ func (r *OLSConfigReconciler) updateOLSDeployment(ctx context.Context, existingD
450450
}
451451
updateDeploymentAnnotations(existingDeployment, annotations)
452452
// update the deployment template annotation triggers the rolling update
453-
templateAnnotations := map[string]string{
454-
OLSConfigHashKey: r.stateCache[OLSConfigHashStateCacheKey],
455-
OLSAppTLSHashKey: r.stateCache[OLSAppTLSHashStateCacheKey],
456-
LLMProviderHashKey: r.stateCache[LLMProviderHashStateCacheKey],
457-
AdditionalCAHashKey: r.stateCache[AdditionalCAHashStateCacheKey],
458-
PostgresSecretHashKey: r.stateCache[PostgresSecretHashStateCacheKey],
459-
PostgresCAHashKey: r.stateCache[PostgresCAHashStateCacheKey],
460-
}
461-
updateDeploymentTemplateAnnotations(existingDeployment, templateAnnotations)
453+
updateDeploymentTemplateAnnotations(existingDeployment, annotations)
462454
changed = true
463455
}
464456

internal/controller/ols_app_server_reconciliator.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,7 @@ func (r *OLSConfigReconciler) reconcileDeployment(ctx context.Context, cr *olsv1
287287
PostgresCAHashKey: r.stateCache[PostgresCAHashStateCacheKey],
288288
}
289289
updateDeploymentAnnotations(desiredDeployment, annotations)
290-
templateAnnotations := map[string]string{
291-
OLSConfigHashKey: r.stateCache[OLSConfigHashStateCacheKey],
292-
OLSAppTLSHashKey: r.stateCache[OLSAppTLSHashStateCacheKey],
293-
LLMProviderHashKey: r.stateCache[LLMProviderHashStateCacheKey],
294-
PostgresSecretHashKey: r.stateCache[PostgresSecretHashStateCacheKey],
295-
PostgresCAHashKey: r.stateCache[PostgresCAHashStateCacheKey],
296-
}
297-
updateDeploymentTemplateAnnotations(desiredDeployment, templateAnnotations)
290+
updateDeploymentTemplateAnnotations(desiredDeployment, annotations)
298291
r.logger.Info("creating a new deployment", "deployment", desiredDeployment.Name)
299292
err = r.Create(ctx, desiredDeployment)
300293
if err != nil {

0 commit comments

Comments
 (0)