1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package e2e
17
18 import (
19 "flag"
20 "fmt"
21 "math/rand"
22 "os"
23 "path"
24 "testing"
25 "time"
26
27 "github.com/onsi/ginkgo"
28 ginkgoconfig "github.com/onsi/ginkgo/config"
29 "github.com/onsi/ginkgo/reporters"
30 "github.com/onsi/gomega"
31 runtimeutils "k8s.io/apimachinery/pkg/util/runtime"
32 "k8s.io/client-go/tools/clientcmd"
33 "k8s.io/component-base/logs"
34 "k8s.io/klog/v2"
35 "k8s.io/kubernetes/test/e2e/framework"
36 "k8s.io/kubernetes/test/e2e/framework/config"
37 "k8s.io/kubernetes/test/e2e/framework/testfiles"
38
39 e2econfig "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/config"
40
41
42 _ "github.com/chaos-mesh/chaos-mesh/e2e-test/e2e/chaos"
43 )
44
45
46 func handleFlags() {
47 config.CopyFlags(config.Flags, flag.CommandLine)
48 framework.RegisterCommonFlags(flag.CommandLine)
49 hackRegisterClusterFlags(flag.CommandLine)
50 e2econfig.RegisterOperatorFlags(flag.CommandLine)
51 flag.Parse()
52 }
53
54 func TestMain(m *testing.M) {
55
56 handleFlags()
57
58 framework.AfterReadingAllFlags(&framework.TestContext)
59
60 if framework.TestContext.RepoRoot != "" {
61 testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot})
62 }
63
64 rand.Seed(time.Now().UnixNano())
65 os.Exit(m.Run())
66 }
67
68 func TestE2E(t *testing.T) {
69 RunE2ETests(t)
70 }
71
72 func RunE2ETests(t *testing.T) {
73 runtimeutils.ReallyCrash = true
74 logs.InitLogs()
75 defer logs.FlushLogs()
76
77 gomega.RegisterFailHandler(framework.Fail)
78
79
80 var r []ginkgo.Reporter
81 r = append(r, reporters.NewJUnitReporter(path.Join(framework.TestContext.ReportDir, fmt.Sprintf("junit_%v%02d.xml", framework.TestContext.ReportPrefix, ginkgoconfig.GinkgoConfig.ParallelNode))))
82 klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, ginkgoconfig.GinkgoConfig.ParallelNode)
83
84 ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "chaosmesh e2e suit", r)
85 }
86
87
88
89 func hackRegisterClusterFlags(flags *flag.FlagSet) {
90 framework.TestContext.KubeConfig = os.Getenv("KUBECONFIG")
91 if len(framework.TestContext.KubeConfig) < 1 {
92 klog.Fatalf("KUBECONFIG ENV NOT SET")
93 }
94 flags.BoolVar(&framework.TestContext.VerifyServiceAccount, "e2e-verify-service-account", true, "If true tests will verify the service account before running.")
95 flags.StringVar(&framework.TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
96 flags.StringVar(&framework.TestContext.KubeAPIContentType, "kube-api-content-type", "application/vnd.kubernetes.protobuf", "ContentType used to communicate with apiserver")
97
98 flags.StringVar(&framework.TestContext.KubeVolumeDir, "volume-dir", "/var/lib/kubelet", "Path to the directory containing the kubelet volumes.")
99 flags.StringVar(&framework.TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
100 flags.StringVar(&framework.TestContext.RepoRoot, "repo-root", "../../", "Root directory of kubernetes repository, for finding test files.")
101 flags.StringVar(&framework.TestContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, skeleton (the fallback if not set), etc.)")
102 flags.StringVar(&framework.TestContext.Tooling, "tooling", "", "The tooling in use (kops, gke, etc.)")
103 flags.StringVar(&framework.TestContext.OutputDir, "e2e-output-dir", "/tmp", "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.")
104 flags.StringVar(&framework.TestContext.Prefix, "prefix", "e2e", "A prefix to be added to cloud resources created during testing.")
105 flags.StringVar(&framework.TestContext.MasterOSDistro, "master-os-distro", "debian", "The OS distribution of cluster master (debian, ubuntu, gci, coreos, or custom).")
106 flags.StringVar(&framework.TestContext.NodeOSDistro, "node-os-distro", "debian", "The OS distribution of cluster VM instances (debian, ubuntu, gci, coreos, or custom).")
107 flags.StringVar(&framework.TestContext.ClusterDNSDomain, "dns-domain", "cluster.local", "The DNS Domain of the cluster.")
108
109 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.")
110 flags.DurationVar(&framework.TestContext.SystemPodsStartupTimeout, "system-pods-startup-timeout", 10*time.Minute, "Timeout for waiting for all system pods to be running before starting tests.")
111 flags.DurationVar(&framework.TestContext.NodeSchedulableTimeout, "node-schedulable-timeout", 30*time.Minute, "Timeout for waiting for all nodes to be schedulable.")
112 flags.DurationVar(&framework.TestContext.SystemDaemonsetStartupTimeout, "system-daemonsets-startup-timeout", 5*time.Minute, "Timeout for waiting for all system daemonsets to be ready.")
113 flags.StringVar(&framework.TestContext.EtcdUpgradeStorage, "etcd-upgrade-storage", "", "The storage version to upgrade to (either 'etcdv2' or 'etcdv3') if doing an etcd upgrade test.")
114 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.")
115 flags.StringVar(&framework.TestContext.GCEUpgradeScript, "gce-upgrade-script", "", "Script to use to upgrade a GCE cluster.")
116 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.")
117
118 nodeKiller := &framework.TestContext.NodeKiller
119 flags.BoolVar(&nodeKiller.Enabled, "node-killer", false, "Whether NodeKiller should kill any nodes.")
120 flags.Float64Var(&nodeKiller.FailureRatio, "node-killer-failure-ratio", 0.01, "Percentage of nodes to be killed")
121 flags.DurationVar(&nodeKiller.Interval, "node-killer-interval", 1*time.Minute, "Time between node failures.")
122 flags.Float64Var(&nodeKiller.JitterFactor, "node-killer-jitter-factor", 60, "Factor used to jitter node failures.")
123 flags.DurationVar(&nodeKiller.SimulatedDowntime, "node-killer-simulated-downtime", 10*time.Minute, "A delay between node death and recreation")
124 }
125