-
Notifications
You must be signed in to change notification settings - Fork 444
/
upstreams.go
62 lines (48 loc) · 1.24 KB
/
upstreams.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
package helpers
import (
"fmt"
"github.com/solo-io/gloo/projects/gloo/pkg/api/external/envoy/api/v2/core"
v1 "github.com/solo-io/gloo/projects/gloo/pkg/api/v1"
"github.com/solo-io/gloo/projects/gloo/pkg/api/v1/ssl"
)
// UpstreamBuilder contains options for building Upstreams to be included in scaled Snapshots
type UpstreamBuilder struct {
sniPattern sniPattern
healthChecks []*core.HealthCheck
}
type sniPattern int
const (
noSni sniPattern = iota
uniqueSni
consistentSni
)
func NewUpstreamBuilder() *UpstreamBuilder {
return &UpstreamBuilder{}
}
func (b *UpstreamBuilder) WithUniqueSni() *UpstreamBuilder {
b.sniPattern = uniqueSni
return b
}
func (b *UpstreamBuilder) WithConsistentSni() *UpstreamBuilder {
b.sniPattern = consistentSni
return b
}
func (b *UpstreamBuilder) WithHealthChecks(healthChecks []*core.HealthCheck) *UpstreamBuilder {
b.healthChecks = healthChecks
return b
}
func (b *UpstreamBuilder) Build(i int) *v1.Upstream {
up := Upstream(i)
up.HealthChecks = b.healthChecks
switch b.sniPattern {
case uniqueSni:
up.SslConfig = &ssl.UpstreamSslConfig{
Sni: fmt.Sprintf("unique-domain-%d", i),
}
case consistentSni:
up.SslConfig = &ssl.UpstreamSslConfig{
Sni: "consistent-domain",
}
}
return up
}