github.com/argoproj/argo-cd@v1.8.7/test/e2e/selective_sync_test.go (about) 1 package e2e 2 3 import ( 4 "fmt" 5 "strings" 6 "testing" 7 8 "github.com/argoproj/gitops-engine/pkg/health" 9 . "github.com/argoproj/gitops-engine/pkg/sync/common" 10 11 . "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" 12 "github.com/argoproj/argo-cd/test/e2e/fixture" 13 . "github.com/argoproj/argo-cd/test/e2e/fixture" 14 . "github.com/argoproj/argo-cd/test/e2e/fixture/app" 15 . "github.com/argoproj/argo-cd/util/errors" 16 "github.com/argoproj/argo-cd/util/rand" 17 ) 18 19 // when you selectively sync, only selected resources should be synced, but the app will be out of sync 20 func TestSelectiveSync(t *testing.T) { 21 Given(t). 22 Path("guestbook"). 23 SelectedResource(":Service:guestbook-ui"). 24 When(). 25 Create(). 26 Sync(). 27 Then(). 28 Expect(Success("")). 29 Expect(OperationPhaseIs(OperationSucceeded)). 30 Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). 31 Expect(ResourceHealthIs("Service", "guestbook-ui", health.HealthStatusHealthy)). 32 Expect(ResourceHealthIs("Deployment", "guestbook-ui", health.HealthStatusMissing)) 33 } 34 35 // when running selective sync, hooks do not run 36 // hooks don't run even if all resources are selected 37 func TestSelectiveSyncDoesNotRunHooks(t *testing.T) { 38 Given(t). 39 Path("hook"). 40 SelectedResource(":Pod:pod"). 41 When(). 42 Create(). 43 Sync(). 44 Then(). 45 Expect(Success("")). 46 Expect(OperationPhaseIs(OperationSucceeded)). 47 Expect(SyncStatusIs(SyncStatusCodeSynced)). 48 Expect(HealthIs(health.HealthStatusHealthy)). 49 Expect(ResourceHealthIs("Pod", "pod", health.HealthStatusHealthy)). 50 Expect(ResourceResultNumbering(1)) 51 } 52 53 func TestSelectiveSyncWithoutNamespace(t *testing.T) { 54 selectedResourceNamespace := getNewNamespace(t) 55 defer func() { 56 FailOnErr(Run("", "kubectl", "delete", "namespace", selectedResourceNamespace)) 57 }() 58 Given(t). 59 Prune(true). 60 Path("guestbook-with-namespace"). 61 And(func() { 62 FailOnErr(Run("", "kubectl", "create", "namespace", selectedResourceNamespace)) 63 }). 64 SelectedResource("apps:Deployment:guestbook-ui"). 65 When(). 66 PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). 67 PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). 68 Create(). 69 Sync(). 70 Then(). 71 Expect(Success("")). 72 Expect(OperationPhaseIs(OperationSucceeded)). 73 Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). 74 Expect(ResourceHealthWithNamespaceIs("Deployment", "guestbook-ui", selectedResourceNamespace, health.HealthStatusHealthy)). 75 Expect(ResourceHealthWithNamespaceIs("Deployment", "guestbook-ui", fixture.DeploymentNamespace(), health.HealthStatusHealthy)). 76 Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", selectedResourceNamespace, SyncStatusCodeSynced)). 77 Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", fixture.DeploymentNamespace(), SyncStatusCodeSynced)) 78 } 79 80 //In selectedResource to sync, namespace is provided 81 func TestSelectiveSyncWithNamespace(t *testing.T) { 82 selectedResourceNamespace := getNewNamespace(t) 83 defer func() { 84 FailOnErr(Run("", "kubectl", "delete", "namespace", selectedResourceNamespace)) 85 }() 86 Given(t). 87 Prune(true). 88 Path("guestbook-with-namespace"). 89 And(func() { 90 FailOnErr(Run("", "kubectl", "create", "namespace", selectedResourceNamespace)) 91 }). 92 SelectedResource(fmt.Sprintf("apps:Deployment:%s/guestbook-ui", selectedResourceNamespace)). 93 When(). 94 PatchFile("guestbook-ui-deployment-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). 95 PatchFile("guestbook-ui-svc-ns.yaml", fmt.Sprintf(`[{"op": "replace", "path": "/metadata/namespace", "value": "%s"}]`, selectedResourceNamespace)). 96 Create(). 97 Sync(). 98 Then(). 99 Expect(Success("")). 100 Expect(OperationPhaseIs(OperationSucceeded)). 101 Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). 102 Expect(ResourceHealthWithNamespaceIs("Deployment", "guestbook-ui", selectedResourceNamespace, health.HealthStatusHealthy)). 103 Expect(ResourceHealthWithNamespaceIs("Deployment", "guestbook-ui", fixture.DeploymentNamespace(), health.HealthStatusMissing)). 104 Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", selectedResourceNamespace, SyncStatusCodeSynced)). 105 Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", fixture.DeploymentNamespace(), SyncStatusCodeOutOfSync)) 106 } 107 108 func getNewNamespace(t *testing.T) string { 109 postFix := "-" + strings.ToLower(rand.RandString(5)) 110 name := fixture.DnsFriendly(t.Name(), "") 111 return fixture.DnsFriendly(fmt.Sprintf("argocd-e2e-%s", name), postFix) 112 }