-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stability: use fault-trigger at e2e tests and add some log (#330)
- Loading branch information
Showing
12 changed files
with
355 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
nodes: | ||
- physical_node: 172.16.4.39 | ||
nodes: | ||
- 172.16.4.171 | ||
- 172.16.4.172 | ||
- 172.16.4.173 | ||
- physical_node: 172.16.4.40 | ||
nodes: | ||
- 172.16.4.174 | ||
- 172.16.4.175 | ||
- 172.16.4.176 | ||
etcds: | ||
- physical_node: 172.16.4.39 | ||
nodes: | ||
- 172.16.4.171 | ||
- 172.16.4.172 | ||
- 172.16.4.173 | ||
apiservers: | ||
- physical_node: 172.16.4.39 | ||
nodes: | ||
- 172.16.4.171 | ||
- 172.16.4.172 | ||
- 172.16.4.173 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package tests | ||
|
||
import ( | ||
"flag" | ||
"io/ioutil" | ||
|
||
yaml "gopkg.in/yaml.v2" | ||
) | ||
|
||
// Config defines the config of operator tests | ||
type Config struct { | ||
configFile string | ||
|
||
LogDir string `yaml:"log_dir" json:"log_dir"` | ||
FaultTriggerPort int `yaml:"fault_trigger_port" json:"fault_trigger_port"` | ||
Nodes []Nodes `yaml:"nodes" json:"nodes"` | ||
ETCDs []Nodes `yaml:"etcds" json:"etcds"` | ||
APIServers []Nodes `yaml:"apiservers" json:"apiservers"` | ||
} | ||
|
||
// Nodes defines a series of nodes that belong to the same physical node. | ||
type Nodes struct { | ||
PhysicalNode string `yaml:"physical_node" json:"physical_node"` | ||
Nodes []string `yaml:"nodes" json:"nodes"` | ||
} | ||
|
||
// NewConfig creates a new config. | ||
func NewConfig() *Config { | ||
cfg := &Config{} | ||
flag.StringVar(&cfg.configFile, "config", "/etc/e2e/config.yaml", "Config file") | ||
flag.StringVar(&cfg.LogDir, "log-dir", "/logDir", "log directory") | ||
flag.IntVar(&cfg.FaultTriggerPort, "fault-trigger-port", 23332, "the http port of fault trigger service") | ||
|
||
return cfg | ||
} | ||
|
||
// Parse parses flag definitions from the argument list. | ||
func (c *Config) Parse() error { | ||
// Parse first to get config file | ||
flag.Parse() | ||
|
||
if c.configFile != "" { | ||
if err := c.configFromFile(c.configFile); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Parse again to replace with command line options. | ||
flag.Parse() | ||
|
||
return nil | ||
} | ||
|
||
func (c *Config) configFromFile(path string) error { | ||
data, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err = yaml.Unmarshal(data, c); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package tests | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/golang/glog" | ||
"github.com/pingcap/tidb-operator/pkg/client/clientset/versioned" | ||
"github.com/pingcap/tidb-operator/pkg/controller" | ||
"github.com/pingcap/tidb-operator/tests/pkg/fault-trigger/client" | ||
"github.com/pingcap/tidb-operator/tests/pkg/fault-trigger/manager" | ||
"k8s.io/client-go/kubernetes" | ||
) | ||
|
||
type FaultTriggerActions interface { | ||
StopNode(physicalNode string, node string) error | ||
StartNode(physicalNode string, node string) error | ||
StopETCD(nodes ...string) error | ||
StartETCD(nodes ...string) error | ||
StopKubelet(node string) error | ||
StartKubelet(node string) error | ||
// TODO: support more faults | ||
// StopKubeAPIServer() error | ||
// StartKubeAPIServer() error | ||
// StopKubeControllerManager() error | ||
// StartKubeControllerManager() error | ||
// StopKubeScheduler() error | ||
// StartKubeScheduler() error | ||
// StopKubeProxy(node string) error | ||
// StartKubeProxy(node string) error | ||
// DiskCorruption(node string) error | ||
// NetworkPartition(fromNode, toNode string) error | ||
// NetworkDelay(fromNode, toNode string) error | ||
// DockerCrash(nodeName string) error | ||
} | ||
|
||
func NewFaultTriggerAction(cli versioned.Interface, kubeCli kubernetes.Interface, cfg *Config) FaultTriggerActions { | ||
return &faultTriggerActions{ | ||
cli: cli, | ||
kubeCli: kubeCli, | ||
pdControl: controller.NewDefaultPDControl(), | ||
cfg: cfg, | ||
} | ||
} | ||
|
||
type faultTriggerActions struct { | ||
cli versioned.Interface | ||
kubeCli kubernetes.Interface | ||
pdControl controller.PDControlInterface | ||
cfg *Config | ||
} | ||
|
||
func (fa *faultTriggerActions) StopNode(physicalNode string, node string) error { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: fa.genFaultTriggerAddr(physicalNode), | ||
}) | ||
|
||
err := faultCli.StopVM(&manager.VM{ | ||
IP: node, | ||
}) | ||
|
||
if err != nil { | ||
glog.Errorf("failed to stop node %s on physical node: %s: %v", node, physicalNode, err) | ||
return err | ||
} | ||
|
||
glog.Infof("node %s on physical node %s is stopped", node, physicalNode) | ||
|
||
return nil | ||
} | ||
|
||
func (fa *faultTriggerActions) StartNode(physicalNode string, node string) error { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: fa.genFaultTriggerAddr(physicalNode), | ||
}) | ||
|
||
err := faultCli.StartVM(&manager.VM{ | ||
IP: node, | ||
}) | ||
|
||
if err != nil { | ||
glog.Errorf("failed to start node %s on physical node %s: %v", node, physicalNode, err) | ||
return err | ||
} | ||
|
||
glog.Infof("node %s on physical node %s is started", physicalNode, node) | ||
|
||
return nil | ||
} | ||
|
||
// StopETCD stops the etcd service. | ||
// If the `nodes` is empty, StopEtcd will stop all etcd service. | ||
func (fa *faultTriggerActions) StopETCD(nodes ...string) error { | ||
if len(nodes) == 0 { | ||
for _, ns := range fa.cfg.ETCDs { | ||
nodes = append(nodes, ns.Nodes...) | ||
} | ||
} | ||
|
||
for _, node := range nodes { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: fa.genFaultTriggerAddr(node), | ||
}) | ||
|
||
if err := faultCli.StopETCD(); err != nil { | ||
glog.Errorf("failed to stop etcd %s: %v", node, err) | ||
return err | ||
} | ||
|
||
glog.Infof("etcd %s is stopped", node) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// StartETCD starts the etcd service. | ||
// If the `nodes` is empty, StartETCD will start all etcd service. | ||
func (fa *faultTriggerActions) StartETCD(nodes ...string) error { | ||
if len(nodes) == 0 { | ||
for _, ns := range fa.cfg.ETCDs { | ||
nodes = append(nodes, ns.Nodes...) | ||
} | ||
} | ||
|
||
for _, node := range nodes { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: fa.genFaultTriggerAddr(node), | ||
}) | ||
|
||
if err := faultCli.StartETCD(); err != nil { | ||
glog.Errorf("failed to start etcd %s: %v", node, err) | ||
return err | ||
} | ||
|
||
glog.Infof("etcd %s is started", node) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// StopKubelet stops the kubelet service. | ||
func (fa *faultTriggerActions) StopKubelet(node string) error { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: fa.genFaultTriggerAddr(node), | ||
}) | ||
|
||
if err := faultCli.StopKubelet(); err != nil { | ||
glog.Errorf("failed to stop kubelet %s: %v", node, err) | ||
return err | ||
} | ||
|
||
glog.Infof("kubelet %s is stopped", node) | ||
|
||
return nil | ||
} | ||
|
||
// StartKubelet starts the kubelet service. | ||
func (fa *faultTriggerActions) StartKubelet(node string) error { | ||
faultCli := client.NewClient(client.Config{ | ||
Addr: node, | ||
}) | ||
|
||
if err := faultCli.StartKubelet(); err != nil { | ||
glog.Errorf("failed to start kubelet %s: %v", node, err) | ||
return err | ||
} | ||
|
||
glog.Infof("kubelet %s is started", node) | ||
|
||
return nil | ||
} | ||
|
||
func (fa *faultTriggerActions) genFaultTriggerAddr(node string) string { | ||
return fmt.Sprintf("%s:%d", node, fa.cfg.FaultTriggerPort) | ||
} |
Oops, something went wrong.