1
2
3
4
5
6
7
8
9
10
11
12
13
14 package e2e
15
16 import (
17 "flag"
18 "fmt"
19 "math/rand"
20 "os"
21 "testing"
22 "time"
23
24 "github.com/onsi/ginkgo"
25 ginkgoconfig "github.com/onsi/ginkgo/config"
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"
31 "k8s.io/kubernetes/test/e2e/framework"
32 "k8s.io/kubernetes/test/e2e/framework/config"
33 e2elog "k8s.io/kubernetes/test/e2e/framework/log"
34 "k8s.io/kubernetes/test/e2e/framework/testfiles"
35 "k8s.io/kubernetes/test/e2e/framework/viperconfig"
36
37 e2econfig "github.com/chaos-mesh/chaos-mesh/test/e2e/config"
38
39
40 _ "github.com/chaos-mesh/chaos-mesh/test/e2e/chaos"
41 )
42
43 var viperConfig = flag.String("viper-config", "", "The name of a viper config file (https://github.com/spf13/viper#what-is-viper). All e2e command line parameters can also be configured in such a file. May contain a path and may or may not contain the file suffix. The default is to look for an optional file with `e2e` as base name. If a file is specified explicitly, it must be present.")
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
59
60
61 if err := viperconfig.ViperizeFlags(*viperConfig, "e2e", flag.CommandLine); err != nil {
62 fmt.Fprintln(os.Stderr, err)
63 os.Exit(1)
64 }
65
66 framework.AfterReadingAllFlags(&framework.TestContext)
67
68 if framework.TestContext.RepoRoot != "" {
69 testfiles.AddFileSource(testfiles.RootFileSource{Root: framework.TestContext.RepoRoot})
70 }
71
72 rand.Seed(time.Now().UnixNano())
73 os.Exit(m.Run())
74 }
75
76 func TestE2E(t *testing.T) {
77 RunE2ETests(t)
78 }
79
80 func RunE2ETests(t *testing.T) {
81 runtimeutils.ReallyCrash = true
82 logs.InitLogs()
83 defer logs.FlushLogs()
84
85 gomega.RegisterFailHandler(e2elog.Fail)
86
87
88 var r []ginkgo.Reporter
89 klog.Infof("Starting e2e run %q on Ginkgo node %d", framework.RunID, ginkgoconfig.GinkgoConfig.ParallelNode)
90
91 ginkgo.RunSpecsWithDefaultAndCustomReporters(t, "chaosmesh e2e suit", r)
92 }
93
94
95
96 func hackRegisterClusterFlags(flags *flag.FlagSet) {
97 framework.TestContext.KubeConfig = os.Getenv("KUBECONFIG")
98 if len(framework.TestContext.KubeConfig) < 1 {
99 klog.Fatalf("KUBECONFIG ENV NOT SET")
100 }
101 flags.BoolVar(&framework.TestContext.VerifyServiceAccount, "e2e-verify-service-account", true, "If true tests will verify the service account before running.")
102 flags.StringVar(&framework.TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
103 flags.StringVar(&framework.TestContext.KubeAPIContentType, "kube-api-content-type", "application/vnd.kubernetes.protobuf", "ContentType used to communicate with apiserver")
104
105 flags.StringVar(&framework.TestContext.KubeVolumeDir, "volume-dir", "/var/lib/kubelet", "Path to the directory containing the kubelet volumes.")
106 flags.StringVar(&framework.TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
107 flags.StringVar(&framework.TestContext.RepoRoot, "repo-root", "../../", "Root directory of kubernetes repository, for finding test files.")
108 flags.StringVar(&framework.TestContext.Provider, "provider", "", "The name of the Kubernetes provider (gce, gke, local, skeleton (the fallback if not set), etc.)")
109 flags.StringVar(&framework.TestContext.Tooling, "tooling", "", "The tooling in use (kops, gke, etc.)")
110 flags.StringVar(&framework.TestContext.OutputDir, "e2e-output-dir", "/tmp", "Output directory for interesting/useful test data, like performance data, benchmarks, and other metrics.")
111 flags.StringVar(&framework.TestContext.Prefix, "prefix", "e2e", "A prefix to be added to cloud resources created during testing.")
112 flags.StringVar(&framework.TestContext.MasterOSDistro, "master-os-distro", "debian", "The OS distribution of cluster master (debian, ubuntu, gci, coreos, or custom).")
113 flags.StringVar(&framework.TestContext.NodeOSDistro, "node-os-distro", "debian", "The OS distribution of cluster VM instances (debian, ubuntu, gci, coreos, or custom).")
114 flags.StringVar(&framework.TestContext.ClusterMonitoringMode, "cluster-monitoring-mode", "standalone", "The monitoring solution that is used in the cluster.")
115 flags.StringVar(&framework.TestContext.ClusterDNSDomain, "dns-domain", "cluster.local", "The DNS Domain of the cluster.")
116
117 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.")
118 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.")
119 flags.DurationVar(&framework.TestContext.NodeSchedulableTimeout, "node-schedulable-timeout", 30*time.Minute, "Timeout for waiting for all nodes to be schedulable.")
120 flags.DurationVar(&framework.TestContext.SystemDaemonsetStartupTimeout, "system-daemonsets-startup-timeout", 5*time.Minute, "Timeout for waiting for all system daemonsets to be ready.")
121 flags.StringVar(&framework.TestContext.EtcdUpgradeStorage, "etcd-upgrade-storage", "", "The storage version to upgrade to (either 'etcdv2' or 'etcdv3') if doing an etcd upgrade test.")
122 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.")
123 flags.StringVar(&framework.TestContext.GCEUpgradeScript, "gce-upgrade-script", "", "Script to use to upgrade a GCE cluster.")
124 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.")
125
126 nodeKiller := &framework.TestContext.NodeKiller
127 flags.BoolVar(&nodeKiller.Enabled, "node-killer", false, "Whether NodeKiller should kill any nodes.")
128 flags.Float64Var(&nodeKiller.FailureRatio, "node-killer-failure-ratio", 0.01, "Percentage of nodes to be killed")
129 flags.DurationVar(&nodeKiller.Interval, "node-killer-interval", 1*time.Minute, "Time between node failures.")
130 flags.Float64Var(&nodeKiller.JitterFactor, "node-killer-jitter-factor", 60, "Factor used to jitter node failures.")
131 flags.DurationVar(&nodeKiller.SimulatedDowntime, "node-killer-simulated-downtime", 10*time.Minute, "A delay between node death and recreation")
132 }
133