Skip to content

Commit 41a2e9e

Browse files
feat: add finalizers field
Finalizers are a valid field for projects, apps and appsets. Signed-off-by: Blake Pettersson <[email protected]>
1 parent 5daf973 commit 41a2e9e

8 files changed

+148
-0
lines changed

argocd/resource_argocd_application_set_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,6 +907,35 @@ func TestAccArgoCDApplicationSet_syncPolicy(t *testing.T) {
907907
})
908908
}
909909

910+
func TestAccArgoCDApplicationSet_finalizers(t *testing.T) {
911+
resource.ParallelTest(t, resource.TestCase{
912+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
913+
ProviderFactories: testAccProviders,
914+
Steps: []resource.TestStep{
915+
{
916+
Config: testAccArgoCDApplicationSet_finalizers(),
917+
Check: resource.ComposeTestCheckFunc(
918+
resource.TestCheckResourceAttrSet(
919+
"argocd_application_set.finalizers",
920+
"metadata.0.finalizers",
921+
),
922+
resource.TestCheckResourceAttr(
923+
"argocd_application_set.finalizers",
924+
"metadata.0.finalizers.0.finalizers",
925+
"argocd.argoproj.io/applicationset",
926+
),
927+
),
928+
},
929+
{
930+
ResourceName: "argocd_application_set.finalizers",
931+
ImportState: true,
932+
ImportStateVerify: true,
933+
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
934+
},
935+
},
936+
})
937+
}
938+
910939
func TestAccArgoCDApplicationSet_syncPolicyWithApplicationsSyncPolicy(t *testing.T) {
911940
resource.ParallelTest(t, resource.TestCase{
912941
PreCheck: func() {
@@ -2909,6 +2938,41 @@ resource "argocd_application_set" "sync_policy" {
29092938
}`
29102939
}
29112940

2941+
func testAccArgoCDApplicationSet_finalizers() string {
2942+
return `
2943+
resource "argocd_application_set" "finalizers" {
2944+
metadata {
2945+
name = "finalizers"
2946+
finalizers = ["argocd.argoproj.io/applicationset"]
2947+
}
2948+
2949+
spec {
2950+
generator {
2951+
clusters {} # Automatically use all clusters defined within Argo CD
2952+
}
2953+
2954+
template {
2955+
metadata {
2956+
name = "appset-finalizers-{{name}}"
2957+
}
2958+
2959+
spec {
2960+
source {
2961+
repo_url = "https://github.com/argoproj/argocd-example-apps/"
2962+
target_revision = "HEAD"
2963+
path = "guestbook"
2964+
}
2965+
2966+
destination {
2967+
server = "{{server}}"
2968+
namespace = "default"
2969+
}
2970+
}
2971+
}
2972+
}
2973+
}`
2974+
}
2975+
29122976
func testAccArgoCDApplicationSet_syncPolicyWithApplicationsSync() string {
29132977
return `
29142978
resource "argocd_application_set" "applications_sync_policy" {

argocd/resource_argocd_application_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2365,6 +2365,35 @@ resource "argocd_application" "multiple_sources" {
23652365
}
23662366
}`
23672367
}
2368+
func testAccArgoCDApplication_finalizers() string {
2369+
return `
2370+
resource "argocd_application" "namespace_metadata" {
2371+
metadata {
2372+
name = "namespace-metadata"
2373+
namespace = "argocd"
2374+
finalizers = ["finalizer.argocd.argoproj.io"]
2375+
}
2376+
2377+
spec {
2378+
project = "default"
2379+
2380+
source {
2381+
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
2382+
chart = "apache"
2383+
target_revision = "9.4.1"
2384+
}
2385+
2386+
destination {
2387+
server = "https://kubernetes.default.svc"
2388+
namespace = "managed-namespace"
2389+
}
2390+
2391+
sync_policy {
2392+
sync_options = ["CreateNamespace=true"]
2393+
}
2394+
}
2395+
}`
2396+
}
23682397

23692398
func testAccArgoCDApplication_ManagedNamespaceMetadata() string {
23702399
return `

argocd/resource_argocd_project_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,19 @@ func TestAccArgoCDProject(t *testing.T) {
9696
),
9797
),
9898
},
99+
{
100+
Config: testAccArgoCDProjectSimpleWithFinalizers(name),
101+
Check: resource.ComposeTestCheckFunc(
102+
resource.TestCheckResourceAttrSet(
103+
"argocd_project.simple",
104+
"metadata.0.uid",
105+
),
106+
resource.TestCheckResourceAttrSet(
107+
"argocd_project.simple",
108+
"metadata.0.finalizers",
109+
),
110+
),
111+
},
99112
},
100113
})
101114
}
@@ -401,6 +414,34 @@ func testAccArgoCDProjectSimpleWithoutOrphaned(name string) string {
401414
`, name)
402415
}
403416

417+
func testAccArgoCDProjectSimpleWithFinalizers(name string) string {
418+
return fmt.Sprintf(`
419+
resource "argocd_project" "simple" {
420+
metadata {
421+
name = "%s"
422+
namespace = "argocd"
423+
labels = {
424+
acceptance = "true"
425+
}
426+
annotations = {
427+
"this.is.a.really.long.nested.key" = "yes, really!"
428+
}
429+
finalizers = ["finalizer1", "finalizer2"]
430+
}
431+
432+
spec {
433+
description = "simple project"
434+
source_repos = ["*"]
435+
436+
destination {
437+
name = "anothercluster"
438+
namespace = "bar"
439+
}
440+
}
441+
}
442+
`, name)
443+
}
444+
404445
func testAccArgoCDProjectSimpleWithEmptyOrphaned(name string) string {
405446
return fmt.Sprintf(`
406447
resource "argocd_project" "simple" {

argocd/schema_metadata.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,11 @@ func metadataFields(objectName string) map[string]*schema.Schema {
6565
Description: fmt.Sprintf("The unique in time and space value for this %s. More info: http://kubernetes.io/docs/user-guide/identifiers#uids", objectName),
6666
Computed: true,
6767
},
68+
"finalizers": {
69+
Type: schema.TypeList,
70+
Description: "List of finalizers for the resource.",
71+
Optional: true,
72+
Elem: &schema.Schema{Type: schema.TypeString},
73+
},
6874
}
6975
}

