Skip to content

Commit

Permalink
Populate Source not Sources for single source applications (#289)
Browse files Browse the repository at this point in the history
* fix: populate `Source` not `Sources` for single source applications

* build: bump ArgoCD versions on tests to match latest release
  • Loading branch information
onematchfox authored May 27, 2023
1 parent f5c1dce commit 13c2baa
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 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.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.3"]
argocd_version: ["v2.5.0", "v2.5.17", "v2.6.0", "v2.6.8", "v2.7.3"]
steps:
- name: Check out code
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
Expand Down
50 changes: 28 additions & 22 deletions argocd/resource_argocd_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,23 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
Detail: err.Error(),
},
}
} else if !featureMultipleApplicationSourcesSupported {
if len(spec.Sources) > 1 {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"multiple application sources is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
},
}
}
}

l := len(spec.Sources)

switch {
case l == 1:
spec.Source = &spec.Sources[0]
spec.Sources = nil
case l > 1 && !featureMultipleApplicationSourcesSupported:
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"multiple application sources is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
},
}
}

featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)
Expand Down Expand Up @@ -473,20 +476,23 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
Detail: err.Error(),
},
}
} else if !featureMultipleApplicationSourcesSupported {
if len(spec.Sources) > 1 {
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"multiple application sources is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
},
}
}
}

l := len(spec.Sources)

switch {
case l == 1:
spec.Source = &spec.Sources[0]
spec.Sources = nil
case l > 1 && !featureMultipleApplicationSourcesSupported:
return []diag.Diagnostic{
{
Severity: diag.Error,
Summary: fmt.Sprintf(
"multiple application sources is only supported from ArgoCD %s onwards",
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
},
}
}

featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)
Expand Down
9 changes: 5 additions & 4 deletions argocd/structure_application_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,13 +793,14 @@ func expandApplicationSetTemplate(temp interface{}, featureMultipleApplicationSo
return
}

if !featureMultipleApplicationSourcesSupported {
if len(template.Spec.Sources) > 1 {
return template, fmt.Errorf("multiple application sources is only supported from ArgoCD %s onwards", featureVersionConstraintsMap[featureMultipleApplicationSources].String())
}
l := len(template.Spec.Sources)

switch {
case l == 1:
template.Spec.Source = &template.Spec.Sources[0]
template.Spec.Sources = nil
case l > 1 && !featureMultipleApplicationSourcesSupported:
return template, fmt.Errorf("multiple application sources is only supported from ArgoCD %s onwards", featureVersionConstraintsMap[featureMultipleApplicationSources].String())
}
}

Expand Down

0 comments on commit 13c2baa

Please sign in to comment.