Skip to content

Commit

Permalink
postgres/migrate: delete with propagation policy set to foreground
Browse files Browse the repository at this point in the history
This ensures that we immediately trigger deletion of child resources.

We want this as some of these commands may run in quick succession, e.g.
`rollback` followed by `setup`, which may cause inconsistent states with
child resources for the NaisJobs not being deleted before naiserator has
to re-create them (e.g. `CreateIfNotExists` for `IAMServiceAccounts`).
  • Loading branch information
tronghn committed Mar 6, 2025
1 parent d499fcf commit a74dd03
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/postgres/migrate/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ func (m *Migrator) Delete(ctx context.Context, obj ctrl.Object) error {
pterm.Printf("Dry run: Skipping deletion of %s: %s\n", v.Type().Name(), obj.GetName())
return nil
}
return m.client.Delete(ctx, obj)

opts := []ctrl.DeleteOption{
ctrl.PropagationPolicy(metav1.DeletePropagationForeground),
}
return m.client.Delete(ctx, obj, opts...)
}

func (m *Migrator) doNaisJob(ctx context.Context, cfgMap *corev1.ConfigMap, command Command) (string, error) {
Expand Down Expand Up @@ -397,7 +401,7 @@ func createObject[T interface {
ctrl.Object
*P
}, P any](ctx context.Context, m *Migrator, owner metav1.Object, obj T, Command Command) error {
err := controllerutil.SetOwnerReference(owner, obj, m.client.Scheme())
err := controllerutil.SetOwnerReference(owner, obj, m.client.Scheme(), controllerutil.WithBlockOwnerDeletion(true))
if err != nil {
return fmt.Errorf("failed to set owner reference: %w", err)
}
Expand Down

0 comments on commit a74dd03

Please sign in to comment.