Skip to content

Commit

Permalink
fix: 'argocd app wait --suspended' stuck if operation is in progress (a…
Browse files Browse the repository at this point in the history
…rgoproj#5511)

* fix: 'argocd app wait --suspended' stuck if operation is in progress

Signed-off-by: Alexander Matyushentsev <AMatyushentsev@gmail.com>
  • Loading branch information
Alexander Matyushentsev authored Feb 19, 2021
1 parent 13b9b92 commit e1168fd
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 34 deletions.
2 changes: 1 addition & 1 deletion cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ func waitOnApplicationStatus(acdClient apiclient.Client, appName string, timeout
selectedResourcesAreReady = checkResourceStatus(watchSync, watchHealth, watchOperation, watchSuspended, string(app.Status.Health.Status), string(app.Status.Sync.Status), appEvent.Application.Operation)
}

if selectedResourcesAreReady && !operationInProgress {
if selectedResourcesAreReady && (!operationInProgress || !watchOperation) {
app = printFinalStatus(app)
return app, nil
}
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1542,3 +1542,30 @@ func TestAppLogs(t *testing.T) {
assert.NotContains(t, out, "Hi")
})
}

func TestAppWaitOperationInProgress(t *testing.T) {
Given(t).
And(func() {
SetResourceOverrides(map[string]ResourceOverride{
"batch/Job": {
HealthLua: `return { status = 'Running' }`,
},
"apps/Deployment": {
HealthLua: `return { status = 'Suspended' }`,
},
})
}).
Async(true).
Path("hook-and-deployment").
When().
Create().
Sync().
Then().
// stuck in running state
Expect(OperationPhaseIs(OperationRunning)).
When().
And(func() {
_, err := RunCli("app", "wait", Name(), "--suspended")
errors.CheckError(err)
})
}
30 changes: 19 additions & 11 deletions test/e2e/sync_waves_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

. "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
. "github.com/argoproj/argo-cd/test/e2e/fixture"
. "github.com/argoproj/argo-cd/test/e2e/fixture/app"

"github.com/argoproj/gitops-engine/pkg/health"
Expand All @@ -16,34 +17,41 @@ func TestFixingDegradedApp(t *testing.T) {
When().
IgnoreErrors().
Create().
PatchFile("pod-1.yaml", `[{"op": "replace", "path": "/spec/containers/0/image", "value": "rubbish"}]`).
And(func() {
SetResourceOverrides(map[string]ResourceOverride{
"ConfigMap": {
HealthLua: `return { status = obj.metadata.annotations and obj.metadata.annotations['health'] or 'Degraded' }`,
},
})
}).
Sync().
Then().
Expect(OperationPhaseIs(OperationFailed)).
Expect(SyncStatusIs(SyncStatusCodeOutOfSync)).
Expect(HealthIs(health.HealthStatusMissing)).
Expect(ResourceResultNumbering(1)).
Expect(ResourceSyncStatusIs("Pod", "pod-1", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("Pod", "pod-1", health.HealthStatusDegraded)).
Expect(ResourceSyncStatusIs("Pod", "pod-2", SyncStatusCodeOutOfSync)).
Expect(ResourceHealthIs("Pod", "pod-2", health.HealthStatusMissing)).
Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("ConfigMap", "cm-1", health.HealthStatusDegraded)).
Expect(ResourceSyncStatusIs("ConfigMap", "cm-2", SyncStatusCodeOutOfSync)).
Expect(ResourceHealthIs("ConfigMap", "cm-2", health.HealthStatusMissing)).
When().
PatchFile("pod-1.yaml", `[{"op": "replace", "path": "/spec/containers/0/image", "value": "nginx:1.17.4-alpine"}]`).
PatchFile("cm-1.yaml", `[{"op": "replace", "path": "/metadata/annotations/health", "value": "Healthy"}]`).
PatchFile("cm-2.yaml", `[{"op": "replace", "path": "/metadata/annotations/health", "value": "Healthy"}]`).
// need to force a refresh here
Refresh(RefreshTypeNormal).
Then().
Expect(ResourceSyncStatusIs("Pod", "pod-1", SyncStatusCodeOutOfSync)).
Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeOutOfSync)).
When().
Sync().
Then().
Expect(OperationPhaseIs(OperationSucceeded)).
Expect(SyncStatusIs(SyncStatusCodeSynced)).
Expect(HealthIs(health.HealthStatusHealthy)).
Expect(ResourceResultNumbering(2)).
Expect(ResourceSyncStatusIs("Pod", "pod-1", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("Pod", "pod-1", health.HealthStatusHealthy)).
Expect(ResourceSyncStatusIs("Pod", "pod-2", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("Pod", "pod-2", health.HealthStatusHealthy))
Expect(ResourceSyncStatusIs("ConfigMap", "cm-1", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("ConfigMap", "cm-1", health.HealthStatusHealthy)).
Expect(ResourceSyncStatusIs("ConfigMap", "cm-2", SyncStatusCodeSynced)).
Expect(ResourceHealthIs("ConfigMap", "cm-2", health.HealthStatusHealthy))
}

func TestOneProgressingDeploymentIsSucceededAndSynced(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/testdata/sync-waves/cm-1.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cm-1
annotations:
argocd.argoproj.io/sync-wave: "1"
6 changes: 6 additions & 0 deletions test/e2e/testdata/sync-waves/cm-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: cm-2
annotations:
argocd.argoproj.io/sync-wave: "2"
11 changes: 0 additions & 11 deletions test/e2e/testdata/sync-waves/pod-1.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions test/e2e/testdata/sync-waves/pod-2.yaml

This file was deleted.

0 comments on commit e1168fd

Please sign in to comment.