1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package e2e
17
18 import (
19 "flag"
20 "math/rand"
21 "os"
22 "testing"
23 "time"
24
25 "github.com/onsi/ginkgo/v2"
26 "github.com/onsi/gomega"
27 runtimeutils "k8s.io/apimachinery/pkg/util/runtime"
28 "k8s.io/client-go/tools/clientcmd"
29 "k8s.io/component-base/logs"
30 "k8s.io/klog/v2"
31 "k8s.io/kubernetes/test/e2e/framework"
32 "k8s.io/kubernetes/test/e2e/framework/config"
33 "k8s.io/kubernetes/test/e2e/framework/testfiles"
34
35 _ "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/chaos"
36 e2econfig "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/config"
37 )
38
39
40 func handleFlags() {
41 config.CopyFlags(config.Flags, flag.CommandLine)
42 framework.RegisterCommonFlags(flag.CommandLine)
43 hackRegisterClusterFlags(flag.CommandLine)
44 e2econfig.RegisterOperatorFlags(flag.CommandLine)
45 flag.Parse()
46 }
47
48 func TestMain(m *testing.M) {
49
50 handleFlags()
51
52 framework.AfterReadingAllFlags(&framework.TestContext)
53
54 if framework.TestContext.RepoRoot != "" {
55 testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot})
56 }
57
58 rand.Seed(time.Now().UnixNano())
59 os.Exit(m.Run())
60 }
61
62 func TestE2E(t *testing.T) {
63 RunE2ETests(t)
64 }
65
66 func RunE2ETests(t *testing.T) {
67 runtimeutils.ReallyCrash = true
68 logs.InitLogs()
69 defer logs.FlushLogs()
70
71 gomega.RegisterFailHandler(framework.Fail)
72
73
74 suite, _ := ginkgo.GinkgoConfiguration()
75 klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, suite.ParallelProcess)
76
77 ginkgo.RunSpecs(t, "chaosmesh e2e suit")
78 }
79
80
81
82 func hackRegisterClusterFlags(flags *flag.FlagSet) {
83 framework.TestContext.KubeConfig = os.Getenv("KUBECONFIG")
84 if len(framework.TestContext.KubeConfig) < 1 {
85 klog.Fatalf("KUBECONFIG ENV NOT SET")
86 }
87 flags.BoolVar(&framework.TestContext.VerifyServiceAccount, "e2e-verify-service-account", true, "If true tests will verify the service account before running.")
88 flags.StringVar(&framework.TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
89 flags.StringVar(&framework.TestContext.KubeAPIContentType, "kube-api-content-type", "application/vnd.kubernetes.protobuf", "ContentType used to communicate with apiserver")
90
91 flags.StringVar(&framework.TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
92 flags.StringVar(&framework.TestContext.RepoRoot, "repo-root", "../../", "Root directory of kubernetes repository, for finding test files.")
93 flags.StringVar(&framework.TestContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, skeleton (the fallback if not set), etc.)")
94 flags.StringVar(&framework.TestContext.Tooling, "tooling", "", "The tooling in use (kops, gke, etc.)")
95 flags.StringVar(&framework.TestContext.OutputDir, "e2e-output-dir", "/tmp", "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.")
96 flags.StringVar(&framework.TestContext.Prefix, "prefix", "e2e", "A prefix to be added to cloud resources created during testing.")
97 flags.StringVar(&framework.TestContext.MasterOSDistro, "master-os-distro", "debian", "The OS distribution of cluster master (debian, ubuntu, gci, coreos, or custom).")
98 flags.StringVar(&framework.TestContext.NodeOSDistro, "node-os-distro", "debian", "The OS distribution of cluster VM instances (debian, ubuntu, gci, coreos, or custom).")
99 flags.StringVar(&framework.TestContext.ClusterDNSDomain, "dns-domain", "cluster.local", "The DNS Domain of the cluster.")
100
101 flags.IntVar(&framework.TestContext.MinStartupPods, "minStartupPods", 0, "The number of pods which we need to see in 'Running' state with a 'Ready' condition of true, before we try running tests. This is useful in any cluster which needs some base pod-based services running before it can be used.")
102 flags.StringVar(&framework.TestContext.EtcdUpgradeStorage, "etcd-upgrade-storage", "", "The storage version to upgrade to (either 'etcdv2' or 'etcdv3') if doing an etcd upgrade test.")
103 flags.StringVar(&framework.TestContext.EtcdUpgradeVersion, "etcd-upgrade-version", "", "The etcd binary version to upgrade to (e.g., '3.0.14', '2.3.7') if doing an etcd upgrade test.")
104 flags.StringVar(&framework.TestContext.GCEUpgradeScript, "gce-upgrade-script", "", "Script to use to upgrade a GCE cluster.")
105 flags.BoolVar(&framework.TestContext.CleanStart, "clean-start", false, "If true, purge all namespaces except default and system before running tests. This serves to Cleanup test namespaces from failed/interrupted e2e runs in a long-lived cluster.")
106
107 nodeKiller := &framework.TestContext.NodeKiller
108 flags.BoolVar(&nodeKiller.Enabled, "node-killer", false, "Whether NodeKiller should kill any nodes.")
109 flags.Float64Var(&nodeKiller.FailureRatio, "node-killer-failure-ratio", 0.01, "Percentage of nodes to be killed")
110 flags.DurationVar(&nodeKiller.Interval, "node-killer-interval", 1*time.Minute, "Time between node failures.")
111 flags.Float64Var(&nodeKiller.JitterFactor, "node-killer-jitter-factor", 60, "Factor used to jitter node failures.")
112 flags.DurationVar(&nodeKiller.SimulatedDowntime, "node-killer-simulated-downtime", 10*time.Minute, "A delay between node death and recreation")
113 }
114