diff --git a/fleetshard/pkg/central/reconciler/reconciler.go b/fleetshard/pkg/central/reconciler/reconciler.go index 73dad97ea2..ec9b54442b 100644 --- a/fleetshard/pkg/central/reconciler/reconciler.go +++ b/fleetshard/pkg/central/reconciler/reconciler.go @@ -911,7 +911,13 @@ func (r *CentralReconciler) ensureCentralDeleted(ctx context.Context, remoteCent if r.managedDBEnabled { // skip Snapshot for remoteCentral created by probe skipSnapshot := remoteCentral.Metadata.Internal - err = r.managedDBProvisioningClient.EnsureDBDeprovisioned(remoteCentral.Id, skipSnapshot) + + databaseID, err := r.getDatabaseID(ctx, remoteCentral.Metadata.Namespace, remoteCentral.Id) + if err != nil { + return false, fmt.Errorf("getting DB ID: %w", err) + } + + err = r.managedDBProvisioningClient.EnsureDBDeprovisioned(databaseID, skipSnapshot) if err != nil { return false, fmt.Errorf("deprovisioning DB: %v", err) } @@ -937,6 +943,27 @@ func (r *CentralReconciler) ensureCentralDeleted(ctx context.Context, remoteCent return globalDeleted, nil } +func (r *CentralReconciler) getDatabaseID(ctx context.Context, remoteCentralNamespace, centralID string) (string, error) { + // By default the database ID (which is used to name the cloud DB resources) is the same as the central ID, + // but this value can be overriden + configMap := &corev1.ConfigMap{} + err := r.client.Get(ctx, ctrlClient.ObjectKey{Namespace: remoteCentralNamespace, Name: "central-db-override"}, configMap) + if err != nil { + if apiErrors.IsNotFound(err) { + return centralID, nil + } + + return centralID, fmt.Errorf("getting central DB ID override ConfigMap: %w", err) + } + + overrideValue, exists := configMap.Data["databaseID"] + if exists { + return overrideValue, nil + } + + return centralID, nil +} + // centralChanged compares the given central to the last central reconciled using a hash func (r *CentralReconciler) centralChanged(central private.ManagedCentral) (bool, error) { currentHash, err := util.MD5SumFromJSONStruct(¢ral) @@ -1064,7 +1091,12 @@ func (r *CentralReconciler) ensureManagedCentralDBInitialized(ctx context.Contex return fmt.Errorf("getting DB password from secret: %w", err) } - err = r.managedDBProvisioningClient.EnsureDBProvisioned(ctx, remoteCentral.Id, remoteCentral.Id, dbMasterPassword, remoteCentral.Metadata.Internal) + databaseID, err := r.getDatabaseID(ctx, remoteCentralNamespace, remoteCentral.Id) + if err != nil { + return fmt.Errorf("getting DB ID: %w", err) + } + + err = r.managedDBProvisioningClient.EnsureDBProvisioned(ctx, databaseID, remoteCentral.Id, dbMasterPassword, remoteCentral.Metadata.Internal) if err != nil { return fmt.Errorf("provisioning RDS DB: %w", err) }