This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
/
desired_v0.go
86 lines (74 loc) · 1.62 KB
/
desired_v0.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
package dynamic
import (
"github.com/caos/orbos/internal/tree"
)
type DesiredV0 struct {
Common *tree.Common `yaml:",inline"`
Spec map[string][]*VIPV0
}
func v0tov1(v0 *DesiredV0) *DesiredV1 {
d := DesiredV1{
Spec: make(map[string][]*VIPV1, len(v0.Spec)),
}
for poolNameV0, poolV0 := range v0.Spec {
vips := make([]*VIPV1, len(poolV0))
for vipIdx, v := range poolV0 {
var wl []*CIDRV1
if vipIdx == 0 {
for _, c := range v.Whitelist {
cider := CIDRV1(*c)
wl = append(wl, &cider)
}
}
var transport []*SourceV1
for _, t := range v.Transport {
var dest []*DestinationV1
for _, d := range t.Destinations {
dest = append(dest, &DestinationV1{
HealthChecks: HealthChecksV1{
Protocol: d.HealthChecks.Protocol,
Path: d.HealthChecks.Path,
Code: d.HealthChecks.Code,
},
Port: PortV1(d.Port),
Pool: d.Pool,
})
}
transport = append(transport, &SourceV1{
Name: t.Name,
SourcePort: PortV1(t.SourcePort),
Destinations: dest,
Whitelist: wl,
})
}
vips[vipIdx] = &VIPV1{
IP: v.IP,
Transport: transport,
}
}
d.Spec[poolNameV0] = vips
}
return &d
}
type VIPV0 struct {
IP string
Whitelist []*CIDRV0
Transport []*SourceV0
}
type SourceV0 struct {
Name string
SourcePort PortV0 `yaml:",omitempty"`
Destinations []*DestinationV0
}
type CIDRV0 string
type PortV0 uint16
type DestinationV0 struct {
HealthChecks HealthChecksV0
Port PortV0
Pool string
}
type HealthChecksV0 struct {
Protocol string
Path string
Code uint16
}