github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/orbiter/kinds/loadbalancers/dynamic/desired_v1.go (about)

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