-
Notifications
You must be signed in to change notification settings - Fork 432
/
bootstrap_builder.go
162 lines (148 loc) · 3.74 KB
/
bootstrap_builder.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
package envoy
import (
"bytes"
"os"
"text/template"
"github.com/onsi/ginkgo/v2"
)
type bootstrapBuilder interface {
Build(ei *Instance) string
}
type templateBootstrapBuilder struct {
template *template.Template
}
func (tbb *templateBootstrapBuilder) Build(ei *Instance) string {
var b bytes.Buffer
if err := tbb.template.Execute(&b, ei); err != nil {
ginkgo.Fail(err.Error())
}
return b.String()
}
type fileBootstrapBuilder struct {
file string
}
func (fbb *fileBootstrapBuilder) Build(ei *Instance) string {
templateBytes, err := os.ReadFile(fbb.file)
if err != nil {
ginkgo.Fail(err.Error())
}
parsedTemplate := template.Must(template.New(fbb.file).Parse(string(templateBytes)))
var b bytes.Buffer
if err := parsedTemplate.Execute(&b, ei); err != nil {
ginkgo.Fail(err.Error())
}
return b.String()
}
const boostrapText = `
layered_runtime:
layers:
- name: static_layer
static_layer:
upstream:
healthy_panic_threshold:
value: 0
- name: admin_layer
admin_layer: {}
node:
cluster: ingress
id: {{.ID}}
metadata:
role: {{.Role}}
static_resources:
clusters:
- name: xds_cluster
connect_timeout: 5.000s
load_assignment:
cluster_name: xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{.GlooAddr}}
port_value: {{.Port}}
http2_protocol_options: {}
type: STATIC
- name: rest_xds_cluster
connect_timeout: 5.000s
load_assignment:
cluster_name: rest_xds_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{.GlooAddr}}
port_value: {{.RestXdsPort}}
upstream_connection_options:
tcp_keepalive: {}
type: STRICT_DNS
respect_dns_ttl: true
{{if .RatelimitAddr}}
- name: ratelimit_cluster
connect_timeout: 5.000s
load_assignment:
cluster_name: ratelimit_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{.RatelimitAddr}}
port_value: {{.RatelimitPort}}
http2_protocol_options: {}
type: STATIC
{{end}}
{{if .AccessLogAddr}}
- name: access_log_cluster
connect_timeout: 5.000s
load_assignment:
cluster_name: access_log_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {{.AccessLogAddr}}
port_value: {{.AccessLogPort}}
http2_protocol_options: {}
type: STATIC
{{end}}
- name: aws_sts_cluster
connect_timeout: 5.000s
type: LOGICAL_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: aws_sts_cluster
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
port_value: 443
address: sts.amazonaws.com
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
sni: sts.amazonaws.com
dynamic_resources:
ads_config:
transport_api_version: {{ .ApiVersion }}
api_type: GRPC
grpc_services:
- envoy_grpc: {cluster_name: xds_cluster}
cds_config:
resource_api_version: {{ .ApiVersion }}
ads: {}
lds_config:
resource_api_version: {{ .ApiVersion }}
ads: {}
admin:
access_log_path: /dev/null
address:
socket_address:
address: 0.0.0.0
port_value: {{.AdminPort}}
`
var bootstrapTemplate = template.Must(template.New("bootstrap").Parse(boostrapText))