Skip to content

Commit 1d82878

Browse files
authored
Fix support for application resource on latest versions of ArgoCD (#240)
1 parent 453fe73 commit 1d82878

File tree

7 files changed

+74
-50
lines changed

7 files changed

+74
-50
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
strategy:
5050
fail-fast: false
5151
matrix:
52-
argocd_version: ["v2.5.0", "v2.4.12", "v2.3.9"]
52+
argocd_version: ["v2.4.0", "v2.4.28", "v2.5.0", "v2.5.16", "v2.6.0", "v2.6.7"]
5353
steps:
5454
- name: Check out code
5555
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ARGOCD_SERVER?=127.0.0.1:8080
55
ARGOCD_AUTH_USERNAME?=admin
66
ARGOCD_AUTH_PASSWORD?=acceptancetesting
77
ARGOCD_CONTEXT?=kind-argocd
8-
ARGOCD_VERSION?=v2.5.0
8+
ARGOCD_VERSION?=v2.6.7
99

1010
export
1111

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,6 @@ make testacc
103103
make testacc_clean_env
104104
```
105105

106-
**Note:** to speed up testing environment setup, it is highly recommended you
107-
pull all needed container images into your local registry first, as the setup
108-
tries to sideload the images within the Kind cluster upon cluster creation.
109-
110-
For example if you use Docker as your local container runtime:
111-
```shell
112-
docker pull quay.io/argoproj/argocd:v2.5.0
113-
docker pull ghcr.io/dexidp/dex:v2.27.0
114-
docker pull redis:6.2.4-alpine
115-
docker pull alpine:3
116-
```
117-
118106
### Generating documentation
119107

120108
This provider uses [terraform-plugin-docs](https://github.com/hashicorp/terraform-plugin-docs/)

argocd/features.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var featureVersionConstraintsMap = map[int]*semver.Version{
4343
featureClusterMetadata: semver.MustParse("2.2.0"),
4444
featureRepositoryCertificates: semver.MustParse("1.2.0"),
4545
featureApplicationHelmSkipCrds: semver.MustParse("2.3.0"),
46-
featureExecLogsPolicy: semver.MustParse("2.4.0"),
46+
featureExecLogsPolicy: semver.MustParse("2.4.4"),
4747
featureProjectSourceNamespaces: semver.MustParse("2.5.0"),
4848
}
4949

argocd/resource_argocd_application.go

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
8989
}
9090
}
9191
c := *server.ApplicationClient
92-
app, err := c.Get(ctx, &applicationClient.ApplicationQuery{
92+
apps, err := c.List(ctx, &applicationClient.ApplicationQuery{
9393
Name: &objectMeta.Name,
9494
AppNamespace: &objectMeta.Namespace,
9595
})
@@ -102,12 +102,22 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
102102
},
103103
}
104104
}
105-
if app != nil {
106-
switch app.DeletionTimestamp {
105+
if apps != nil {
106+
if len(apps.Items) != 1 {
107+
return []diag.Diagnostic{
108+
{
109+
Severity: diag.Error,
110+
Summary: fmt.Sprintf("found multiple applications matching name '%s' and namespace '%s'", objectMeta.Name, objectMeta.Namespace),
111+
Detail: err.Error(),
112+
},
113+
}
114+
}
115+
116+
switch apps.Items[0].DeletionTimestamp {
107117
case nil:
108118
default:
109119
// Pre-existing app is still in Kubernetes soft deletion queue
110-
time.Sleep(time.Duration(*app.DeletionGracePeriodSeconds))
120+
time.Sleep(time.Duration(*apps.Items[0].DeletionGracePeriodSeconds))
111121
}
112122
}
113123

@@ -190,7 +200,7 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
190200
}
191201
}
192202

193-
app, err = c.Create(ctx, &applicationClient.ApplicationCreateRequest{
203+
app, err := c.Create(ctx, &applicationClient.ApplicationCreateRequest{
194204
Application: &application.Application{
195205
ObjectMeta: objectMeta,
196206
Spec: spec,
@@ -222,18 +232,21 @@ func resourceArgoCDApplicationCreate(ctx context.Context, d *schema.ResourceData
222232

223233
if wait, ok := d.GetOk("wait"); ok && wait.(bool) {
224234
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *resource.RetryError {
225-
a, err := c.Get(ctx, &applicationClient.ApplicationQuery{
235+
list, err := c.List(ctx, &applicationClient.ApplicationQuery{
226236
Name: &app.Name,
227237
AppNamespace: &app.Namespace,
228238
})
229239
if err != nil {
230240
return resource.NonRetryableError(fmt.Errorf("error while waiting for application %s to be synced and healthy: %s", app.Name, err))
231241
}
232-
if a.Status.Health.Status != health.HealthStatusHealthy {
233-
return resource.RetryableError(fmt.Errorf("expected application health status to be healthy but was %s", a.Status.Health.Status))
242+
if len(list.Items) != 1 {
243+
return resource.NonRetryableError(fmt.Errorf("found multiple applications matching name '%s' and namespace '%s'", app.Name, app.Namespace))
244+
}
245+
if list.Items[0].Status.Health.Status != health.HealthStatusHealthy {
246+
return resource.RetryableError(fmt.Errorf("expected application health status to be healthy but was %s", list.Items[0].Status.Health.Status))
234247
}
235-
if a.Status.Sync.Status != application.SyncStatusCodeSynced {
236-
return resource.RetryableError(fmt.Errorf("expected application sync status to be synced but was %s", a.Status.Sync.Status))
248+
if list.Items[0].Status.Sync.Status != application.SyncStatusCodeSynced {
249+
return resource.RetryableError(fmt.Errorf("expected application sync status to be synced but was %s", list.Items[0].Status.Sync.Status))
237250
}
238251
return nil
239252
})
@@ -268,7 +281,7 @@ func resourceArgoCDApplicationRead(ctx context.Context, d *schema.ResourceData,
268281
appName := ids[0]
269282
namespace := ids[1]
270283

271-
app, err := c.Get(ctx, &applicationClient.ApplicationQuery{
284+
apps, err := c.List(ctx, &applicationClient.ApplicationQuery{
272285
Name: &appName,
273286
AppNamespace: &namespace,
274287
})
@@ -285,7 +298,16 @@ func resourceArgoCDApplicationRead(ctx context.Context, d *schema.ResourceData,
285298
},
286299
}
287300
}
288-
err = flattenApplication(app, d)
301+
if len(apps.Items) != 1 {
302+
return []diag.Diagnostic{
303+
{
304+
Severity: diag.Error,
305+
Summary: fmt.Sprintf("found multiple applications matching name '%s' and namespace '%s'", appName, namespace),
306+
Detail: err.Error(),
307+
},
308+
}
309+
}
310+
err = flattenApplication(&apps.Items[0], d)
289311
if err != nil {
290312
return []diag.Diagnostic{
291313
{
@@ -407,11 +429,11 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
407429
}
408430
}
409431
}
410-
app, err := c.Get(ctx, &applicationClient.ApplicationQuery{
432+
apps, err := c.List(ctx, &applicationClient.ApplicationQuery{
411433
Name: &appName,
412434
AppNamespace: &namespace,
413435
})
414-
if app != nil {
436+
if apps != nil {
415437
// Kubernetes API requires providing the up-to-date correct ResourceVersion for updates
416438
// FIXME ResourceVersion not available anymore
417439
// appRequest.ResourceVersion = app.ResourceVersion
@@ -428,18 +450,21 @@ func resourceArgoCDApplicationUpdate(ctx context.Context, d *schema.ResourceData
428450
}
429451
if wait, _ok := d.GetOk("wait"); _ok && wait.(bool) {
430452
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *resource.RetryError {
431-
a, err := c.Get(ctx, &applicationClient.ApplicationQuery{
432-
Name: &app.Name,
433-
AppNamespace: &app.Namespace,
453+
list, err := c.List(ctx, &applicationClient.ApplicationQuery{
454+
Name: &appName,
455+
AppNamespace: &namespace,
434456
})
435457
if err != nil {
436-
return resource.NonRetryableError(fmt.Errorf("error while waiting for application %s to be synced and healthy: %s", app.Name, err))
458+
return resource.NonRetryableError(fmt.Errorf("error while waiting for application %s to be synced and healthy: %s", list.Items[0].Name, err))
459+
}
460+
if len(list.Items) != 1 {
461+
return resource.NonRetryableError(fmt.Errorf("found multiple applications matching name '%s' and namespace '%s'", appName, namespace))
437462
}
438-
if a.Status.Health.Status != health.HealthStatusHealthy {
439-
return resource.RetryableError(fmt.Errorf("expected application health status to be healthy but was %s", a.Status.Health.Status))
463+
if list.Items[0].Status.Health.Status != health.HealthStatusHealthy {
464+
return resource.RetryableError(fmt.Errorf("expected application health status to be healthy but was %s", list.Items[0].Status.Health.Status))
440465
}
441-
if a.Status.Sync.Status != application.SyncStatusCodeSynced {
442-
return resource.RetryableError(fmt.Errorf("expected application sync status to be synced but was %s", a.Status.Sync.Status))
466+
if list.Items[0].Status.Sync.Status != application.SyncStatusCodeSynced {
467+
return resource.RetryableError(fmt.Errorf("expected application sync status to be synced but was %s", list.Items[0].Status.Sync.Status))
443468
}
444469
return nil
445470
})
@@ -489,7 +514,7 @@ func resourceArgoCDApplicationDelete(ctx context.Context, d *schema.ResourceData
489514
}
490515
if wait, ok := d.GetOk("wait"); ok && wait.(bool) {
491516
err = resource.RetryContext(ctx, d.Timeout(schema.TimeoutDelete), func() *resource.RetryError {
492-
_, err := c.Get(ctx, &applicationClient.ApplicationQuery{
517+
_, err := c.List(ctx, &applicationClient.ApplicationQuery{
493518
Name: &appName,
494519
AppNamespace: &namespace,
495520
})

argocd/resource_argocd_cluster_test.go

Lines changed: 2 additions & 2 deletions
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.23",
37+
"1.24",
3838
),
3939
resource.TestCheckResourceAttr(
4040
"argocd_cluster.simple",
@@ -66,7 +66,7 @@ func TestAccArgoCDCluster(t *testing.T) {
6666
resource.TestCheckResourceAttr(
6767
"argocd_cluster.tls",
6868
"info.0.server_version",
69-
"1.23",
69+
"1.24",
7070
),
7171
resource.TestCheckResourceAttr(
7272
"argocd_cluster.tls",

scripts/testacc_prepare_env.sh

100644100755
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,39 @@
33

44
export PATH=$PATH:.
55

6+
argocd_version=${ARGOCD_VERSION:-v2.6.7}
7+
k8s_version=${ARGOCD_KUBERNETES_VERSION:-v1.24.7}
8+
69
echo "\n--- Kustomize sanity checks\n"
710
kustomize version || exit 1
811

912
echo "\n--- Create Kind cluster\n"
10-
kind create cluster --name argocd --config scripts/kind-config.yml --image kindest/node:${ARGOCD_KUBERNETES_VERSION:-v1.23.12}
13+
kind create cluster --name argocd --config scripts/kind-config.yml --image kindest/node:$k8s_version
1114

1215
echo "\n--- Kind sanity checks\n"
1316
kubectl get nodes -o wide
1417
kubectl get pods --all-namespaces -o wide
1518
kubectl get services --all-namespaces -o wide
1619

17-
if [[ -z "${ARGOCD_CI}" ]]; then
18-
echo "\n--- Load already available container images from local registry into Kind (local development only)\n"
19-
kind load docker-image redis:6.2.4-alpine --name argocd
20-
kind load docker-image ghcr.io/dexidp/dex:v2.27.0 --name argocd
21-
kind load docker-image alpine:3 --name argocd
22-
kind load docker-image quay.io/argoproj/argocd:${ARGOCD_VERSION:-v2.5.0} --name argocd
20+
echo "\n--- Fetch ArgoCD installation manifests\n"
21+
curl https://raw.githubusercontent.com/argoproj/argo-cd/$argocd_version/manifests/install.yaml > manifests/install/argocd.yml
22+
23+
if [ -z "${ARGOCD_CI}" ]; then
24+
echo "\n--- Load local container images from into Kind (local development only)\n"
25+
docker pull quay.io/argoproj/argocd:$argocd_version
26+
kind load docker-image quay.io/argoproj/argocd:$argocd_version --name argocd
27+
28+
dex_version=$(cat manifests/install/argocd.yml| grep "image: ghcr.io/dexidp/dex" | cut -d":" -f3)
29+
docker pull ghcr.io/dexidp/dex:$dex_version
30+
kind load docker-image ghcr.io/dexidp/dex:$dex_version --name argocd
31+
32+
redis_version=$(cat manifests/install/argocd.yml| grep "image: redis" | cut -d":" -f3)
33+
docker pull redis:$redis_version
34+
kind load docker-image redis:$redis_version --name argocd
2335
fi
2436

25-
echo "\n--- Install ArgoCD ${ARGOCD_VERSION:-v2.5.0}\n"
26-
curl https://raw.githubusercontent.com/argoproj/argo-cd/${ARGOCD_VERSION:-v2.5.0}/manifests/install.yaml > manifests/install/argocd.yml && \
27-
kustomize build manifests/install | kubectl apply -f - && \
37+
echo "\n--- Install ArgoCD $argocd_version\n"
38+
kustomize build manifests/install | kubectl apply -f - && \
2839
kubectl apply -f manifests/testdata/
2940

3041
echo "\n--- Wait for ArgoCD components to be ready...\n"

0 commit comments

Comments
 (0)