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

Add ignore_application_differences to argocd_application_set resource #357

Merged
merged 18 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a66d0a3
feat(argocd_applicationset): add ignore_application_differences attri…
dtrouillet Dec 12, 2023
271126c
feat(argocd_applicationset): remove unnecessary if condition
dtrouillet Dec 12, 2023
1750c5c
doc(argocd_applicationset): fix documentation application_set
dtrouillet Dec 12, 2023
87296b6
chores(argocd): add ArgoCD 2.9.3 to matrix test
dtrouillet Dec 12, 2023
df78c47
build(deps): Bump github.com/go-git/go-git/v5 from 5.7.0 to 5.11.0 (#…
dependabot[bot] Jan 11, 2024
3cb8cca
build(deps): Bump github.com/argoproj/argo-cd/v2 from 2.8.3 to 2.8.8 …
dependabot[bot] Feb 5, 2024
b7d4a30
fix: Add DiffSuppressFunc on argocd_cluster.server (#353)
mkilchhofer Feb 5, 2024
59f0a64
build(deps): Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#358)
dependabot[bot] Feb 5, 2024
16d72a6
build(deps): Bump github.com/cloudflare/circl from 1.3.3 to 1.3.7 (#364)
dependabot[bot] Feb 5, 2024
fee0d1b
Merge branch 'feature/ignoreApplicationDifferences' into feature/upda…
dtrouillet Feb 20, 2024
adf40ce
Merge branch 'master' into feature/ignoreApplicationDifferences
dtrouillet Feb 20, 2024
becf3e8
Merge branch 'master' into feature/ignoreApplicationDifferences
onematchfox Mar 23, 2024
3867112
build(deps-dev): bump test versions of ArgoCD to latest patch versions
onematchfox Mar 23, 2024
0d7b084
build(deps-dev): bump test versions of k8s
onematchfox Mar 23, 2024
1eed29c
build(deps): bump github.com/argoproj/argo-cd/v2 from 2.9.3 to 2.9.9
onematchfox Mar 23, 2024
75d49c4
build(deps): bump k8s modules to align with argocd version
onematchfox Mar 23, 2024
fa6f80a
fix: call cluster list endpoint with trimmed server
onematchfox Mar 23, 2024
937cae9
fix: add diff suppression for empty sync policy on application
onematchfox Mar 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading