Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for managedFieldsManagers and Helm templating version #400

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 @@ -261,6 +266,32 @@ func TestAccArgoCDApplication_IgnoreDifferences(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"wait", "cascade", "status"},
},
{
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 @@ -1162,6 +1193,7 @@ resource "argocd_application" "helm" {

pass_credentials = true
ignore_missing_value_files = true
version = "v3"

value_files = ["values.yaml"]

Expand Down Expand Up @@ -1630,6 +1662,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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code ensures that the version is correctly set when creating the application in ArgoCD however, you are missing the oppositye side of this code which ensures that the Terraform state is updated to reflect the current state of the application in ArgoCD. See flattenApplicationSourceHelm.

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

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 @@ -299,6 +299,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 @@ -361,6 +362,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
Loading