Skip to content

Commit ea02a51

Browse files
dtrouilletdependabot[bot]mkilchhoferonematchfox
authored
Add ignore_application_differences to argocd_application_set resource (argoproj-labs#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 (argoproj-labs#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 (argoproj-labs#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 (argoproj-labs#353) * build(deps): Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (argoproj-labs#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 (argoproj-labs#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]>
1 parent 23a4432 commit ea02a51

14 files changed

+372
-370
lines changed

.github/workflows/tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
strategy:
4949
fail-fast: false
5050
matrix:
51-
argocd_version: ["v2.6.15", "v2.7.14", "v2.8.3"]
51+
argocd_version: ["v2.8.13", "v2.9.9", "v2.10.4"]
5252
steps:
5353
- name: Check out code
5454
uses: actions/checkout@v4

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ARGOCD_INSECURE?=true
44
ARGOCD_SERVER?=127.0.0.1:8080
55
ARGOCD_AUTH_USERNAME?=admin
66
ARGOCD_AUTH_PASSWORD?=acceptancetesting
7-
ARGOCD_VERSION?=v2.8.3
7+
ARGOCD_VERSION?=v2.9.3
88

99
export
1010

argocd/resource_argocd_application_set.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func resourceArgoCDApplicationSetCreate(ctx context.Context, d *schema.ResourceD
4141
return featureNotSupported(features.ApplicationSet)
4242
}
4343

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

53+
if !si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences) && spec.IgnoreApplicationDifferences != nil {
54+
return featureNotSupported(features.ApplicationSetIgnoreApplicationDifferences)
55+
}
56+
5357
if !si.IsFeatureSupported(features.ApplicationSetApplicationsSyncPolicy) && spec.SyncPolicy != nil && spec.SyncPolicy.ApplicationsSync != nil {
5458
return featureNotSupported(features.ApplicationSetApplicationsSyncPolicy)
5559
}
@@ -122,7 +126,7 @@ func resourceArgoCDApplicationSetUpdate(ctx context.Context, d *schema.ResourceD
122126
return nil
123127
}
124128

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

138+
if !si.IsFeatureSupported(features.ApplicationSetIgnoreApplicationDifferences) && spec.IgnoreApplicationDifferences != nil {
139+
return featureNotSupported(features.ApplicationSetIgnoreApplicationDifferences)
140+
}
141+
134142
if !si.IsFeatureSupported(features.ApplicationSetApplicationsSyncPolicy) && spec.SyncPolicy != nil && spec.SyncPolicy.ApplicationsSync != nil {
135143
return featureNotSupported(features.ApplicationSetApplicationsSyncPolicy)
136144
}

argocd/resource_argocd_cluster.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ func resourceArgoCDClusterCreate(ctx context.Context, d *schema.ResourceData, me
3939
// Need a full lock here to avoid race conditions between List existing clusters and creating a new one
4040
tokenMutexClusters.Lock()
4141

42+
rtrimmedServer := strings.TrimRight(cluster.Server, "/")
43+
4244
// Cluster are unique by "server address" so we should check there is no existing cluster with this address before
4345
existingClusters, err := si.ClusterClient.List(ctx, &clusterClient.ClusterQuery{
4446
Id: &clusterClient.ClusterID{
4547
Type: "server",
46-
Value: cluster.Server, // TODO: not used by backend, upstream bug ?
48+
Value: rtrimmedServer,
4749
},
4850
})
49-
5051
if err != nil {
5152
tokenMutexClusters.Unlock()
5253
return errorToDiagnostics(fmt.Sprintf("failed to list existing clusters when creating cluster %s", cluster.Server), err)
5354
}
5455

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

7271
c, err := si.ClusterClient.Create(ctx, &clusterClient.ClusterCreateRequest{
73-
Cluster: cluster, Upsert: false})
72+
Cluster: cluster, Upsert: false,
73+
})
7474
tokenMutexClusters.Unlock()
7575

