Skip to content

Commit 16ecc04

Browse files
feat: add finalizers field
Finalizers are a valid field for projects, apps and appsets. Fixes #391 and #404. Signed-off-by: Blake Pettersson <[email protected]>
1 parent 5e4ae92 commit 16ecc04

File tree

8 files changed

+173
-0
lines changed

8 files changed

+173
-0
lines changed

argocd/resource_argocd_application_set_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,31 @@ func TestAccArgoCDApplicationSet_syncPolicy(t *testing.T) {
950950
})
951951
}
952952

953+
func TestAccArgoCDApplicationSet_finalizers(t *testing.T) {
954+
resource.ParallelTest(t, resource.TestCase{
955+
PreCheck: func() { testAccPreCheck(t); testAccPreCheckFeatureSupported(t, features.ApplicationSet) },
956+
ProviderFactories: testAccProviders,
957+
Steps: []resource.TestStep{
958+
{
959+
Config: testAccArgoCDApplicationSet_finalizers(),
960+
Check: resource.ComposeTestCheckFunc(
961+
resource.TestCheckResourceAttr(
962+
"argocd_application_set.finalizers",
963+
"metadata.0.finalizers.0",
964+
"argocd.argoproj.io/applicationset",
965+
),
966+
),
967+
},
968+
{
969+
ResourceName: "argocd_application_set.finalizers",
970+
ImportState: true,
971+
ImportStateVerify: true,
972+
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
973+
},
974+
},
975+
})
976+
}
977+
953978
func TestAccArgoCDApplicationSet_syncPolicyWithApplicationsSyncPolicy(t *testing.T) {
954979
resource.ParallelTest(t, resource.TestCase{
955980
PreCheck: func() {
@@ -3083,6 +3108,41 @@ resource "argocd_application_set" "sync_policy" {
30833108
}`
30843109
}
30853110

3111+
func testAccArgoCDApplicationSet_finalizers() string {
3112+
return `
3113+
resource "argocd_application_set" "finalizers" {
3114+
metadata {
3115+
name = "finalizers"
3116+
finalizers = ["argocd.argoproj.io/applicationset"]
3117+
}
3118+
3119+
spec {
3120+
generator {
3121+
clusters {} # Automatically use all clusters defined within Argo CD
3122+
}
3123+
3124+
template {
3125+
metadata {
3126+
name = "appset-finalizers-{{name}}"
3127+
}
3128+
3129+
spec {
3130+
source {
3131+
repo_url = "https://github.com/argoproj/argocd-example-apps/"
3132+
target_revision = "HEAD"
3133+
path = "guestbook"
3134+
}
3135+
3136+
destination {
3137+
server = "{{server}}"
3138+
namespace = "default"
3139+
}
3140+
}
3141+
}
3142+
}
3143+
}`
3144+
}
3145+
30863146
func testAccArgoCDApplicationSet_syncPolicyWithApplicationsSync() string {
30873147
return `
30883148
resource "argocd_application_set" "applications_sync_policy" {

argocd/resource_argocd_application_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,29 @@ func TestAccArgoCDApplication_EmptySyncPolicyBlock(t *testing.T) {
760760
})
761761
}
762762

763+
func TestAccArgoCDApplication_Finalizers(t *testing.T) {
764+
resource.ParallelTest(t, resource.TestCase{
765+
PreCheck: func() { testAccPreCheck(t) },
766+
ProviderFactories: testAccProviders,
767+
Steps: []resource.TestStep{
768+
{
769+
Config: testAccArgoCDApplication_finalizers(),
770+
Check: resource.ComposeTestCheckFunc(
771+
resource.TestCheckResourceAttrSet(
772+
"argocd_application.finalizers",
773+
"metadata.0.uid",
774+
),
775+
resource.TestCheckResourceAttr(
776+
"argocd_application.finalizers",
777+
"metadata.0.finalizers.0",
778+
"finalizer.argocd.argoproj.io",
779+
),
780+
),
781+
},
782+
},
783+
})
784+
}
785+
763786
func TestAccArgoCDApplication_NoAutomatedBlock(t *testing.T) {
764787
resource.ParallelTest(t, resource.TestCase{
765788
PreCheck: func() { testAccPreCheck(t) },
@@ -2416,6 +2439,35 @@ resource "argocd_application" "multiple_sources" {
24162439
}
24172440
}`
24182441
}
2442+
func testAccArgoCDApplication_finalizers() string {
2443+
return `
2444+
resource "argocd_application" "finalizers" {
2445+
metadata {
2446+
name = "finalizers"
2447+
namespace = "argocd"
2448+
finalizers = ["finalizer.argocd.argoproj.io"]
2449+
}
2450+
2451+
spec {
2452+
project = "default"
2453+
2454+
source {
2455+
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
2456+
chart = "apache"
2457+
target_revision = "9.4.1"
2458+
}
2459+
2460+
destination {
2461+
server = "https://kubernetes.default.svc"
2462+
namespace = "managed-namespace"
2463+
}
2464+
2465+
sync_policy {
2466+
sync_options = ["CreateNamespace=true"]
2467+
}
2468+
}
2469+
}`
2470+
}
24192471

24202472
func testAccArgoCDApplication_ManagedNamespaceMetadata() string {
24212473
return `

argocd/resource_argocd_project_test.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ 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.TestCheckResourceAttr(
107+
"argocd_project.simple",
108+
"metadata.0.finalizers.0",
109+
"finalizer1",
110+
),
111+
resource.TestCheckResourceAttr(
112+
"argocd_project.simple",
113+
"metadata.0.finalizers.1",
114+
"finalizer2",
115+
),
116+
),
117+
},
99118
},
100119
})
101120
}
@@ -401,6 +420,34 @@ func testAccArgoCDProjectSimpleWithoutOrphaned(name string) string {
401420
`, name)
402421
}
403422

423+
func testAccArgoCDProjectSimpleWithFinalizers(name string) string {
424+
return fmt.Sprintf(`
425+
resource "argocd_project" "simple" {
426+
metadata {
427+
name = "%s"
428+
namespace = "argocd"
429+
labels = {
430+
acceptance = "true"
431+
}
432+
annotations = {
433+
"this.is.a.really.long.nested.key" = "yes, really!"
434+
}
435+
finalizers = ["finalizer1", "finalizer2"]
436+
}
437+
438+
spec {
439+
description = "simple project"
440+
source_repos = ["*"]
441+
442+
destination {
443+
name = "anothercluster"
444+
namespace = "bar"
445+
}
446+
}
447+
}
448+
`, name)
449+
}
450+
404451
func testAccArgoCDProjectSimpleWithEmptyOrphaned(name string) string {
405452
return fmt.Sprintf(`
406453
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
@@ -193,6 +193,7 @@ resource "argocd_application" "multiple_sources" {
193193
Optional:
194194

195195
- `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
196+
- `finalizers` (List of String) List of finalizers for the resource.
196197
- `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
197198
- `name` (String) Name of the applications.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
198199
- `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
@@ -578,6 +578,7 @@ resource "argocd_application_set" "progressive_sync" {
578578
Optional:
579579

580580
- `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
581+
- `finalizers` (List of String) List of finalizers for the resource.
581582
- `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
582583
- `name` (String) Name of the applicationsets.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
583584
- `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
@@ -151,6 +151,7 @@ resource "argocd_project" "myproject" {
151151
Optional:
152152

153153
- `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
154+
- `finalizers` (List of String) List of finalizers for the resource.
154155
- `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
155156
- `name` (String) Name of the appprojects.argoproj.io, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names
156157
- `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)