-
Notifications
You must be signed in to change notification settings - Fork 6.5k
chore(test): add e2e tests for gitops-engine #23304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
5710f26
03191b3
2f01b8f
3de0803
dfa70ce
34df8d9
16dd3b2
a65b69d
792cf82
0bed9ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,17 +4,89 @@ import ( | |
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/argoproj/gitops-engine/pkg/health" | ||
| . "github.com/argoproj/gitops-engine/pkg/sync/common" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| . "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" | ||
| "github.com/argoproj/argo-cd/v3/test/e2e/fixture" | ||
| . "github.com/argoproj/argo-cd/v3/test/e2e/fixture" | ||
| . "github.com/argoproj/argo-cd/v3/test/e2e/fixture/app" | ||
| "github.com/argoproj/argo-cd/v3/util/errors" | ||
| ) | ||
|
|
||
| // TestSyncWithCreateNamespace verifies that the namespace is created when the | ||
| // CreateNamespace=true is provided as part of the normal sync resources | ||
| func TestSyncWithCreateNamespace(t *testing.T) { | ||
| newNamespace := getNewNamespace(t) | ||
| defer func() { | ||
| if !t.Skipped() { | ||
| errors.NewHandler(t).FailOnErr(fixture.Run("", "kubectl", "delete", "namespace", newNamespace)) | ||
| } | ||
| }() | ||
|
|
||
| Given(t). | ||
| Path(guestbookPath). | ||
| When(). | ||
| CreateFromFile(func(app *Application) { | ||
| app.Spec.Destination.Namespace = newNamespace | ||
| app.Spec.SyncPolicy = &SyncPolicy{ | ||
| SyncOptions: SyncOptions{ | ||
| "CreateNamespace=true", | ||
| }, | ||
| } | ||
| }). | ||
| Then(). | ||
| Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). | ||
| When(). | ||
| Sync(). | ||
| Then(). | ||
| // Only one resource should be in sync result | ||
| Expect(SyncStatusIs(SyncStatusCodeSynced)). | ||
| Expect(HealthIs(health.HealthStatusHealthy)). | ||
| Expect(OperationPhaseIs(OperationSucceeded)). | ||
| Expect(ResourceResultNumbering(3)) | ||
| } | ||
|
|
||
| // TestSyncWithCreateNamespaceAndDryRunError verifies that the namespace is created before the | ||
| // DryRun validation is made on the resources, even if the sync fails. This allows transient errors | ||
| // to be resolved on sync retries | ||
| func TestSyncWithCreateNamespaceAndDryRunError(t *testing.T) { | ||
| newNamespace := getNewNamespace(t) | ||
| defer func() { | ||
| if !t.Skipped() { | ||
| errors.NewHandler(t).FailOnErr(fixture.Run("", "kubectl", "delete", "namespace", newNamespace)) | ||
| } | ||
| }() | ||
|
|
||
| Given(t). | ||
| Path("failure-during-sync"). | ||
| When(). | ||
| CreateFromFile(func(app *Application) { | ||
| app.Spec.Destination.Namespace = newNamespace | ||
| app.Spec.SyncPolicy = &SyncPolicy{ | ||
| SyncOptions: SyncOptions{ | ||
| "CreateNamespace=true", | ||
| }, | ||
| } | ||
| }). | ||
| Then(). | ||
| Expect(SyncStatusIs(SyncStatusCodeOutOfSync)). | ||
| When(). | ||
| IgnoreErrors(). | ||
| Sync(). | ||
| Then(). | ||
| // Only one resource should be in sync result | ||
| Expect(OperationPhaseIs(OperationFailed)). | ||
| Expect(ResourceResultNumbering(2)). | ||
| Expect(ResourceSyncStatusIs("Namespace", newNamespace, SyncStatusCodeSynced)). | ||
| Expect(ResourceSyncStatusWithNamespaceIs("ServiceAccount", newNamespace, "failure-during-sync", "")) | ||
| } | ||
|
|
||
| // TestSyncOptionsValidateFalse verifies we can disable validation during kubectl apply, using the | ||
| // 'argocd.argoproj.io/sync-options: Validate=false' sync option | ||
| func TestSyncOptionsValidateFalse(t *testing.T) { | ||
|
|
@@ -53,7 +125,7 @@ func TestSyncWithStatusIgnored(t *testing.T) { | |
| Path(guestbookPath). | ||
| When(). | ||
| And(func() { | ||
| require.NoError(t, fixture.SetResourceOverrides(map[string]ResourceOverride{ | ||
| require.NoError(t, SetResourceOverrides(map[string]ResourceOverride{ | ||
| "/": { | ||
| IgnoreDifferences: OverrideIgnoreDiff{JSONPointers: []string{"/status"}}, | ||
| }, | ||
|
|
@@ -73,7 +145,7 @@ func TestSyncWithStatusIgnored(t *testing.T) { | |
| // app should remain synced if k8s change detected | ||
| When(). | ||
| And(func() { | ||
| errors.NewHandler(t).FailOnErr(fixture.KubeClientset.AppsV1().Deployments(fixture.DeploymentNamespace()).Patch(t.Context(), | ||
| errors.NewHandler(t).FailOnErr(KubeClientset.AppsV1().Deployments(DeploymentNamespace()).Patch(t.Context(), | ||
| "guestbook-ui", types.JSONPatchType, []byte(`[{ "op": "replace", "path": "/status/observedGeneration", "value": 2 }]`), metav1.PatchOptions{})) | ||
| }). | ||
| Then(). | ||
|
|
@@ -104,7 +176,7 @@ func TestSyncWithApplyOutOfSyncOnly(t *testing.T) { | |
| } | ||
|
|
||
| func TestSyncWithSkipHook(t *testing.T) { | ||
| fixture.SkipOnEnv(t, "OPENSHIFT") | ||
| SkipOnEnv(t, "OPENSHIFT") | ||
| Given(t). | ||
| Path(guestbookPath). | ||
| When(). | ||
|
|
@@ -146,3 +218,50 @@ func TestSyncWithForceReplace(t *testing.T) { | |
| Then(). | ||
| Expect(SyncStatusIs(SyncStatusCodeSynced)) | ||
| } | ||
|
|
||
| // Given application is set with --sync-option CreateNamespace=true and --sync-option ServerSideApply=true | ||
| // | ||
| // application --dest-namespace exists | ||
| // | ||
| // Then, --dest-namespace is created with server side apply | ||
| // application is synced and healthy with resource | ||
| // application resources created with server side apply in the newly created namespace. | ||
| func TestNamespaceCreationWithSSA(t *testing.T) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test was moved and not changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Edit: test was updated because for some reason the e2e fails with |
||
| SkipOnEnv(t, "OPENSHIFT") | ||
| namespace := "guestbook-ui-with-ssa" | ||
| defer func() { | ||
| if !t.Skipped() { | ||
| _, err := Run("", "kubectl", "delete", "namespace", namespace) | ||
| assert.NoError(t, err) | ||
| } | ||
| }() | ||
|
|
||
| ctx := Given(t) | ||
| ctx. | ||
| SetAppNamespace(AppNamespace()). | ||
| Timeout(30). | ||
| Path("guestbook"). | ||
| When(). | ||
| CreateFromFile(func(app *Application) { | ||
| app.Spec.SyncPolicy = &SyncPolicy{ | ||
| SyncOptions: SyncOptions{"CreateNamespace=true", "ServerSideApply=true"}, | ||
| } | ||
| }). | ||
| Then(). | ||
| Expect(NoNamespace(namespace)). | ||
| When(). | ||
| AppSet("--dest-namespace", namespace). | ||
| Sync(). | ||
| Then(). | ||
| Expect(Success("")). | ||
| Expect(Namespace(namespace, func(_ *Application, ns *corev1.Namespace) { | ||
| assert.NotContains(t, ns.Annotations, "kubectl.kubernetes.io/last-applied-configuration") | ||
| })). | ||
| Expect(SyncStatusIs(SyncStatusCodeSynced)). | ||
| Expect(HealthIs(health.HealthStatusHealthy)). | ||
| Expect(OperationPhaseIs(OperationSucceeded)). | ||
| Expect(ResourceHealthWithNamespaceIs("Deployment", "guestbook-ui", namespace, health.HealthStatusHealthy)). | ||
| Expect(ResourceSyncStatusWithNamespaceIs("Deployment", "guestbook-ui", namespace, SyncStatusCodeSynced)). | ||
| Expect(ResourceHealthWithNamespaceIs("Service", "guestbook-ui", namespace, health.HealthStatusHealthy)). | ||
| Expect(ResourceSyncStatusWithNamespaceIs("Service", "guestbook-ui", namespace, SyncStatusCodeSynced)) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: revert when merge