7676
if err != nil {

argocd/resource_argocd_cluster_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestAccArgoCDCluster(t *testing.T) {
3434
resource.TestCheckResourceAttr(
3535
"argocd_cluster.simple",
3636
"info.0.server_version",
37-
"1.24",
37+
"1.27",
3838
),
3939
resource.TestCheckResourceAttr(
4040
"argocd_cluster.simple",
@@ -65,7 +65,7 @@ func TestAccArgoCDCluster(t *testing.T) {
6565
resource.TestCheckResourceAttr(
6666
"argocd_cluster.tls",
6767
"info.0.server_version",
68-
"1.24",
68+
"1.27",
6969
),
7070
resource.TestCheckResourceAttr(
7171
"argocd_cluster.tls",

argocd/schema_application.go

+14
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,20 @@ func applicationSpecSchemaV4(allOptional bool) *schema.Schema {
15981598
Optional: true,
15991599
MaxItems: 1,
16001600
MinItems: 1,
1601+
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
1602+
// Avoid drift when sync_policy is empty
1603+
if k == "spec.0.sync_policy.#" {
1604+
_, hasAutomated := d.GetOk("spec.0.sync_policy.0.automated")
1605+
_, hasSyncOptions := d.GetOk("spec.0.sync_policy.0.sync_options")
1606+
_, hasRetry := d.GetOk("spec.0.sync_policy.0.retry")
1607+
_, hasManagedNamespaceMetadata := d.GetOk("spec.0.sync_policy.0.managed_namespace_metadata")
1608+
1609+
if !hasAutomated && !hasSyncOptions && !hasRetry && !hasManagedNamespaceMetadata {
1610+
return true
1611+
}
1612+
}
1613+
return false
1614+
},
16011615
Elem: &schema.Resource{
16021616
Schema: map[string]*schema.Schema{
16031617
"automated": {

argocd/schema_application_set.go

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,36 @@ func applicationSetSpecSchemaV0() *schema.Schema {
1515
Required: true,
1616
Elem: &schema.Resource{
1717
Schema: map[string]*schema.Schema{
18+
"ignore_application_differences": {
19+
Type: schema.TypeList,
20+
Description: "Application Set [ignoreApplicationDifferences](https://argo-cd.readthedocs.io/en/stable/operator-manual/applicationset/Controlling-Resource-Modification/#ignore-certain-changes-to-applications).",
21+
Optional: true,
22+
Elem: &schema.Resource{
23+
Schema: map[string]*schema.Schema{
24+
"json_pointers": {
25+
Type: schema.TypeSet,
26+
Description: "Json pointers to ignore differences",
27+
Optional: true,
28+
Elem: &schema.Schema{
29+
Type: schema.TypeString,
30+
},
31+
},
32+
"jq_path_expressions": {
33+
Type: schema.TypeSet,
34+
Description: "jq path to ignore differences",
35+
Optional: true,
36+
Elem: &schema.Schema{
37+
Type: schema.TypeString,
38+
},
39+
},
40+
"name": {
41+
Type: schema.TypeString,
42+
Description: "name",
43+
Optional: true,
44+
},
45+
},
46+
},
47+
},
1848
"generator": applicationSetGeneratorSchemaV0(),
1949
"go_template": {
2050
Type: schema.TypeBool,

argocd/structure_application_set.go

+55-3
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import (
1212
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
)
1414

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

1919
return
2020
}
2121

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

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

45+
if v, ok := s["ignore_application_differences"].([]interface{}); ok && len(v) > 0 {
46+
spec.IgnoreApplicationDifferences = expandApplicationSetIgnoreDifferences(v, featureApplicationSetIgnoreApplicationDifferences)
47+
}
48+
4549
if v, ok := s["template"].([]interface{}); ok && len(v) > 0 {
4650
spec.Template, err = expandApplicationSetTemplate(v[0], featureMultipleApplicationSourcesSupported)
4751
if err != nil {
@@ -867,6 +871,39 @@ func expandApplicationSetTemplateMeta(meta interface{}) (metadata application.Ap
867871
return metadata, nil
868872
}
869873

874+
func expandApplicationSetIgnoreDifferences(ids []interface{}, featureApplicationSetIgnoreApplicationDifferences bool) (result []application.ApplicationSetResourceIgnoreDifferences) {
875+
if !featureApplicationSetIgnoreApplicationDifferences {
876+
return
877+
}
878+
879+
for _, _id := range ids {
880+
id := _id.(map[string]interface{})
881+
882+
var elem = application.ApplicationSetResourceIgnoreDifferences{}
883+
884+
if v, ok := id["json_pointers"]; ok {
885+
jps := v.(*schema.Set).List()
886+
for _, jp := range jps {
887+
elem.JSONPointers = append(elem.JSONPointers, jp.(string))
888+
}
889+
}
890+
891+
if v, ok := id["jq_path_expressions"]; ok {
892+
jqpes := v.(*schema.Set).List()
893+
for _, jqpe := range jqpes {
894+
elem.JQPathExpressions = append(elem.JQPathExpressions, jqpe.(string))
895+
}
896+
}
897+
898+
if v, ok := id["name"]; ok {
899+
elem.Name = v.(string)
900+
}
901+
902+
result = append(result, elem)
903+
}
904+
905+
return //nolint:nakedret // overriding as function follows pattern in rest of file
906+
}
870907
func flattenApplicationSet(as *application.ApplicationSet, d *schema.ResourceData) error {
871908
fMetadata := flattenMetadata(as.ObjectMeta, d)
872909
if err := d.Set("metadata", fMetadata); err != nil {
@@ -913,9 +950,24 @@ func flattenApplicationSetSpec(s application.ApplicationSetSpec) ([]map[string]i
913950
spec["sync_policy"] = flattenApplicationSetSyncPolicy(*s.SyncPolicy)
914951
}
915952

953+
if s.IgnoreApplicationDifferences != nil {
954+
spec["ignore_application_differences"] = flattenApplicationSetIgnoreDifferences(s.IgnoreApplicationDifferences)
955+
}
956+
916957
return []map[string]interface{}{spec}, nil
917958
}
918959

960+
func flattenApplicationSetIgnoreDifferences(ids application.ApplicationSetIgnoreDifferences) (result []map[string]interface{}) {
961+
for _, id := range ids {
962+
result = append(result, map[string]interface{}{
963+
"name": id.Name,
964+
"json_pointers": id.JSONPointers,
965+
"jq_path_expressions": id.JQPathExpressions,
966+
})
967+
}
968+
969+
return
970+
}
919971
func flattenGenerator(g application.ApplicationSetGenerator) (map[string]interface{}, error) {
920972
generator := map[string]interface{}{}
921973

docs/resources/application_set.md

+11
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ Required:
598598
Optional:
599599

600600
- `go_template` (Boolean) Enable use of [Go Text Template](https://pkg.go.dev/text/template).
601+
- `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))
601602
- `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))
602603
- `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))
603604

@@ -15524,6 +15525,16 @@ Optional:
1552415525

1552515526

1552615527

15528+
<a id="nestedblock--spec--ignore_application_differences"></a>
15529+
### Nested Schema for `spec.ignore_application_differences`
15530+
15531+
Optional:
15532+
15533+
- `jq_path_expressions` (Set of String) jq path to ignore differences
15534+
- `json_pointers` (Set of String) Json pointers to ignore differences
15535+
- `name` (String) name
15536+
15537+
1552715538
<a id="nestedblock--spec--strategy"></a>
1552815539
### Nested Schema for `spec.strategy`
1552915540

0 commit comments

Comments
 (0)