Skip to content

Commit

Permalink
Fix post-delete finalizer in appset (#18003)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Bowbeer <joe.bowbeer@gmail.com>
  • Loading branch information
joebowbeer committed Apr 26, 2024
1 parent 96e796e commit 575575a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
12 changes: 12 additions & 0 deletions applicationset/controllers/applicationset_controller.go
Expand Up @@ -17,6 +17,7 @@ package controllers
import (
"context"
"fmt"
"strings"
"time"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -723,6 +724,17 @@ func (r *ApplicationSetReconciler) createOrUpdateInCluster(ctx context.Context,
}
}

// Preserve post-delete finalizers:
// https://github.com/argoproj/argo-cd/issues/17181
for _, finalizer := range found.ObjectMeta.Finalizers {
if strings.HasPrefix(finalizer, argov1alpha1.PostDeleteFinalizerName) {
if generatedApp.Finalizers == nil {
generatedApp.Finalizers = []string{}
}
generatedApp.Finalizers = append(generatedApp.Finalizers, finalizer)
}
}

found.ObjectMeta.Annotations = generatedApp.Annotations

found.ObjectMeta.Finalizers = generatedApp.Finalizers
Expand Down
65 changes: 65 additions & 0 deletions applicationset/controllers/applicationset_controller_test.go
Expand Up @@ -1281,6 +1281,71 @@ func TestCreateOrUpdateInCluster(t *testing.T) {
},
},
},
}, {
name: "Ensure that argocd post-delete finalizers are preserved from an existing app",
appSet: v1alpha1.ApplicationSet{
ObjectMeta: metav1.ObjectMeta{
Name: "name",
Namespace: "namespace",
},
Spec: v1alpha1.ApplicationSetSpec{
Template: v1alpha1.ApplicationSetTemplate{
Spec: v1alpha1.ApplicationSpec{
Project: "project",
},
},
},
},
existingApps: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app1",
Namespace: "namespace",
ResourceVersion: "2",
Finalizers: []string{
v1alpha1.PostDeleteFinalizerName,
v1alpha1.PostDeleteFinalizerName + "/mystage",
},
},
Spec: v1alpha1.ApplicationSpec{
Project: "project",
},
},
},
desiredApps: []v1alpha1.Application{
{
ObjectMeta: metav1.ObjectMeta{
Name: "app1",
},
Spec: v1alpha1.ApplicationSpec{
Project: "project",
},
},
},
expected: []v1alpha1.Application{
{
TypeMeta: metav1.TypeMeta{
Kind: application.ApplicationKind,
APIVersion: "argoproj.io/v1alpha1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app1",
Namespace: "namespace",
ResourceVersion: "2",
Finalizers: []string{
v1alpha1.PostDeleteFinalizerName,
v1alpha1.PostDeleteFinalizerName + "/mystage",
},
},
Spec: v1alpha1.ApplicationSpec{
Project: "project",
},
},
},
},
} {

Expand Down

0 comments on commit 575575a

Please sign in to comment.