diff --git a/cmd/create/create_loadbalancer.go b/cmd/create/create_loadbalancer.go index 855a531..909d9d5 100644 --- a/cmd/create/create_loadbalancer.go +++ b/cmd/create/create_loadbalancer.go @@ -52,6 +52,7 @@ type CreateLoadBalancerOptions struct { Name string Host string AllowedSources []string + PPv2En bool } type CreateLoadBalancerResult struct { @@ -139,7 +140,7 @@ func NewCreateLoadBalancerCmd(restOptions *api.RESTOptions) *cobra.Command { o := CreateLoadBalancerOptions{} var createLbCmd = &cobra.Command{ - Use: "lb IP [--select=] [--tcp=:] [--udp=:] [--sctp=:] [--icmp] [--mark=] [--secips=,] [--sources=,] [--endpoints=:,] [--mode=] [--bgp] [--monitor] [--inatimeout=] [--name=] [--attachEP] [--detachEP] [--security=] [--host=]", + Use: "lb IP [--select=] [--tcp=:] [--udp=:] [--sctp=:] [--icmp] [--mark=] [--secips=,] [--sources=,] [--endpoints=:,] [--mode=] [--bgp] [--monitor] [--inatimeout=] [--name=] [--attachEP] [--detachEP] [--security=] [--host=] [--ppv2en]", Short: "Create a LoadBalancer", Long: `Create a LoadBalancer @@ -170,6 +171,7 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2 loxicmd create lb 2001::1 --tcp=2020:8080 --endpoints=4ffe::1:1,5ffe::1:1,6ffe::1:1 loxicmd create lb 2001::1 --tcp=2020:8080 --endpoints=31.31.31.1:1,32.32.32.1:1,33.33.33.1:1 loxicmd create lb 10.10.10.254 --sctp=2020:8080 --endpoints=33.33.33.1:1 --attachEP + loxicmd create lb 100.100.100.1 --tcp=8080:80 --endpoints=10.10.10.1:1 --ppv2en `, PreRun: func(cmd *cobra.Command, args []string) { if len(args) == 0 { @@ -240,6 +242,7 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2 Oper: api.LbOP(oper), Security: api.LbSec(SecStringToNum(o.Security)), Host: o.Host, + PpV2: o.PPv2En, } if o.Mode == "dsr" && targetPort != port { @@ -308,6 +311,7 @@ ex) loxicmd create lb 192.168.0.200 --tcp=80:32015 --endpoints=10.212.0.1:1,10.2 createLbCmd.Flags().StringVarP(&o.Security, "security", "", o.Security, "Security mode for load balancer rule") createLbCmd.Flags().StringVarP(&o.Host, "host", "", o.Host, "Ingress Host URL Path") createLbCmd.Flags().StringSliceVar(&o.AllowedSources, "sources", o.AllowedSources, "Allowed sources for this rule as ''") + createLbCmd.Flags().BoolVarP(&o.PPv2En, "ppv2en", "", false, "Enable proxy procotol v2") return createLbCmd } diff --git a/cmd/get/get_loadbalancer.go b/cmd/get/get_loadbalancer.go index 91c1eb0..ed1c3e2 100644 --- a/cmd/get/get_loadbalancer.go +++ b/cmd/get/get_loadbalancer.go @@ -101,7 +101,7 @@ func NumToSecurty(sec int) string { return ret } -func NumToMode(mode int) string { +func NumToMode(mode int, ppv2 bool) string { var ret string switch mode { case 1: @@ -117,6 +117,9 @@ func NumToMode(mode int) string { default: ret = "default" } + if ppv2 { + ret += ":ppv2" + } return ret } @@ -188,7 +191,7 @@ func PrintGetLbResult(resp *http.Response, o api.RESTOptions) { for i, eps := range lbrule.Endpoints { if i == 0 { - data = append(data, []string{lbrule.Service.ExternalIP, secIPs, sources, lbrule.Service.Host, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)), + data = append(data, []string{lbrule.Service.ExternalIP, secIPs, sources, lbrule.Service.Host, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode), lbrule.Service.PpV2), eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), eps.State, eps.Counter}) } else { data = append(data, []string{"", "", "", "", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), eps.State, eps.Counter}) @@ -197,7 +200,7 @@ func PrintGetLbResult(resp *http.Response, o api.RESTOptions) { } else { for i, eps := range lbrule.Endpoints { if i == 0 { - data = append(data, []string{lbrule.Service.ExternalIP, secIPs, sources, lbrule.Service.Host, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)), + data = append(data, []string{lbrule.Service.ExternalIP, secIPs, sources, lbrule.Service.Host, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode), lbrule.Service.PpV2), eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), "-", eps.Counter}) } else { data = append(data, []string{"", "", "", "", "", "", "", "", "", "", eps.EndpointIP, fmt.Sprintf("%d", eps.TargetPort), fmt.Sprintf("%d", eps.Weight), "-", eps.Counter}) @@ -206,7 +209,7 @@ func PrintGetLbResult(resp *http.Response, o api.RESTOptions) { } } else { table.SetHeader(LOADBALANCER_TITLE) - data = append(data, []string{lbrule.Service.ExternalIP, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode)), fmt.Sprintf("%d", len(lbrule.Endpoints)), BoolToMon(lbrule.Service.Monitor)}) + data = append(data, []string{lbrule.Service.ExternalIP, fmt.Sprintf("%d", lbrule.Service.Port), protocolStr, lbrule.Service.Name, fmt.Sprintf("%d", lbrule.Service.Block), NumToSelect(int(lbrule.Service.Sel)), NumToMode(int(lbrule.Service.Mode), lbrule.Service.PpV2), fmt.Sprintf("%d", len(lbrule.Endpoints)), BoolToMon(lbrule.Service.Monitor)}) } } diff --git a/pkg/api/loadBalancer.go b/pkg/api/loadBalancer.go index 6cc7ac9..eeb4f09 100644 --- a/pkg/api/loadBalancer.go +++ b/pkg/api/loadBalancer.go @@ -56,6 +56,7 @@ type LoadBalancerService struct { Oper LbOP `json:"oper,omitempty"` Security LbSec `json:"security,omitempty" yaml:"security"` Host string `json:"host,omitempty" yaml:"path"` + PpV2 bool `json:"proxyprotocolv2" yaml:"proxyprotocolv2"` } type LoadBalancerEndpoint struct {