Skip to content

Commit

Permalink
chore: don't hardcode argo-e2e* namespaces (argoproj#12871)
Browse files Browse the repository at this point in the history
There are two environment variables which are used to set namespaces
other than `argo-e2e` and `argo-e2e-external`; `ARGOCD_E2E_NAMESPACE`
and `ARGOCD_E2E_APP_NAMESPACE` respectively.

When using these env vars, a bunch of tests fail since a lot of them
hardcode `argo-e2e` or `argo-e2e-external`. This PR changes that to
use either `TestNamespace()` or `AppNamespace()`, which will set the
correct namespace to use if the above env vars have been set.

Signed-off-by: Blake Pettersson <blake.pettersson@gmail.com>
  • Loading branch information
blakepettersson authored and alexec committed Mar 19, 2023
1 parent 640f481 commit 4587bc3
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 114 deletions.
10 changes: 5 additions & 5 deletions test/e2e/app_management_ns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1603,15 +1603,15 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
},
}
defer func() {
log.Infof("Ingress 'sample-ingress' deleted from %s", ArgoCDNamespace)
CheckError(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
log.Infof("Ingress 'sample-ingress' deleted from %s", TestNamespace())
CheckError(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
}()

svc := &v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-ui",
Annotations: map[string]string{
common.AnnotationKeyAppInstance: fmt.Sprintf("%s_%s:Service:%s/guesbook-ui", ArgoCDNamespace, ctx.AppQualifiedName(), DeploymentNamespace()),
common.AnnotationKeyAppInstance: fmt.Sprintf("%s_%s:Service:%s/guesbook-ui", TestNamespace(), ctx.AppQualifiedName(), DeploymentNamespace()),
},
},
Spec: v1.ServiceSpec{
Expand All @@ -1633,7 +1633,7 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
{Group: "", Kind: "Service"},
}}).
And(func() {
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Create(context.Background(), svc, metav1.CreateOptions{}))
}).
Path(guestbookPath).
Expand All @@ -1659,7 +1659,7 @@ func TestNamespacedNotPermittedResources(t *testing.T) {
Expect(DoesNotExist())

// Make sure prohibited resources are not deleted during application deletion
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{}))
}

