diff --git a/test/e2e/deployment_test.go b/test/e2e/deployment_test.go index bb12e5efbbd9f..dee795f8facae 100644 --- a/test/e2e/deployment_test.go +++ b/test/e2e/deployment_test.go @@ -1,12 +1,18 @@ package e2e import ( + "fmt" "testing" + "github.com/stretchr/testify/assert" + + "github.com/argoproj/argo-cd/v2/util/argo" + "github.com/argoproj/gitops-engine/pkg/health" . "github.com/argoproj/gitops-engine/pkg/sync/common" . "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" + . "github.com/argoproj/argo-cd/v2/test/e2e/fixture" . "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app" ) @@ -31,3 +37,70 @@ func TestDeployment(t *testing.T) { ]`). Sync() } + +func TestDeploymentWithAnnotationTrackingMode(t *testing.T) { + ctx := Given(t) + + SetTrackingMethod(string(argo.TrackingMethodAnnotation)) + ctx. + Path("deployment"). + When(). + Create(). + Sync(). + Then(). + Expect(OperationPhaseIs(OperationSucceeded)). + Expect(SyncStatusIs(SyncStatusCodeSynced)). + Expect(HealthIs(health.HealthStatusHealthy)). + When(). + Then(). + And(func(app *Application) { + out, err := RunCli("app", "manifests", app.Name) + assert.NoError(t, err) + assert.Contains(t, out, fmt.Sprintf(`annotations: + app.kubernetes.io/instance: %s`, Name())) + }) +} + +func TestDeploymentWithLabelTrackingMode(t *testing.T) { + ctx := Given(t) + SetTrackingMethod(string(argo.TrackingMethodLabel)) + ctx. + Path("deployment"). + When(). + Create(). + Sync(). + Then(). + Expect(OperationPhaseIs(OperationSucceeded)). + Expect(SyncStatusIs(SyncStatusCodeSynced)). + Expect(HealthIs(health.HealthStatusHealthy)). + When(). + Then(). + And(func(app *Application) { + out, err := RunCli("app", "manifests", app.Name) + assert.NoError(t, err) + assert.Contains(t, out, fmt.Sprintf(`labels: + app: nginx + app.kubernetes.io/instance: %s`, Name())) + }) +} + +func TestDeploymentWithoutTrackingMode(t *testing.T) { + Given(t). + Path("deployment"). + When(). + Create(). + Sync(). + Then(). + Expect(OperationPhaseIs(OperationSucceeded)). + Expect(SyncStatusIs(SyncStatusCodeSynced)). + Expect(HealthIs(health.HealthStatusHealthy)). + When(). + Then(). + And(func(app *Application) { + out, err := RunCli("app", "manifests", app.Name) + assert.NoError(t, err) + assert.Contains(t, out, fmt.Sprintf(`labels: + app: nginx + app.kubernetes.io/instance: %s`, Name())) + }) +} diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index 08d0f16d9919f..95789cdbed710 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -336,6 +336,13 @@ func SetResourceOverrides(overrides map[string]v1alpha1.ResourceOverride) { SetResourceOverridesSplitKeys(overrides) } +func SetTrackingMethod(trackingMethod string) { + updateSettingConfigMap(func(cm *corev1.ConfigMap) error { + cm.Data["application.resourceTrackingMethod"] = trackingMethod + return nil + }) +} + func SetResourceOverridesSplitKeys(overrides map[string]v1alpha1.ResourceOverride) { updateSettingConfigMap(func(cm *corev1.ConfigMap) error { for k, v := range overrides {