Fix broken e2e tests (#1667)

This commit is contained in:
Alexander Matyushentsev 2019-05-31 13:13:35 -07:00 committed by GitHub
parent 556f12fd59
commit 8a7c870f1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 49 deletions

View file

@ -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: |

View file

@ -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)

View file

@ -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 {

View file

@ -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"
}
}

View file

@ -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()

View file

@ -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,

View file

@ -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().