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