added annotations

This commit is contained in:
ston1th 2021-04-10 02:46:35 +02:00
commit 9e85a199a7
4 changed files with 35 additions and 2 deletions

2
go.mod
View file

@ -3,7 +3,7 @@ module git.giftfish.de/ston1th/cloud-controller-manager-pve
go 1.13
require (
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210409233730-d130ea4e2b17
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210410004255-5de98614da2a
git.giftfish.de/ston1th/pve-go v0.0.0-20201101190916-eb9546c9aff3
github.com/go-logr/logr v0.4.0
github.com/google/uuid v1.1.2 // indirect

2
go.sum
View file

@ -16,6 +16,8 @@ git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210409203803-6da132106f8f h1:EZkCEZp
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210409203803-6da132106f8f/go.mod h1:6uEaQksVEIIoMSaQ93Tw0jRyqCwwgxxh6hyffTNmT1Y=
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210409233730-d130ea4e2b17 h1:bPDD8/T+5+M/qpQV2ipgBbj7uzu2/rYTK4QDOAz7Lc4=
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210409233730-d130ea4e2b17/go.mod h1:6uEaQksVEIIoMSaQ93Tw0jRyqCwwgxxh6hyffTNmT1Y=
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210410004255-5de98614da2a h1:AEdyjqQIVPKgBsGuouJlM/p+L/+di/lMexAp78uOl9U=
git.giftfish.de/ston1th/haproxy-lb v0.0.0-20210410004255-5de98614da2a/go.mod h1:6uEaQksVEIIoMSaQ93Tw0jRyqCwwgxxh6hyffTNmT1Y=
git.giftfish.de/ston1th/pve-go v0.0.0-20201101190916-eb9546c9aff3 h1:7qaAhq9dXZYCdGT/TpwVUpWjEntxbPJrPgFgo3wPFU4=
git.giftfish.de/ston1th/pve-go v0.0.0-20201101190916-eb9546c9aff3/go.mod h1:WOrvThayhaB89KZwQqGzqcTD9nVeTsnaRB1vBaeb2tM=
git.giftfish.de/ston1th/raftbbolt v0.0.0-20201114165203-b85c94bfc9b0/go.mod h1:9dF/aHYkXts6/6oVyJ+vzXCn7NURDaoREaanX0aspx0=

View file

@ -2,6 +2,12 @@ apiVersion: v1
kind: Service
metadata:
name: nginx
annotations:
#frontend.haproxy-lb/options: "tcplog,splice-request"
#backend.haproxy-lb/options: "splice-response,httpchk GET /"
#backend.haproxy-lb/proxy-protocol: v2
#backend.haproxy-lb/check-proxy-protocol: true
#backend.haproxy-lb/default-server: ""
spec:
selector:
app: nginx

View file

@ -14,6 +14,7 @@ package pvecloud
import (
"context"
"strings"
apiclient "git.giftfish.de/ston1th/haproxy-lb/pkg/api/client"
"git.giftfish.de/ston1th/haproxy-lb/pkg/api/v1/client"
@ -60,8 +61,32 @@ func (lb *loadbalancer) GetLoadBalancerName(ctx context.Context, clusterName str
}
func (lb *loadbalancer) EnsureLoadBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node) (status *v1.LoadBalancerStatus, err error) {
// TODO service annotations
/*TODO service annotations
port <node.Status.HealthCheckNodePort (int32)>
https://pkg.go.dev/k8s.io/api/core/v1#NodeStatus
node.Status.ExternalTrafficPolicy ?
v1.ServiceExternalTrafficPolicyTypeLocal
v1.ServiceExternalTrafficPolicyTypeCluster
*/
var slb schema.LoadBalancer
if fo, ok := service.Annotations["frontend.haproxy-lb/options"]; ok {
slb.Options.Frontend = strings.Split(fo, ",")
}
if bo, ok := service.Annotations["backend.haproxy-lb/options"]; ok {
slb.Options.Backend = strings.Split(bo, ",")
}
if cp, ok := service.Annotations["backend.haproxy-lb/proxy-protocol"]; ok {
if cp == "v1" || cp == "v2" {
slb.Options.ProxyProtocol = cp
}
}
if cpp, ok := service.Annotations["backend.haproxy-lb/check-proxy-protocol"]; ok {
slb.Options.CheckProxyProtocol = cpp == "true"
}
if df, ok := service.Annotations["backend.haproxy-lb/default-server"]; ok {
slb.Options.DefaultServer = df
}
for _, port := range service.Spec.Ports {
sp := schema.Port{Port: int(port.Port)}
for _, node := range nodes {