Skip to content

Commit

Permalink
Add ignore_application_differences to argocd_application_set reso…
Browse files Browse the repository at this point in the history
…urce (#357)

* feat(argocd_applicationset): add ignore_application_differences attribute

* feat(argocd_applicationset): remove unnecessary if condition

* doc(argocd_applicationset): fix documentation application_set

* chores(argocd): add ArgoCD 2.9.3 to matrix test

* build(deps): Bump github.com/go-git/go-git/v5 from 5.7.0 to 5.11.0 (#361)

Bumps [github.com/go-git/go-git/v5](https://github.com/go-git/go-git) from 5.7.0 to 5.11.0.
- [Release notes](https://github.com/go-git/go-git/releases)
- [Commits](go-git/go-git@v5.7.0...v5.11.0)

---
updated-dependencies:
- dependency-name: github.com/go-git/go-git/v5
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): Bump github.com/argoproj/argo-cd/v2 from 2.8.3 to 2.8.8 (#365)

Bumps [github.com/argoproj/argo-cd/v2](https://github.com/argoproj/argo-cd) from 2.8.3 to 2.8.8.
- [Release notes](https://github.com/argoproj/argo-cd/releases)
- [Changelog](https://github.com/argoproj/argo-cd/blob/master/CHANGELOG.md)
- [Commits](argoproj/argo-cd@v2.8.3...v2.8.8)

---
updated-dependencies:
- dependency-name: github.com/argoproj/argo-cd/v2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: Add DiffSuppressFunc on argocd_cluster.server (#353)

* build(deps): Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#358)

Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.14.0 to 0.17.0.
- [Commits](golang/crypto@v0.14.0...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/crypto
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7 (#364)

Bumps [github.com/cloudflare/circl](https://github.com/cloudflare/circl) from 1.3.3 to 1.3.7.
- [Release notes](https://github.com/cloudflare/circl/releases)
- [Commits](cloudflare/circl@v1.3.3...v1.3.7)

---
updated-dependencies:
- dependency-name: github.com/cloudflare/circl
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps-dev): bump test versions of ArgoCD to latest patch versions

* build(deps-dev): bump test versions of k8s

* build(deps): bump github.com/argoproj/argo-cd/v2 from 2.9.3 to 2.9.9

* build(deps): bump k8s modules to align with argocd version

* fix: call cluster list endpoint with trimmed server

* fix: add diff suppression for empty sync policy on application

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marco Maurer (-Kilchhofer) <[email protected]>
Co-authored-by: Brian Fox <[email protected]>
  • Loading branch information
4 people authored Mar 23, 2024
1 parent 23a4432 commit ea02a51
Show file tree
Hide file tree
Showing 14 changed files with 372 additions and 370 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
strategy:
fail-fast: false
matrix:
argocd_version: ["v2.6.15", "v2.7.14", "v2.8.3"]
argocd_version: ["v2.8.13", "v2.9.9", "v2.10.4"]
steps:
- name: Check out code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARGOCD_INSECURE?=true
ARGOCD_SERVER?=127.0.0.1:8080
ARGOCD_AUTH_USERNAME?=admin
ARGOCD_AUTH_PASSWORD?=acceptancetesting
ARGOCD_VERSION?=v2.8.3
ARGOCD_VERSION?=v2.9.3

export

Expand Down
12 changes: 10 additions & 2 deletions argocd/resource_argocd_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func resourceArgoCDApplicationSetCreate(ctx context.Context, d *schema.ResourceD
return featureNotSupported(features.ApplicationSet)
}

objectMeta, spec, err := expandApplicationSet(d, si.IsFeatureSupported(features.MultipleApplicationSources))
objectMeta, spec, err := expandApplicationSet(d, si.IsFeatureSupported(features.MultipleApplicationSources), si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences))
if err != nil {
return errorToDiagnostics("failed to expand application set", err)
}
Expand All @@ -50,6 +50,10 @@ func resourceArgoCDApplicationSetCreate(ctx context.Context, d *schema.ResourceD
return featureNotSupported(features.ApplicationSetProgressiveSync)
}

if !si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences) && spec.IgnoreApplicationDifferences != nil {
return featureNotSupported(features.ApplicationSetIgnoreApplicationDifferences)
}

if !si.IsFeatureSupported(features.ApplicationSetApplicationsSyncPolicy) && spec.SyncPolicy != nil && spec.SyncPolicy.ApplicationsSync != nil {
return featureNotSupported(features.ApplicationSetApplicationsSyncPolicy)
}
Expand Down Expand Up @@ -122,7 +126,7 @@ func resourceArgoCDApplicationSetUpdate(ctx context.Context, d *schema.ResourceD
return nil
}

objectMeta, spec, err := expandApplicationSet(d, si.IsFeatureSupported(features.MultipleApplicationSources))
objectMeta, spec, err := expandApplicationSet(d, si.IsFeatureSupported(features.MultipleApplicationSources), si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences))
if err != nil {
return errorToDiagnostics(fmt.Sprintf("failed to expand application set %s", d.Id()), err)
}
Expand All @@ -131,6 +135,10 @@ func resourceArgoCDApplicationSetUpdate(ctx context.Context, d *schema.ResourceD
return featureNotSupported(features.ApplicationSetProgressiveSync)
}

if !si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences) && spec.IgnoreApplicationDifferences != nil {
return featureNotSupported(features.ApplicationSetIgnoreApplicationDifferences)
}

if !si.IsFeatureSupported(features.ApplicationSetApplicationsSyncPolicy) && spec.SyncPolicy != nil && spec.SyncPolicy.ApplicationsSync != nil {
return featureNotSupported(features.ApplicationSetApplicationsSyncPolicy)
}
Expand Down
10 changes: 5 additions & 5 deletions argocd/resource_argocd_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,20 @@ func resourceArgoCDClusterCreate(ctx context.Context, d *schema.ResourceData, me
// Need a full lock here to avoid race conditions between List existing clusters and creating a new one
tokenMutexClusters.Lock()

rtrimmedServer := strings.TrimRight(cluster.Server, "/")

// Cluster are unique by "server address" so we should check there is no existing cluster with this address before
existingClusters, err := si.ClusterClient.List(ctx, &clusterClient.ClusterQuery{
Id: &clusterClient.ClusterID{
Type: "server",
Value: cluster.Server, // TODO: not used by backend, upstream bug ?
Value: rtrimmedServer,
},
})

if err != nil {
tokenMutexClusters.Unlock()
return errorToDiagnostics(fmt.Sprintf("failed to list existing clusters when creating cluster %s", cluster.Server), err)
}

rtrimmedServer := strings.TrimRight(cluster.Server, "/")

if len(existingClusters.Items) > 0 {
for _, existingCluster := range existingClusters.Items {
if rtrimmedServer == strings.TrimRight(existingCluster.Server, "/") {
Expand All @@ -70,7 +69,8 @@ func resourceArgoCDClusterCreate(ctx context.Context, d *schema.ResourceData, me
}

c, err := si.ClusterClient.Create(ctx, &clusterClient.ClusterCreateRequest{
Cluster: cluster, Upsert: false})
Cluster: cluster, Upsert: false,
})
tokenMutexClusters.Unlock()

if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions argocd/resource_argocd_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestAccArgoCDCluster(t *testing.T) {
resource.TestCheckResourceAttr(
"argocd_cluster.simple",
"info.0.server_version",
"1.24",
"1.27",
),
resource.TestCheckResourceAttr(
"argocd_cluster.simple",
Expand Down Expand Up @@ -65,7 +65,7 @@ func TestAccArgoCDCluster(t *testing.T) {
resource.TestCheckResourceAttr(
"argocd_cluster.tls",
"info.0.server_version",
"1.24",
"1.27",
),
resource.TestCheckResourceAttr(
"argocd_cluster.tls",
Expand Down
14 changes: 14 additions & 0 deletions argocd/schema_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,20 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
Optional: true,
MaxItems: 1,
MinItems: 1,
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
// Avoid drift when sync_policy is empty
if k == "spec.0.sync_policy.#" {
_, hasAutomated := d.GetOk("spec.0.sync_policy.0.automated")
_, hasSyncOptions := d.GetOk("spec.0.sync_policy.0.sync_options")
_, hasRetry := d.GetOk("spec.0.sync_policy.0.retry")
_, hasManagedNamespaceMetadata := d.GetOk("spec.0.sync_policy.0.managed_namespace_metadata")

if !hasAutomated && !hasSyncOptions && !hasRetry && !hasManagedNamespaceMetadata {
return true
}
}
return false
},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"automated": {
Expand Down
30 changes: 30 additions & 0 deletions argocd/schema_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@ func applicationSetSpecSchemaV0() *schema.Schema {
Required: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ignore_application_differences": {
Type: schema.TypeList,
Description: "Application Set [ignoreApplicationDifferences](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/#ignore-certain-changes-to-applications).",
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"json_pointers": {
Type: schema.TypeSet,
Description: "Json pointers to ignore differences",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"jq_path_expressions": {
Type: schema.TypeSet,
Description: "jq path to ignore differences",
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"name": {
Type: schema.TypeString,
Description: "name",
Optional: true,
},
},
},
},
"generator": applicationSetGeneratorSchemaV0(),
"go_template": {
Type: schema.TypeBool,
Expand Down
58 changes: 55 additions & 3 deletions argocd/structure_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func expandApplicationSet(d *schema.ResourceData, featureMultipleApplicationSourcesSupported bool) (metadata meta.ObjectMeta, spec application.ApplicationSetSpec, err error) {
func expandApplicationSet(d *schema.ResourceData, featureMultipleApplicationSourcesSupported bool, featureApplicationSetIgnoreApplicationDifferences bool) (metadata meta.ObjectMeta, spec application.ApplicationSetSpec, err error) {
metadata = expandMetadata(d)
spec, err = expandApplicationSetSpec(d, featureMultipleApplicationSourcesSupported)
spec, err = expandApplicationSetSpec(d, featureMultipleApplicationSourcesSupported, featureApplicationSetIgnoreApplicationDifferences)

return
}

func expandApplicationSetSpec(d *schema.ResourceData, featureMultipleApplicationSourcesSupported bool) (spec application.ApplicationSetSpec, err error) {
func expandApplicationSetSpec(d *schema.ResourceData, featureMultipleApplicationSourcesSupported bool, featureApplicationSetIgnoreApplicationDifferences bool) (spec application.ApplicationSetSpec, err error) {
s := d.Get("spec.0").(map[string]interface{})

if v, ok := s["generator"].([]interface{}); ok && len(v) > 0 {
Expand All @@ -42,6 +42,10 @@ func expandApplicationSetSpec(d *schema.ResourceData, featureMultipleApplication
spec.SyncPolicy = expandApplicationSetSyncPolicy(v[0].(map[string]interface{}))
}

if v, ok := s["ignore_application_differences"].([]interface{}); ok && len(v) > 0 {
spec.IgnoreApplicationDifferences = expandApplicationSetIgnoreDifferences(v, featureApplicationSetIgnoreApplicationDifferences)
}

if v, ok := s["template"].([]interface{}); ok && len(v) > 0 {
spec.Template, err = expandApplicationSetTemplate(v[0], featureMultipleApplicationSourcesSupported)
if err != nil {
Expand Down Expand Up @@ -867,6 +871,39 @@ func expandApplicationSetTemplateMeta(meta interface{}) (metadata application.Ap
return metadata, nil
}

func expandApplicationSetIgnoreDifferences(ids []interface{}, featureApplicationSetIgnoreApplicationDifferences bool) (result []application.ApplicationSetResourceIgnoreDifferences) {
if !featureApplicationSetIgnoreApplicationDifferences {
return
}

for _, _id := range ids {
id := _id.(map[string]interface{})

var elem = application.ApplicationSetResourceIgnoreDifferences{}

if v, ok := id["json_pointers"]; ok {
jps := v.(*schema.Set).List()
for _, jp := range jps {
elem.JSONPointers = append(elem.JSONPointers, jp.(string))
}
}

if v, ok := id["jq_path_expressions"]; ok {
jqpes := v.(*schema.Set).List()
for _, jqpe := range jqpes {
elem.JQPathExpressions = append(elem.JQPathExpressions, jqpe.(string))
}
}

if v, ok := id["name"]; ok {
elem.Name = v.(string)
}

result = append(result, elem)
}

return //nolint:nakedret // overriding as function follows pattern in rest of file
}
func flattenApplicationSet(as *application.ApplicationSet, d *schema.ResourceData) error {
fMetadata := flattenMetadata(as.ObjectMeta, d)
if err := d.Set("metadata", fMetadata); err != nil {
Expand Down Expand Up @@ -913,9 +950,24 @@ func flattenApplicationSetSpec(s application.ApplicationSetSpec) ([]map[string]i
spec["sync_policy"] = flattenApplicationSetSyncPolicy(*s.SyncPolicy)
}

if s.IgnoreApplicationDifferences != nil {
spec["ignore_application_differences"] = flattenApplicationSetIgnoreDifferences(s.IgnoreApplicationDifferences)
}

return []map[string]interface{}{spec}, nil
}

func flattenApplicationSetIgnoreDifferences(ids application.ApplicationSetIgnoreDifferences) (result []map[string]interface{}) {
for _, id := range ids {
result = append(result, map[string]interface{}{
"name": id.Name,
"json_pointers": id.JSONPointers,
"jq_path_expressions": id.JQPathExpressions,
})
}

return
}
func flattenGenerator(g application.ApplicationSetGenerator) (map[string]interface{}, error) {
generator := map[string]interface{}{}

Expand Down
11 changes: 11 additions & 0 deletions docs/resources/application_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ Required:
Optional:

- `go_template` (Boolean) Enable use of [Go Text Template](https://pkg.go.dev/text/template).
- `ignore_application_differences` (Block List) Application Set [ignoreApplicationDifferences](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/#ignore-certain-changes-to-applications). (see [below for nested schema](#nestedblock--spec--ignore_application_differences))
- `strategy` (Block List, Max: 1) [Progressive Sync](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Progressive-Syncs/) strategy (see [below for nested schema](#nestedblock--spec--strategy))
- `sync_policy` (Block List, Max: 1) Application Set [sync policy](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/). (see [below for nested schema](#nestedblock--spec--sync_policy))

Expand Down Expand Up @@ -15524,6 +15525,16 @@ Optional:



<a id="nestedblock--spec--ignore_application_differences"></a>
### Nested Schema for `spec.ignore_application_differences`

Optional:

- `jq_path_expressions` (Set of String) jq path to ignore differences
- `json_pointers` (Set of String) Json pointers to ignore differences
- `name` (String) name


<a id="nestedblock--spec--strategy"></a>
### Nested Schema for `spec.strategy`

Expand Down
Loading

0 comments on commit ea02a51

Please sign in to comment.