Skip to content

Commit a74dd03

Browse files
committed
postgres/migrate: delete with propagation policy set to foreground
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`).
1 parent d499fcf commit a74dd03

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/postgres/migrate/migrate.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ func (m *Migrator) Delete(ctx context.Context, obj ctrl.Object) error {
109109
pterm.Printf("Dry run: Skipping deletion of %s: %s\n", v.Type().Name(), obj.GetName())
110110
return nil
111111
}
112-
return m.client.Delete(ctx, obj)
112+
113+
opts := []ctrl.DeleteOption{
114+
ctrl.PropagationPolicy(metav1.DeletePropagationForeground),
115+
}
116+
return m.client.Delete(ctx, obj, opts...)
113117
}
114118

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

0 commit comments

Comments
 (0)