...
1
2
3 package model
4
5 import (
6 "fmt"
7 "io"
8 "strconv"
9
10 v1 "k8s.io/api/core/v1"
11
12 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
13 )
14
15 type Fd struct {
16 Fd string `json:"fd"`
17 Target string `json:"target"`
18 }
19
20 type Namespace struct {
21 Ns string `json:"ns"`
22 Component []*v1.Pod `json:"component"`
23 Pod []*v1.Pod `json:"pod"`
24 Stresschaos []*v1alpha1.StressChaos `json:"stresschaos"`
25 Iochaos []*v1alpha1.IOChaos `json:"iochaos"`
26 Podiochaos []*v1alpha1.PodIOChaos `json:"podiochaos"`
27 Httpchaos []*v1alpha1.HTTPChaos `json:"httpchaos"`
28 Podhttpchaos []*v1alpha1.PodHttpChaos `json:"podhttpchaos"`
29 Networkchaos []*v1alpha1.NetworkChaos `json:"networkchaos"`
30 Podnetworkchaos []*v1alpha1.PodNetworkChaos `json:"podnetworkchaos"`
31 }
32
33 type Process struct {
34 Pod *v1.Pod `json:"pod"`
35 Pid string `json:"pid"`
36 Command string `json:"command"`
37 Fds []*Fd `json:"fds"`
38 }
39
40 type Component string
41
42 const (
43 ComponentManager Component = "MANAGER"
44 ComponentDaemon Component = "DAEMON"
45 ComponentDashboard Component = "DASHBOARD"
46 ComponentDNSServer Component = "DNSSERVER"
47 )
48
49 var AllComponent = []Component{
50 ComponentManager,
51 ComponentDaemon,
52 ComponentDashboard,
53 ComponentDNSServer,
54 }
55
56 func (e Component) IsValid() bool {
57 switch e {
58 case ComponentManager, ComponentDaemon, ComponentDashboard, ComponentDNSServer:
59 return true
60 }
61 return false
62 }
63
64 func (e Component) String() string {
65 return string(e)
66 }
67
68 func (e *Component) UnmarshalGQL(v interface{}) error {
69 str, ok := v.(string)
70 if !ok {
71 return fmt.Errorf("enums must be strings")
72 }
73
74 *e = Component(str)
75 if !e.IsValid() {
76 return fmt.Errorf("%s is not a valid Component", str)
77 }
78 return nil
79 }
80
81 func (e Component) MarshalGQL(w io.Writer) {
82 fmt.Fprint(w, strconv.Quote(e.String()))
83 }
84