Expand Down
18 changes: 9 additions & 9 deletions test/e2e/app_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func TestAppCreation(t *testing.T) {
When().
// ensure that update replaces spec and merge labels and annotations
And(func() {
FailOnErr(AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).Patch(context.Background(),
FailOnErr(AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Patch(context.Background(),
ctx.GetName(), types.MergePatchType, []byte(`{"metadata": {"labels": { "test": "label" }, "annotations": { "test": "annotation" }}}`), metav1.PatchOptions{}))
}).
CreateApp("--upsert").
Expand Down Expand Up @@ -504,7 +504,7 @@ func TestAppRollbackSuccessful(t *testing.T) {
}}
patch, _, err := diff.CreateTwoWayMergePatch(app, appWithHistory, &Application{})
require.NoError(t, err)
app, err = AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).Patch(context.Background(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
app, err = AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Patch(context.Background(), app.Name, types.MergePatchType, patch, metav1.PatchOptions{})
require.NoError(t, err)

// sync app and make sure it reaches InSync state
Expand Down Expand Up @@ -1594,8 +1594,8 @@ func TestNotPermittedResources(t *testing.T) {
},
}
defer func() {
log.Infof("Ingress 'sample-ingress' deleted from %s", ArgoCDNamespace)
CheckError(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
log.Infof("Ingress 'sample-ingress' deleted from %s", TestNamespace())
CheckError(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Delete(context.Background(), "sample-ingress", metav1.DeleteOptions{}))
}()

svc := &v1.Service{
Expand Down Expand Up @@ -1623,7 +1623,7 @@ func TestNotPermittedResources(t *testing.T) {
{Group: "", Kind: "Service"},
}}).
And(func() {
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Create(context.Background(), ingress, metav1.CreateOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Create(context.Background(), svc, metav1.CreateOptions{}))
}).
Path(guestbookPath).
Expand All @@ -1649,7 +1649,7 @@ func TestNotPermittedResources(t *testing.T) {
Expect(DoesNotExist())

// Make sure prohibited resources are not deleted during application deletion
FailOnErr(KubeClientset.NetworkingV1().Ingresses(ArgoCDNamespace).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.NetworkingV1().Ingresses(TestNamespace()).Get(context.Background(), "sample-ingress", metav1.GetOptions{}))
FailOnErr(KubeClientset.CoreV1().Services(DeploymentNamespace()).Get(context.Background(), "guestbook-ui", metav1.GetOptions{}))
}

Expand Down Expand Up @@ -1688,7 +1688,7 @@ func TestCreateAppWithNoNameSpaceForGlobalResource(t *testing.T) {
Then().
And(func(app *Application) {
time.Sleep(500 * time.Millisecond)
app, err := AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).Get(context.Background(), app.Name, metav1.GetOptions{})
app, err := AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
assert.NoError(t, err)
assert.Len(t, app.Status.Conditions, 0)
})
Expand All @@ -1708,7 +1708,7 @@ func TestCreateAppWithNoNameSpaceWhenRequired(t *testing.T) {
Refresh(RefreshTypeNormal).
Then().
And(func(app *Application) {
updatedApp, err := AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).Get(context.Background(), app.Name, metav1.GetOptions{})
updatedApp, err := AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
require.NoError(t, err)

assert.Len(t, updatedApp.Status.Conditions, 2)
Expand All @@ -1732,7 +1732,7 @@ func TestCreateAppWithNoNameSpaceWhenRequired2(t *testing.T) {
Refresh(RefreshTypeNormal).
Then().
And(func(app *Application) {
updatedApp, err := AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).Get(context.Background(), app.Name, metav1.GetOptions{})
updatedApp, err := AppClientset.ArgoprojV1alpha1().Applications(TestNamespace()).Get(context.Background(), app.Name, metav1.GetOptions{})
require.NoError(t, err)

assert.Len(t, updatedApp.Status.Conditions, 2)
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/app_namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAppCreationInOtherNamespace(t *testing.T) {
ctx := Given(t)
ctx.
Path(guestbookPath).
SetAppNamespace(ArgoCDAppNamespace).
SetAppNamespace(AppNamespace()).
When().
CreateApp().
Then().
Expand Down Expand Up @@ -83,7 +83,7 @@ func TestDeletingNamespacedAppStuckInSync(t *testing.T) {
})
}).
Async(true).
SetAppNamespace(ArgoCDAppNamespace).
SetAppNamespace(AppNamespace()).
Path("hook-custom-health").
When().
CreateApp().
Expand Down
28 changes: 14 additions & 14 deletions test/e2e/applicationset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestSimpleListGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestSimpleListGeneratorGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -237,7 +237,7 @@ func TestSimpleGitDirectoryGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -346,7 +346,7 @@ func TestSimpleGitDirectoryGeneratorGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -457,7 +457,7 @@ func TestSimpleGitFilesGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -566,7 +566,7 @@ func TestSimpleGitFilesGeneratorGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestSimpleSCMProviderGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "argo-cd-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1062,7 +1062,7 @@ func TestSimpleSCMProviderGeneratorGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "argo-cd-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1131,7 +1131,7 @@ func TestCustomApplicationFinalizers(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io/background"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestCustomApplicationFinalizersGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "my-cluster-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io/background"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1297,7 +1297,7 @@ func TestSimplePullRequestGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-1",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1372,7 +1372,7 @@ func TestSimplePullRequestGeneratorGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "guestbook-1",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
Labels: map[string]string{"app": "preview"},
},
Expand Down Expand Up @@ -1448,7 +1448,7 @@ func TestGitGeneratorPrivateRepo(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1523,7 +1523,7 @@ func TestGitGeneratorPrivateRepoGoTemplate(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/cluster_generator_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package e2e

import (
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
"testing"
"time"

Expand All @@ -9,7 +10,6 @@ import (
"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
)

func TestSimpleClusterGenerator(t *testing.T) {
Expand All @@ -21,7 +21,7 @@ func TestSimpleClusterGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestClusterGeneratorWithLocalCluster(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "in-cluster-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -231,7 +231,7 @@ func TestSimpleClusterGeneratorAddingCluster(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "{{name}}-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -313,7 +313,7 @@ func TestSimpleClusterGeneratorDeletingCluster(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "{{name}}-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/clusterdecisiongenerator_e2e_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package e2e

import (
"github.com/argoproj/argo-cd/v2/test/e2e/fixture"
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
argov1alpha1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
. "github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets"
"github.com/argoproj/argo-cd/v2/test/e2e/fixture/applicationsets/utils"
)

var tenSec = int64(10)
Expand All @@ -22,7 +22,7 @@ func TestSimpleClusterDecisionResourceGenerator(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "cluster1-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestSimpleClusterDecisionResourceGeneratorAddingCluster(t *testing.T) {
},
ObjectMeta: metav1.ObjectMeta{
Name: "{{name}}-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestSimpleClusterDecisionResourceGeneratorDeletingClusterSecret(t *testing.
},
ObjectMeta: metav1.ObjectMeta{
Name: "{{name}}-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -316,7 +316,7 @@ func TestSimpleClusterDecisionResourceGeneratorDeletingClusterFromResource(t *te
},
ObjectMeta: metav1.ObjectMeta{
Name: "{{name}}-guestbook",
Namespace: utils.ArgoCDNamespace,
Namespace: fixture.TestNamespace(),
Finalizers: []string{"resources-finalizer.argocd.argoproj.io"},
},
Spec: argov1alpha1.ApplicationSpec{
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/app/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (a *Actions) Declarative(filename string) *Actions {
func (a *Actions) DeclarativeWithCustomRepo(filename string, repoURL string) *Actions {
a.context.t.Helper()
values := map[string]interface{}{
"ArgoCDNamespace": fixture.ArgoCDNamespace,
"ArgoCDNamespace": fixture.TestNamespace(),
"DeploymentNamespace": fixture.DeploymentNamespace(),
"Name": a.context.AppName(),
"Path": a.context.path,
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture/app/expectation.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func event(namespace string, reason string, message string) Expectation {
}

func Event(reason string, message string) Expectation {
return event(fixture.ArgoCDNamespace, reason, message)
return event(fixture.TestNamespace(), reason, message)
}

func NamespacedEvent(namespace string, reason string, message string) Expectation {
Expand Down
Loading

0 comments on commit 4587bc3

Please sign in to comment.