Skip to content

Commit 13c2baa

Browse files
authored
Populate Source not Sources for single source applications (#289)
* fix: populate `Source` not `Sources` for single source applications * build: bump ArgoCD versions on tests to match latest release
1 parent f5c1dce commit 13c2baa

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
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.5.0", "v2.5.16", "v2.6.0", "v2.6.7", "v2.7.3"]
51+
argocd_version: ["v2.5.0", "v2.5.17", "v2.6.0", "v2.6.8", "v2.7.3"]
5252
steps:
5353
- name: Check out code
5454
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

argocd/resource_argocd_application.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -200,20 +200,23 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
200200
Detail: err.Error(),
201201
},
202202
}
203-
} else if !featureMultipleApplicationSourcesSupported {
204-
if len(spec.Sources) > 1 {
205-
return []diag.Diagnostic{
206-
{
207-
Severity: diag.Error,
208-
Summary: fmt.Sprintf(
209-
"multiple application sources is only supported from ArgoCD %s onwards",
210-
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
211-
},
212-
}
213-
}
203+
}
204+
205+
l := len(spec.Sources)
214206

207+
switch {
208+
case l == 1:
215209
spec.Source = &spec.Sources[0]
216210
spec.Sources = nil
211+
case l > 1 && !featureMultipleApplicationSourcesSupported:
212+
return []diag.Diagnostic{
213+
{
214+
Severity: diag.Error,
215+
Summary: fmt.Sprintf(
216+
"multiple application sources is only supported from ArgoCD %s onwards",
217+
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
218+
},
219+
}
217220
}
218221

219222
featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)
@@ -473,20 +476,23 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
473476
Detail: err.Error(),
474477
},
475478
}
476-
} else if !featureMultipleApplicationSourcesSupported {
477-
if len(spec.Sources) > 1 {
478-
return []diag.Diagnostic{
479-
{
480-
Severity: diag.Error,
481-
Summary: fmt.Sprintf(
482-
"multiple application sources is only supported from ArgoCD %s onwards",
483-
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
484-
},
485-
}
486-
}
479+
}
480+
481+
l := len(spec.Sources)
487482

483+
switch {
484+
case l == 1:
488485
spec.Source = &spec.Sources[0]
489486
spec.Sources = nil
487+
case l > 1 && !featureMultipleApplicationSourcesSupported:
488+
return []diag.Diagnostic{
489+
{
490+
Severity: diag.Error,
491+
Summary: fmt.Sprintf(
492+
"multiple application sources is only supported from ArgoCD %s onwards",
493+
featureVersionConstraintsMap[featureMultipleApplicationSources].String()),
494+
},
495+
}
490496
}
491497

492498
featureApplicationHelmSkipCrdsSupported, err := si.isFeatureSupported(featureApplicationHelmSkipCrds)

argocd/structure_application_set.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,14 @@ func expandApplicationSetTemplate(temp interface{}, featureMultipleApplicationSo
793793
return
794794
}
795795

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

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

0 commit comments

Comments
 (0)