github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/app_autosync_ns_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "testing" 6 7 v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 9 . "github.com/argoproj/gitops-engine/pkg/sync/common" 10 "github.com/stretchr/testify/assert" 11 "k8s.io/apimachinery/pkg/types" 12 13 . "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" 14 "github.com/argoproj/argo-cd/v2/test/e2e/fixture" 15 . "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app" 16 "github.com/argoproj/argo-cd/v2/util/errors" 17 ) 18 19 func TestNSAutoSyncSelfHealDisabled(t *testing.T) { 20 Given(t). 21 SetTrackingMethod("annotation"). 22 Path(guestbookPath). 23 SetAppNamespace(fixture.AppNamespace()). 24 // TODO: There is a bug with annotation tracking method that prevents 25 // controller from picking up changes in the cluster. 26 When(). 27 // app should be auto-synced once created 28 CreateFromFile(func(app *Application) { 29 app.Spec.SyncPolicy = &SyncPolicy{Automated: &SyncPolicyAutomated{SelfHeal: false}} 30 }). 31 Then(). 32 Expect(SyncStatusIs(SyncStatusCodeSynced)). 33 // app should be auto-synced if git change detected 34 When(). 35 PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 1}]`). 36 Refresh(RefreshTypeNormal). 37 Then(). 38 Expect(SyncStatusIs(SyncStatusCodeSynced)). 39 // app should not be auto-synced if k8s change detected 40 When(). 41 And(func() { 42 errors.FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(), 43 "guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), v1.PatchOptions{})) 44 }). 45 Then(). 46 Expect(SyncStatusIs(SyncStatusCodeOutOfSync)) 47 } 48 49 func TestNSAutoSyncSelfHealEnabled(t *testing.T) { 50 Given(t). 51 SetTrackingMethod("annotation"). 52 Path(guestbookPath). 53 SetAppNamespace(fixture.AppNamespace()). 54 When(). 55 // app should be auto-synced once created 56 CreateFromFile(func(app *Application) { 57 app.Spec.SyncPolicy = &SyncPolicy{ 58 Automated: &SyncPolicyAutomated{SelfHeal: true}, 59 Retry: &RetryStrategy{Limit: 0}, 60 } 61 }). 62 Then(). 63 Expect(OperationPhaseIs(OperationSucceeded)). 64 Expect(SyncStatusIs(SyncStatusCodeSynced)). 65 When(). 66 // app should be auto-synced once k8s change detected 67 And(func() { 68 errors.FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(context.Background(), 69 "guestbook-ui", types.MergePatchType, []byte(`{"spec": {"revisionHistoryLimit": 0}}`), v1.PatchOptions{})) 70 }). 71 Refresh(RefreshTypeNormal). 72 Then(). 73 Expect(OperationPhaseIs(OperationSucceeded)). 74 Expect(SyncStatusIs(SyncStatusCodeSynced)). 75 When(). 76 // app should be attempted to auto-synced once and marked with error after failed attempt detected 77 PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": "badValue"}]`). 78 Refresh(RefreshTypeNormal). 79 Then(). 80 Expect(OperationPhaseIs(OperationFailed)). 81 When(). 82 // Trigger refresh again to make sure controller notices previously failed sync attempt before expectation timeout expires 83 Refresh(RefreshTypeNormal). 84 Then(). 85 Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). 86 Expect(Condition(ApplicationConditionSyncError, "Failed sync attempt")). 87 When(). 88 // SyncError condition should be removed after successful sync 89 PatchFile("guestbook-ui-deployment.yaml", `[{"op": "replace", "path": "/spec/revisionHistoryLimit", "value": 1}]`). 90 Refresh(RefreshTypeNormal). 91 Then(). 92 Expect(OperationPhaseIs(OperationSucceeded)). 93 When(). 94 // Trigger refresh twice to make sure controller notices successful attempt and removes condition 95 Refresh(RefreshTypeNormal). 96 Then(). 97 Expect(SyncStatusIs(SyncStatusCodeSynced)). 98 And(func(app *Application) { 99 assert.Len(t, app.Status.Conditions, 0) 100 }) 101 102 }