Skip to content

Commit ec4ab16

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 <blake.pettersson@gmail.com>
1 parent 5daf973 commit ec4ab16

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
@@ -907,6 +907,31 @@ 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.TestCheckResourceAttr(
919+
"argocd_application_set.finalizers",
920+
"metadata.0.finalizers.0",
921+
"argocd.argoproj.io/applicationset",
922+
),
923+
),
924+
},
925+
{
926+
ResourceName: "argocd_application_set.finalizers",
927+
ImportState: true,
928+
ImportStateVerify: true,
929+
ImportStateVerifyIgnore: []string{"metadata.0.resource_version"},
930+
},
931+
},
932+
})
933+
}
934+
910935
func TestAccArgoCDApplicationSet_syncPolicyWithApplicationsSyncPolicy(t *testing.T) {
911936
resource.ParallelTest(t, resource.TestCase{
912937
PreCheck: func() {
@@ -2909,6 +2934,41 @@ resource "argocd_application_set" "sync_policy" {
29092934
}`
29102935
}
29112936

2937+
func testAccArgoCDApplicationSet_finalizers() string {
2938+
return `
2939+
resource "argocd_application_set" "finalizers" {
2940+
metadata {
2941+
name = "finalizers"
2942+
finalizers = ["argocd.argoproj.io/applicationset"]
2943+
}
2944+
2945+
spec {
2946+
generator {
2947+
clusters {} # Automatically use all clusters defined within Argo CD
2948+
}
2949+
2950+
template {
2951+
metadata {
2952+
name = "appset-finalizers-{{name}}"
2953+
}
2954+
2955+
spec {
2956+
source {
2957+
repo_url = "https://github.com/argoproj/argocd-example-apps/"
2958+
target_revision = "HEAD"
2959+
path = "guestbook"
2960+
}
2961+
2962+
destination {
2963+
server = "{{server}}"
2964+
namespace = "default"
2965+
}
2966+
}
2967+
}
2968+
}
2969+
}`
2970+
}
2971+
29122972
func testAccArgoCDApplicationSet_syncPolicyWithApplicationsSync() string {
29132973
return `
29142974
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) },
@@ -2365,6 +2388,35 @@ resource "argocd_application" "multiple_sources" {
23652388
}
23662389
}`
23672390
}
2391+
func testAccArgoCDApplication_finalizers() string {
2392+
return `
2393+
resource "argocd_application" "finalizers" {
2394+
metadata {
2395+
name = "finalizers"
2396+
namespace = "argocd"
2397+
finalizers = ["finalizer.argocd.argoproj.io"]
2398+
}
2399+
2400+
spec {
2401+
project = "default"
2402+
2403+
source {
2404+
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
2405+
chart = "apache"
2406+
target_revision = "9.4.1"
2407+
}
2408+
2409+
destination {
2410+
server = "https://kubernetes.default.svc"
2411+
namespace = "managed-namespace"
2412+
}
2413+
2414+
sync_policy {
2415+
sync_options = ["CreateNamespace=true"]
2416+
}
2417+
}
2418+
}`
2419+
}
23682420

23692421
func testAccArgoCDApplication_ManagedNamespaceMetadata() string {
23702422
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
@@ -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)