Skip to content

Commit

Permalink
Added support for managedFieldsManagers and Helm templating version (#…
Browse files Browse the repository at this point in the history
…400)

* Added support for the managed_fields_managers to specify ignoring differences for external controllers that manage fields. Added support for adding the helm version for templating

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Updated documentation

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Ensured that helm version and managed fields managers are flattened. Added test cases for helm version and managed fields managers

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Included the helm version in test case

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Fixed typo in test case ref to managed_fields_managers

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Fixed issues with test cases. Updated documentation withe the two accepted values for helm version

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Fixed helm version and managed fields managers attr checks

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Included json pointers in ignore difference to fix issues with state verification in tests

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

* Ignore validate on state checks. Fixed bad formatting, thanks VSCode. Removed json pointers on one of the tests

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>

---------

Signed-off-by: Tony Owens <anthony.owens1987@gmail.com>
  • Loading branch information
tonedefdev authored Aug 20, 2024
1 parent adc97b7 commit f4c64ee
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 6 deletions.
77 changes: 77 additions & 0 deletions argocd/resource_argocd_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ ingress:
"spec.0.source.0.helm.0.ignore_missing_value_files",
"true",
),
resource.TestCheckResourceAttr(
"argocd_application.helm",
"spec.0.source.0.helm.0.version",
"v3",
),
),
},
{
Expand Down Expand Up @@ -264,6 +269,32 @@ func TestAccArgoCDApplication_IgnoreDifferences(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "status", "validate"},
},
{
Config: testAccArgoCDApplicationIgnoreDiffManagedFieldsManagers(
acctest.RandomWithPrefix("test-acc")),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(
"argocd_application.ignore_differences_managed_fields_managers",
"metadata.0.uid",
),
resource.TestCheckResourceAttr(
"argocd_application.ignore_differences_managed_fields_managers",
"spec.0.ignore_difference.0.managed_fields_managers.0",
"some-controller-owner",
),
resource.TestCheckResourceAttr(
"argocd_application.ignore_differences_managed_fields_managers",
"spec.0.ignore_difference.1.managed_fields_managers.1",
"some-other-controller-owner",
),
),
},
{
ResourceName: "argocd_application.ignore_differences_managed_fields_managers",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "status", "validate"},
},
},
})
}
Expand Down Expand Up @@ -1201,6 +1232,7 @@ resource "argocd_application" "helm" {
pass_credentials = true
ignore_missing_value_files = true
version = "v3"
value_files = ["values.yaml"]
Expand Down Expand Up @@ -1672,6 +1704,51 @@ resource "argocd_application" "ignore_differences_jqpe" {
`, name)
}

func testAccArgoCDApplicationIgnoreDiffManagedFieldsManagers(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "ignore_differences_managed_fields_managers" {
metadata {
name = "%s"
namespace = "argocd"
labels = {
acceptance = "true"
}
}
spec {
source {
repo_url = "https://raw.githubusercontent.com/bitnami/charts/archive-full-index/bitnami"
chart = "redis"
target_revision = "16.9.11"
}
destination {
server = "https://kubernetes.default.svc"
namespace = "default"
}
ignore_difference {
group = "apps"
kind = "Deployment"
json_pointers = ["/spec/replicas"]
managed_fields_managers = ["some-controller-owner"]
}
ignore_difference {
group = "apps"
kind = "StatefulSet"
name = "someStatefulSet"
managed_fields_managers = [
"some-controller-owner",
"some-other-controller-owner",
]
}
}
}
`, name)
}

func testAccArgoCDApplication_OptionalDestinationNamespace(name string) string {
return fmt.Sprintf(`
resource "argocd_application" "no_namespace" {
Expand Down
14 changes: 14 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,11 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
Description: "If true then adds '--pass-credentials' to Helm commands to pass credentials to all domains.",
Optional: true,
},
"version": {
Type: schema.TypeString,
Description: "The Helm version to use for templating. Accepts either `v2` or `v3`",
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -1759,6 +1764,15 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
Type: schema.TypeString,
},
},
"managed_fields_managers": {
Type: schema.TypeSet,
Description: "List of external controller manager names whose changes to fields should be ignored.",
Set: schema.HashString,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
Expand Down
25 changes: 19 additions & 6 deletions argocd/structure_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ func expandApplicationSourceHelm(in []interface{}) *application.ApplicationSourc
result.SkipCrds = v.(bool)
}

if v, ok := a["version"]; ok {
result.Version = v.(string)
}

return result
}

Expand Down Expand Up @@ -451,6 +455,13 @@ func expandApplicationIgnoreDifferences(ids []interface{}) (result []application
}
}

if v, ok := id["managed_fields_managers"]; ok {
managedFieldsManagers := v.(*schema.Set).List()
for _, fieldsManager := range managedFieldsManagers {
elem.ManagedFieldsManagers = append(elem.ManagedFieldsManagers, fieldsManager.(string))
}
}

result = append(result, elem)
}

Expand Down Expand Up @@ -645,12 +656,13 @@ func flattenApplicationInfo(infos []application.Info) (result []map[string]strin
func flattenApplicationIgnoreDifferences(ids []application.ResourceIgnoreDifferences) (result []map[string]interface{}) {
for _, id := range ids {
result = append(result, map[string]interface{}{
"group": id.Group,
"kind": id.Kind,
"name": id.Name,
"namespace": id.Namespace,
"json_pointers": id.JSONPointers,
"jq_path_expressions": id.JQPathExpressions,
"group": id.Group,
"kind": id.Kind,
"name": id.Name,
"namespace": id.Namespace,
"json_pointers": id.JSONPointers,
"jq_path_expressions": id.JQPathExpressions,
"managed_fields_managers": id.ManagedFieldsManagers,
})
}

Expand Down Expand Up @@ -788,6 +800,7 @@ func flattenApplicationSourceHelm(as []*application.ApplicationSourceHelm) (resu
"values": a.Values,
"pass_credentials": a.PassCredentials,
"ignore_missing_value_files": a.IgnoreMissingValueFiles,
"version": a.Version,
})
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/resources/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ Optional:
- `skip_crds` (Boolean) Whether to skip custom resource definition installation step (Helm's [--skip-crds](https://helm.sh/docs/chart_best_practices/custom_resource_definitions/)).
- `value_files` (List of String) List of Helm value files to use when generating a template.
- `values` (String) Helm values to be passed to 'helm template', typically defined as a block.
- `version` (String) The Helm version to use for templating. Accepts either `v2` or `v3`

<a id="nestedblock--spec--source--helm--file_parameter"></a>
### Nested Schema for `spec.source.helm.file_parameter`
Expand Down Expand Up @@ -362,6 +363,7 @@ Optional:
- `jq_path_expressions` (Set of String) List of JQ path expression strings targeting the field(s) to ignore.
- `json_pointers` (Set of String) List of JSONPaths strings targeting the field(s) to ignore.
- `kind` (String) The Kubernetes resource Kind to match for.
- `managed_fields_managers` (Set of String) List of external controller manager names whose changes to fields should be ignored.
- `name` (String) The Kubernetes resource Name to match for.
- `namespace` (String) The Kubernetes resource Namespace to match for.

Expand Down
Loading

0 comments on commit f4c64ee

Please sign in to comment.