Skip to content

Commit

Permalink
ROX-18427: read central DB ID override from optional ConfigMap
Browse files Browse the repository at this point in the history
  • Loading branch information
vladbologa committed Sep 11, 2023
1 parent f35e8b2 commit d94244a
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,7 +987,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)
}
Expand All @@ -1013,6 +1019,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(&central)
Expand Down Expand Up @@ -1140,7 +1167,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)
}
Expand Down

0 comments on commit d94244a

Please sign in to comment.