From 767590ba5a92c2e484221e55bd5249feeedd3fd7 Mon Sep 17 00:00:00 2001 From: Alexander Matyushentsev Date: Thu, 30 May 2019 15:19:29 -0700 Subject: [PATCH] Fix broken e2e tests --- .circleci/config.yml | 9 +++---- test/e2e/app_management_test.go | 13 +++++------ test/e2e/fixture/app/consequences.go | 13 ++--------- test/e2e/fixture/app/expectation.go | 9 +++---- test/e2e/fixture/cmd.go | 2 ++ test/e2e/fixture/fixture.go | 35 ++++++++++++---------------- test/e2e/repo_creds_test.go | 4 +++- 7 files changed, 36 insertions(+), 49 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 309f71306b308..e2baa7d71fcf3 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -275,7 +275,7 @@ jobs: ARGOCD_FAKE_IN_CLUSTER: "true" - run: name: Start API server - command: go run ./cmd/argocd-server/main.go --loglevel debug --redis localhost:6379 --disable-auth --insecure --dex-server http://localhost:5556 --repo-server localhost:8081 --staticassets ../argo-cd-ui/dist/app + command: go run ./cmd/argocd-server/main.go --loglevel debug --redis localhost:6379 --insecure --dex-server http://localhost:5556 --repo-server localhost:8081 --staticassets ../argo-cd-ui/dist/app background: true environment: ARGOCD_FAKE_IN_CLUSTER: "true" @@ -283,9 +283,7 @@ jobs: name: Wait for API server command: | set -x - # TODO - try to reduce to 20 - sleep 60 - curl -v --retry 5 localhost:8080 + until curl -v http://localhost:8080/healthz; do sleep 3; done - run: name: Start controller command: go run ./cmd/argocd-application-controller/main.go --loglevel debug --redis localhost:6379 --repo-server localhost:8081 --kubeconfig ~/.kube/config @@ -296,11 +294,10 @@ jobs: name: Smoke test command: | set -x + argocd login localhost:8080 --plaintext --username admin --password password argocd app create guestbook --dest-namespace default --dest-server https://kubernetes.default.svc --repo https://github.com/argoproj/argocd-example-apps.git --path guestbook argocd app sync guestbook argocd app delete guestbook - environment: - ARGOCD_OPTS: "--server localhost:8080 --plaintext" - run: name: Run e2e tests command: | diff --git a/test/e2e/app_management_test.go b/test/e2e/app_management_test.go index 26a9565c737f0..077bb4be92e6e 100644 --- a/test/e2e/app_management_test.go +++ b/test/e2e/app_management_test.go @@ -65,13 +65,11 @@ func TestAppDeletion(t *testing.T) { Delete(true). Then(). Expect(DoesNotExist()). - Expect(Event(EventReasonResourceDeleted, "delete")). - And(func(_ *Application) { - // app should NOT be listed - output, err := fixture.RunCli("app", "list") - assert.NoError(t, err) - assert.NotContains(t, output, fixture.Name()) - }) + Expect(Event(EventReasonResourceDeleted, "delete")) + + output, err := fixture.RunCli("app", "list") + assert.NoError(t, err) + assert.NotContains(t, output, fixture.Name()) } func TestTrackAppStateAndSyncApp(t *testing.T) { @@ -484,6 +482,7 @@ func TestPermissions(t *testing.T) { proj.Spec.SourceRepos = []string{} _, err = fixture.AppClientset.ArgoprojV1alpha1().AppProjects(fixture.ArgoCDNamespace).Update(proj) assert.NoError(t, err) + time.Sleep(1 * time.Second) closer, client, err := fixture.ArgoCDClientset.NewApplicationClient() assert.NoError(t, err) defer util.Close(closer) diff --git a/test/e2e/fixture/app/consequences.go b/test/e2e/fixture/app/consequences.go index b8f3e36b6cd57..100eb5dfdb2dc 100644 --- a/test/e2e/fixture/app/consequences.go +++ b/test/e2e/fixture/app/consequences.go @@ -1,11 +1,10 @@ package app import ( - "strings" "time" - "github.com/ghodss/yaml" log "github.com/sirupsen/logrus" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "github.com/argoproj/argo-cd/errors" . "github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1" @@ -52,15 +51,7 @@ func (c *Consequences) app() *Application { } func (c *Consequences) get() (*Application, error) { - output, err := fixture.RunCli("app", "get", c.context.name, "-o", "yaml") - if err != nil { - if strings.Contains(output, "NotFound") { - return nil, nil - } - return nil, err - } - app := &Application{} - return app, yaml.Unmarshal([]byte(output), app) + return fixture.AppClientset.ArgoprojV1alpha1().Applications(fixture.ArgoCDNamespace).Get(c.context.name, v1.GetOptions{}) } func (c *Consequences) resource(name string) ResourceStatus { diff --git a/test/e2e/fixture/app/expectation.go b/test/e2e/fixture/app/expectation.go index 7bbf0d953ca06..7658dc3c9db17 100644 --- a/test/e2e/fixture/app/expectation.go +++ b/test/e2e/fixture/app/expectation.go @@ -5,6 +5,7 @@ import ( "strings" v1 "k8s.io/api/core/v1" + apierr "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" @@ -83,13 +84,13 @@ func ResourceHealthIs(resource string, expected HealthStatusCode) Expectation { func DoesNotExist() Expectation { return func(c *Consequences) (state, string) { - app, err := c.get() + _, err := c.get() if err != nil { + if apierr.IsNotFound(err) { + return succeeded, "app does not exist" + } return failed, err.Error() } - if app == nil { - return succeeded, "app does not exist" - } return pending, "app should not exist" } } diff --git a/test/e2e/fixture/cmd.go b/test/e2e/fixture/cmd.go index 352fb6db45056..15660f9e28df7 100644 --- a/test/e2e/fixture/cmd.go +++ b/test/e2e/fixture/cmd.go @@ -1,6 +1,7 @@ package fixture import ( + "os" "os/exec" "strings" "time" @@ -15,6 +16,7 @@ func Run(workDir, name string, args ...string) (string, error) { log.WithFields(log.Fields{"name": name, "args": args, "workDir": workDir}).Info("running command") cmd := exec.Command(name, args...) + cmd.Env = os.Environ() cmd.Dir = workDir outBytes, err := cmd.Output() diff --git a/test/e2e/fixture/fixture.go b/test/e2e/fixture/fixture.go index dbafee30b4802..b9392bb0c5899 100644 --- a/test/e2e/fixture/fixture.go +++ b/test/e2e/fixture/fixture.go @@ -13,6 +13,7 @@ import ( jsonpatch "github.com/evanphx/json-patch" "github.com/ghodss/yaml" log "github.com/sirupsen/logrus" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" @@ -63,10 +64,6 @@ func getKubeConfig(configPath string, overrides clientcmd.ConfigOverrides) *rest // creates e2e tests fixture: ensures that Application CRD is installed, creates temporal namespace, starts repo and api server, // configure currently available cluster. func init() { - - // trouble-shooting check to see if this busted add-on is going to cause problems - FailOnErr(Run("", "kubectl", "api-resources", "-o", "name")) - // set-up variables config := getKubeConfig("", clientcmd.ConfigOverrides{}) AppClientset = appclientset.NewForConfigOrDie(config) @@ -127,8 +124,9 @@ func CreateSecret(username, password string) string { secretName := fmt.Sprintf("argocd-e2e-secret-%s", id) FailOnErr(Run("", "kubectl", "create", "secret", "generic", secretName, "--from-literal=username="+username, - "--from-literal=password="+password)) - FailOnErr(Run("", "kubectl", "label", "secret", secretName, testingLabel+"=true")) + "--from-literal=password="+password, + "-n", ArgoCDNamespace)) + FailOnErr(Run("", "kubectl", "label", "secret", secretName, testingLabel+"=true", "-n", ArgoCDNamespace)) return secretName } @@ -136,22 +134,18 @@ func EnsureCleanState() { start := time.Now() + policy := v1.DeletePropagationBackground // delete resources - text, err := Run("", "kubectl", "get", "app", "-o", "name") - CheckError(err) - for _, name := range strings.Split(text, "\n") { - if name != "" { - appName := strings.TrimPrefix(name, "application.argoproj.io/") - // we cannot delete any app, if an op is in progress - _, _ = RunCli("app", "terminate-op", appName) - // is it much more reliable to get argocd to delete an app than kubectl, deleting directly can make ArgoCD stuck - _, _ = RunCli("app", "delete", appName) - } - } - FailOnErr(Run("", "kubectl", "delete", "appprojects", "--field-selector", "metadata.name!=default")) - // takes around 5s, so we don't wait + // kubectl delete apps --all + CheckError(AppClientset.ArgoprojV1alpha1().Applications(ArgoCDNamespace).DeleteCollection(&v1.DeleteOptions{PropagationPolicy: &policy}, v1.ListOptions{})) + // kubectl delete appprojects --field-selector metadata.name!=default + CheckError(AppClientset.ArgoprojV1alpha1().AppProjects(ArgoCDNamespace).DeleteCollection( + &v1.DeleteOptions{PropagationPolicy: &policy}, v1.ListOptions{FieldSelector: "metadata.name!=default"})) + // kubectl delete secrets -l e2e.argoproj.io=true + CheckError(KubeClientset.CoreV1().Secrets(ArgoCDNamespace).DeleteCollection( + &v1.DeleteOptions{PropagationPolicy: &policy}, v1.ListOptions{LabelSelector: testingLabel + "=true"})) + FailOnErr(Run("", "kubectl", "delete", "ns", "-l", testingLabel+"=true", "--field-selector", "status.phase=Active", "--wait=false")) - FailOnErr(Run("", "kubectl", "delete", "secrets", "-l", testingLabel+"=true")) // reset settings s, err := SettingsManager.GetSettings() @@ -160,6 +154,7 @@ func EnsureCleanState() { // changing theses causes a restart AdminPasswordHash: s.AdminPasswordHash, AdminPasswordMtime: s.AdminPasswordMtime, + ServerSignature: s.ServerSignature, Certificate: s.Certificate, DexConfig: s.DexConfig, OIDCConfigRAW: s.OIDCConfigRAW, diff --git a/test/e2e/repo_creds_test.go b/test/e2e/repo_creds_test.go index b35147bdede68..e9618cfd6b85e 100644 --- a/test/e2e/repo_creds_test.go +++ b/test/e2e/repo_creds_test.go @@ -47,7 +47,9 @@ func TestCanAddAppFromPrivateRepoWithCredConfig(t *testing.T) { Path(appPath). And(func() { secretName := fixture.CreateSecret("blah", accessToken) - FailOnErr(fixture.Run("", "kubectl", "patch", "cm", "argocd-cm", "-p", fmt.Sprintf(`{"data": {"repository.credentials": "- passwordSecret:\n key: password\n name: %s\n url: %s\n usernameSecret:\n key: username\n name: %s\n"}}`, secretName, repoUrl, secretName))) + FailOnErr(fixture.Run("", "kubectl", "patch", "cm", "argocd-cm", + "-n", fixture.ArgoCDNamespace, + "-p", fmt.Sprintf(`{"data": {"repository.credentials": "- passwordSecret:\n key: password\n name: %s\n url: %s\n usernameSecret:\n key: username\n name: %s\n"}}`, secretName, repoUrl, secretName))) }). When(). Create().