github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/loadbalancers/dynamic/desired_v0.go (about) 1 package dynamic 2 3 import ( 4 "github.com/caos/orbos/pkg/tree" 5 ) 6 7 type DesiredV0 struct { 8 Common *tree.Common `yaml:",inline"` 9 Spec map[string][]*VIPV0 10 } 11 12 func v0tov1(v0 *DesiredV0) *DesiredV1 { 13 d := DesiredV1{ 14 Spec: make(map[string][]*VIPV1, len(v0.Spec)), 15 } 16 for poolNameV0, poolV0 := range v0.Spec { 17 vips := make([]*VIPV1, len(poolV0)) 18 for vipIdx, v := range poolV0 { 19 20 var wl []*CIDRV1 21 if vipIdx == 0 { 22 for _, c := range v.Whitelist { 23 cider := CIDRV1(*c) 24 wl = append(wl, &cider) 25 } 26 } 27 28 var transport []*SourceV1 29 for _, t := range v.Transport { 30 var dest []*DestinationV1 31 for _, d := range t.Destinations { 32 dest = append(dest, &DestinationV1{ 33 HealthChecks: HealthChecksV1{ 34 Protocol: d.HealthChecks.Protocol, 35 Path: d.HealthChecks.Path, 36 Code: d.HealthChecks.Code, 37 }, 38 Port: PortV1(d.Port), 39 Pool: d.Pool, 40 }) 41 } 42 43 transport = append(transport, &SourceV1{ 44 Name: t.Name, 45 SourcePort: PortV1(t.SourcePort), 46 Destinations: dest, 47 Whitelist: wl, 48 }) 49 } 50 vips[vipIdx] = &VIPV1{ 51 IP: v.IP, 52 Transport: transport, 53 } 54 } 55 d.Spec[poolNameV0] = vips 56 } 57 return &d 58 } 59 60 type VIPV0 struct { 61 IP string 62 Whitelist []*CIDRV0 63 Transport []*SourceV0 64 } 65 66 type SourceV0 struct { 67 Name string 68 SourcePort PortV0 `yaml:",omitempty"` 69 Destinations []*DestinationV0 70 } 71 72 type CIDRV0 string 73 74 type PortV0 uint16 75 76 type DestinationV0 struct { 77 HealthChecks HealthChecksV0 78 Port PortV0 79 Pool string 80 } 81 82 type HealthChecksV0 struct { 83 Protocol string 84 Path string 85 Code uint16 86 }