-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Improve tests #1667
Improve tests #1667
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}) | ||
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. I know this looks odd, but the intent to was make sure that we prefer to invoke the CLI tool, than the API. How come you changed this bit? 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. Forgot to mention it in PR description. This method is executed most frequently during e2e tests execution. Looks like any process fork takes at least 100ms, so I decided to switch it to api call to save several seconds |
||
} | ||
|
||
func (c *Consequences) resource(name string) ResourceStatus { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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")) | ||
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. 👍 |
||
|
||
// set-up variables | ||
config := getKubeConfig("", clientcmd.ConfigOverrides{}) | ||
AppClientset = appclientset.NewForConfigOrDie(config) | ||
|
@@ -127,31 +124,28 @@ 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 | ||
} | ||
|
||
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) | ||
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. Do you need to maintain this line? 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. There is no need to terminate operation after fixing #1665. After application is deleted the controller is no longs stuck trying to update operation state. 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. 👍 |
||
// 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{})) | ||
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. Maybe comment with the kubectl equivilant? 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. sure. added |
||
// 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")) | ||
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. Do you need to delete this line too? 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. We still need to deleted temporal namespaces. There is no API to delete collection of namespaces, so I kept one 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. Nope, not fussed. 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. Hmmm.. How can there be no API for this, I'd assumed that kubectl just makes API calls? 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. you are right. there is API, but no API to delete collection, only one by one deletion |
||
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, | ||
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. 👍 |
||
Certificate: s.Certificate, | ||
DexConfig: s.DexConfig, | ||
OIDCConfigRAW: s.OIDCConfigRAW, | ||
|
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.
nice