argocd/structure_metadata.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ func expandMetadata(d *schema.ResourceData) (meta meta.ObjectMeta) {
2020
meta.Labels = expandStringMap(m["labels"].(map[string]interface{}))
2121
}
2222

23+
if v, ok := m["finalizers"].([]interface{}); ok && len(v) > 0 {
24+
meta.Finalizers = expandStringList(v)
25+
}
26+
2327
if v, ok := m["name"]; ok {
2428
meta.Name = v.(string)
2529
}
@@ -37,6 +41,7 @@ func flattenMetadata(meta meta.ObjectMeta, d *schema.ResourceData) []interface{}
3741
"name": meta.Name,
3842
"namespace": meta.Namespace,
3943
"resource_version": meta.ResourceVersion,
44+
"finalizers": meta.Finalizers,
4045
"uid": fmt.Sprintf("%v", meta.UID),
4146
}
4247

docs/resources/application.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ resource "argocd_application" "multiple_sources" {
191191
Optional:
192192

193193
- `annotations` (Map of String) An unstructured key value map stored with the applications.argoproj.io that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations
194+
- `finalizers` (List of String) List of finalizers for the resource.
194195
- `labels` (Map of String) Map of string keys and values that can be used to organize and categorize (scope and select) the applications.argoproj.io. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels
195196
- `name` (String) Name of the applications.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
196197
- `namespace` (String) Namespace of the applications.argoproj.io, must be unique. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/

docs/resources/application_set.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ resource "argocd_application_set" "progressive_sync" {
576576
Optional:
577577

578578
- `annotations` (Map of String) An unstructured key value map stored with the applicationsets.argoproj.io that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations
579+
- `finalizers` (List of String) List of finalizers for the resource.
579580
- `labels` (Map of String) Map of string keys and values that can be used to organize and categorize (scope and select) the applicationsets.argoproj.io. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels
580581
- `name` (String) Name of the applicationsets.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
581582
- `namespace` (String) Namespace of the applicationsets.argoproj.io, must be unique. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/

docs/resources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ resource "argocd_project" "myproject" {
149149
Optional:
150150

151151
- `annotations` (Map of String) An unstructured key value map stored with the appprojects.argoproj.io that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations
152+
- `finalizers` (List of String) List of finalizers for the resource.
152153
- `labels` (Map of String) Map of string keys and values that can be used to organize and categorize (scope and select) the appprojects.argoproj.io. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels
153154
- `name` (String) Name of the appprojects.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
154155
- `namespace` (String) Namespace of the appprojects.argoproj.io, must be unique. Cannot be updated. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/

0 commit comments

Comments
 (0)