-
Notifications
You must be signed in to change notification settings - Fork 775
/
virtual_service.go
190 lines (173 loc) · 5.08 KB
/
virtual_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// RAINBOND, Application Management Platform
// Copyright (C) 2014-2017 Goodrain Co., Ltd.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. For any non-GPL usage of Rainbond,
// one or multiple Commercial Licenses authorized by Goodrain Co., Ltd.
// must be obtained first.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package v1
import corev1 "k8s.io/api/core/v1"
// Protocol defines network protocols supported for things like container ports.
type Protocol string
const (
// ProtocolTCP is the TCP protocol.
ProtocolTCP Protocol = "TCP"
// ProtocolUDP is the UDP protocol.
ProtocolUDP Protocol = "UDP"
// ProtocolSCTP is the SCTP protocol.
ProtocolSCTP Protocol = "SCTP"
)
//VirtualService VirtualService
type VirtualService struct {
Meta
Enabled bool `json:"enable"`
Protocol corev1.Protocol `json:"protocol"`
// BackendProtocol indicates which protocol should be used to communicate with the service
BackendProtocol string `json:"backend-protocol"`
Port int32 `json:"port"`
Listening []string `json:"listening"` //if Listening is nil,will listen all
Note string `json:"note"`
DefaultPoolName string `json:"default_pool_name"`
RuleNames []string `json:"rule_names"`
SSLdecrypt bool `json:"ssl_decrypt"`
DefaultCertificateName string `json:"default_certificate_name"`
RequestLogEnable bool `json:"request_log_enable"`
RequestLogFileName string `json:"request_log_file_name"`
RequestLogFormat string `json:"request_log_format"`
//ConnectTimeout The time, in seconds, to wait for data from a new connection. If no data is received within this time, the connection will be closed. A value of 0 (zero) will disable the timeout.
ConnectTimeout int `json:"connect_timeout"`
//Timeout A connection should be closed if no additional data has been received for this period of time. A value of 0 (zero) will disable this timeout. Note that the default value may vary depending on the protocol selected.
Timeout int `json:"timeout"`
ServerName string `json:"server_name"`
PoolName string `json:"pool_name"`
SSLCert *SSLCert `json:"ssl_cert"`
Locations []*Location `json:"locations"`
ForceSSLRedirect bool `json:"force_ssl_redirect"`
ExtensionConfig map[string]interface{} `json:"extension_config"`
}
//Equals equals vs
func (v *VirtualService) Equals(c *VirtualService) bool {
if v == c {
return true
}
if v == nil || c == nil {
return false
}
if !v.Meta.Equals(&c.Meta) {
return false
}
if v.Enabled != c.Enabled {
return false
}
if v.Protocol != c.Protocol {
return false
}
if v.BackendProtocol != c.BackendProtocol {
return false
}
if v.Port != c.Port {
return false
}
// TODO: this snippet needs improvement
if len(v.Listening) != len(c.Listening) {
return false
}
for _, vl := range v.Listening {
flag := false
for _, cl := range c.Listening {
if vl == cl {
flag = true
break
}
}
if !flag {
return false
}
}
if v.Note != c.Note {
return false
}
if v.DefaultPoolName != c.DefaultPoolName {
return false
}
// TODO: this snippet needs improvement
if len(v.RuleNames) != len(c.RuleNames) {
return false
}
for _, vr := range v.RuleNames {
flag := false
for _, cr := range c.RuleNames {
if vr == cr {
flag = true
break
}
}
if !flag {
return false
}
}
if v.SSLdecrypt != c.SSLdecrypt {
return false
}
if v.DefaultCertificateName != c.DefaultCertificateName {
return false
}
if v.RequestLogEnable != c.RequestLogEnable {
return false
}
if v.RequestLogFileName != c.RequestLogFileName {
return false
}
if v.RequestLogFormat != c.RequestLogFormat {
return false
}
if v.ConnectTimeout != c.ConnectTimeout {
return false
}
if v.Timeout != c.Timeout {
return false
}
if v.ServerName != c.ServerName {
return false
}
if v.PoolName != c.PoolName {
return false
}
if len(v.Locations) != len(c.Locations) {
return false
}
for _, vloc := range v.Locations {
flag := false
for _, cloc := range c.Locations {
if vloc.Equals(cloc) {
flag = true
break
}
}
if !flag {
return false
}
}
if !v.SSLCert.Equals(c.SSLCert) {
return false
}
if v.ForceSSLRedirect != c.ForceSSLRedirect {
return false
}
if len(v.ExtensionConfig) != len(c.ExtensionConfig) {
return false
}
for key, ve := range v.ExtensionConfig {
if c.ExtensionConfig[key] != ve {
return false
}
}
return true
}