Skip to content

Commit 67f3666

Browse files
committed
MINOR: add quic support
1 parent 40f79b0 commit 67f3666

16 files changed

+244
-27
lines changed

crs/api/ingress/v1/backend.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.2"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.3-0.20240213005611-75890279f890"
2626

2727
// Backend is a specification for a Backend resource
2828
type Backend struct {

crs/api/ingress/v1/defaults.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.2"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.3-0.20240213005611-75890279f890"
2626

2727
// Defaults is a specification for a Defaults resource
2828
type Defaults struct {

crs/api/ingress/v1/global.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.2"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.3-0.20240213005611-75890279f890"
2626
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.default_path)", message="spec.config.default_path is set by ingress controller internally"
2727
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.master__dash__worker)", message="spec.config.master-worker is set by ingress controller internally"
2828
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.pidfile)", message="spec.config.pidfile is set by ingress controller internally"

crs/definition/ingress.v1.haproxy.org_backends.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.2
7+
haproxy.org/client-native: v5.1.3-0.20240213005611-75890279f890
88
name: backends.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

crs/definition/ingress.v1.haproxy.org_defaults.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.2
7+
haproxy.org/client-native: v5.1.3-0.20240213005611-75890279f890
88
name: defaults.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

crs/definition/ingress.v1.haproxy.org_globals.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.2
7+
haproxy.org/client-native: v5.1.3-0.20240213005611-75890279f890
88
name: globals.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

go.mod

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/google/renameio v1.0.1
1010
github.com/haproxytech/client-native/v2 v2.5.2-0.20220126142624-4a2781a21376
1111
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
12-
github.com/haproxytech/client-native/v5 v5.1.2
12+
github.com/haproxytech/client-native/v5 v5.1.3-0.20240213005611-75890279f890
1313
github.com/haproxytech/config-parser/v5 v5.1.0
1414
github.com/jessevdk/go-flags v1.4.0
1515
github.com/pires/go-proxyproto v0.7.0
@@ -37,15 +37,15 @@ require (
3737
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
3838
github.com/evanphx/json-patch/v5 v5.7.0 // indirect
3939
github.com/go-logr/logr v1.4.1 // indirect
40-
github.com/go-openapi/analysis v0.22.0 // indirect
40+
github.com/go-openapi/analysis v0.22.2 // indirect
4141
github.com/go-openapi/errors v0.21.0 // indirect
4242
github.com/go-openapi/jsonpointer v0.20.2 // indirect
4343
github.com/go-openapi/jsonreference v0.20.4 // indirect
44-
github.com/go-openapi/loads v0.21.3 // indirect
45-
github.com/go-openapi/spec v0.20.13 // indirect
46-
github.com/go-openapi/strfmt v0.21.10 // indirect
44+
github.com/go-openapi/loads v0.21.5 // indirect
45+
github.com/go-openapi/spec v0.20.14 // indirect
46+
github.com/go-openapi/strfmt v0.22.0 // indirect
4747
github.com/go-openapi/swag v0.22.9 // indirect
48-
github.com/go-openapi/validate v0.22.4 // indirect
48+
github.com/go-openapi/validate v0.23.0 // indirect
4949
github.com/gofrs/flock v0.8.1 // indirect
5050
github.com/gogo/protobuf v1.3.2 // indirect
5151
github.com/golang/protobuf v1.5.3 // indirect

go.sum

+14-14
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
3434
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
3535
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
3636
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
37-
github.com/go-faker/faker/v4 v4.2.0 h1:dGebOupKwssrODV51E0zbMrv5e2gO9VWSLNC1WDCpWg=
38-
github.com/go-faker/faker/v4 v4.2.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4=
37+
github.com/go-faker/faker/v4 v4.3.0 h1:UXOW7kn/Mwd0u6MR30JjUKVzguT20EB/hBOddAAO+DY=
38+
github.com/go-faker/faker/v4 v4.3.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4=
3939
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
4040
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
4141
github.com/go-logr/zapr v1.2.4 h1:QHVo+6stLbfJmYGkQ7uGHUCu5hnAFAj6mDe6Ea0SeOo=
@@ -47,8 +47,8 @@ github.com/go-openapi/analysis v0.19.2/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9sn
4747
github.com/go-openapi/analysis v0.19.4/go.mod h1:3P1osvZa9jKjb8ed2TPng3f0i/UY9snX6gxi44djMjk=
4848
github.com/go-openapi/analysis v0.19.5/go.mod h1:hkEAkxagaIvIP7VTn8ygJNkd4kAYON2rCu0v0ObL0AU=
4949
github.com/go-openapi/analysis v0.19.10/go.mod h1:qmhS3VNFxBlquFJ0RGoDtylO9y4pgTAUNE9AEEMdlJQ=
50-
github.com/go-openapi/analysis v0.22.0 h1:wQ/d07nf78HNj4u+KiSY0sT234IAyePPbMgpUjUJQR0=
51-
github.com/go-openapi/analysis v0.22.0/go.mod h1:acDnkkCI2QxIo8sSIPgmp1wUlRohV7vfGtAIVae73b0=
50+
github.com/go-openapi/analysis v0.22.2 h1:ZBmNoP2h5omLKr/srIC9bfqrUGzT6g6gNv03HE9Vpj0=
51+
github.com/go-openapi/analysis v0.22.2/go.mod h1:pDF4UbZsQTo/oNuRfAWWd4dAh4yuYf//LYorPTjrpvo=
5252
github.com/go-openapi/errors v0.17.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
5353
github.com/go-openapi/errors v0.18.0/go.mod h1:LcZQpmvG4wyF5j4IhA73wkLFQg+QJXOQHVjmcZxhka0=
5454
github.com/go-openapi/errors v0.19.2/go.mod h1:qX0BLWsyaKfvhluLejVpVNwNRdXZhEbTA4kxxpKBC94=
@@ -74,8 +74,8 @@ github.com/go-openapi/loads v0.19.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf
7474
github.com/go-openapi/loads v0.19.2/go.mod h1:QAskZPMX5V0C2gvfkGZzJlINuP7Hx/4+ix5jWFxsNPs=
7575
github.com/go-openapi/loads v0.19.3/go.mod h1:YVfqhUCdahYwR3f3iiwQLhicVRvLlU/WO5WPaZvcvSI=
7676
github.com/go-openapi/loads v0.19.5/go.mod h1:dswLCAdonkRufe/gSUC3gN8nTSaB9uaS2es0x5/IbjY=
77-
github.com/go-openapi/loads v0.21.3 h1:8sSH2FIm/SnbDUGv572md4YqVMFne/a9Eubvcd3anew=
78-
github.com/go-openapi/loads v0.21.3/go.mod h1:Y3aMR24iHbKHppOj91nQ/SHc0cuPbAr4ndY4a02xydc=
77+
github.com/go-openapi/loads v0.21.5 h1:jDzF4dSoHw6ZFADCGltDb2lE4F6De7aWSpe+IcsRzT0=
78+
github.com/go-openapi/loads v0.21.5/go.mod h1:PxTsnFBoBe+z89riT+wYt3prmSBP6GDAQh2l9H1Flz8=
7979
github.com/go-openapi/runtime v0.0.0-20180920151709-4f900dc2ade9/go.mod h1:6v9a6LTXWQCdL8k1AO3cvqx5OtZY/Y9wKTgaoP6YRfA=
8080
github.com/go-openapi/runtime v0.19.0/go.mod h1:OwNfisksmmaZse4+gpV3Ne9AyMOlP1lt4sK4FXt0O64=
8181
github.com/go-openapi/runtime v0.19.4/go.mod h1:X277bwSUBxVlCYR3r7xgZZGKVvBd/29gLDlFGtJ8NL4=
@@ -86,17 +86,17 @@ github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcs
8686
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
8787
github.com/go-openapi/spec v0.19.6/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
8888
github.com/go-openapi/spec v0.19.7/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
89-
github.com/go-openapi/spec v0.20.13 h1:XJDIN+dLH6vqXgafnl5SUIMnzaChQ6QTo0/UPMbkIaE=
90-
github.com/go-openapi/spec v0.20.13/go.mod h1:8EOhTpBoFiask8rrgwbLC3zmJfz4zsCUueRuPM6GNkw=
89+
github.com/go-openapi/spec v0.20.14 h1:7CBlRnw+mtjFGlPDRZmAMnq35cRzI91xj03HVyUi/Do=
90+
github.com/go-openapi/spec v0.20.14/go.mod h1:8EOhTpBoFiask8rrgwbLC3zmJfz4zsCUueRuPM6GNkw=
9191
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
9292
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
9393
github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY=
9494
github.com/go-openapi/strfmt v0.19.2/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6+bY1AVL9LU=
9595
github.com/go-openapi/strfmt v0.19.3/go.mod h1:0yX7dbo8mKIvc3XSKp7MNfxw4JytCfCD6+bY1AVL9LU=
9696
github.com/go-openapi/strfmt v0.19.4/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk=
9797
github.com/go-openapi/strfmt v0.19.5/go.mod h1:eftuHTlB/dI8Uq8JJOyRlieZf+WkkxUuk0dgdHXr2Qk=
98-
github.com/go-openapi/strfmt v0.21.10 h1:JIsly3KXZB/Qf4UzvzJpg4OELH/0ASDQsyk//TTBDDk=
99-
github.com/go-openapi/strfmt v0.21.10/go.mod h1:vNDMwbilnl7xKiO/Ve/8H8Bb2JIInBnH+lqiw6QWgis=
98+
github.com/go-openapi/strfmt v0.22.0 h1:Ew9PnEYc246TwrEspvBdDHS4BVKXy/AOVsfqGDgAcaI=
99+
github.com/go-openapi/strfmt v0.22.0/go.mod h1:HzJ9kokGIju3/K6ap8jL+OlGAbjpSv27135Yr9OivU4=
100100
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
101101
github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
102102
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
@@ -107,8 +107,8 @@ github.com/go-openapi/swag v0.22.9/go.mod h1:3/OXnFfnMAwBD099SwYRk7GD3xOrr1iL7d/
107107
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
108108
github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA=
109109
github.com/go-openapi/validate v0.19.3/go.mod h1:90Vh6jjkTn+OT1Eefm0ZixWNFjhtOH7vS9k0lo6zwJo=
110-
github.com/go-openapi/validate v0.22.4 h1:5v3jmMyIPKTR8Lv9syBAIRxG6lY0RqeBPB1LKEijzk8=
111-
github.com/go-openapi/validate v0.22.4/go.mod h1:qm6O8ZIcPVdSY5219468Jv7kBdGvkiZLPOmqnqTUZ2A=
110+
github.com/go-openapi/validate v0.23.0 h1:2l7PJLzCis4YUGEoW6eoQw3WhyM65WSIcjX6SQnlfDw=
111+
github.com/go-openapi/validate v0.23.0/go.mod h1:EeiAZ5bmpSIOJV1WLfyYF9qp/B1ZgSaEpHTJHtN5cbE=
112112
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
113113
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
114114
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
@@ -172,8 +172,8 @@ github.com/haproxytech/client-native/v2 v2.5.2-0.20220126142624-4a2781a21376 h1:
172172
github.com/haproxytech/client-native/v2 v2.5.2-0.20220126142624-4a2781a21376/go.mod h1:MTl8dabMibEE9ytnR1uPOFbcJ7XtYKEhxnBcqBP8kXM=
173173
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed h1:qjKxpoe4wYQmpGrrooqau88Fgusy9VQfulpXghBDqx8=
174174
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed/go.mod h1:xRVluo27FAjK4ag33+jUfpnNf9olXQlTRHUl3VMvq98=
175-
github.com/haproxytech/client-native/v5 v5.1.2 h1:dKENRtRzkzWWw7s/sF8/3Suz8soQXVd5KHoTJN/HS7o=
176-
github.com/haproxytech/client-native/v5 v5.1.2/go.mod h1:0jS6IZLjDDYxpbJGnomwqWrDh2a0/EsvyQXG6sEUVe4=
175+
github.com/haproxytech/client-native/v5 v5.1.3-0.20240213005611-75890279f890 h1:3C4xBxJ2G/M5dIzqUwtYG53eJjlhmaEZJskGnP/BATc=
176+
github.com/haproxytech/client-native/v5 v5.1.3-0.20240213005611-75890279f890/go.mod h1:p2nO/UaaNpT6oHfZ+FrICKt7UlRLa5yqE/COUy79qK4=
177177
github.com/haproxytech/config-parser/v4 v4.0.0-rc2.0.20220126135717-1dd35f8b7a52/go.mod h1:pEuHx+aFhn0lIdvAg1OaawQfeRkpq1I8HzjtZN4/PLI=
178178
github.com/haproxytech/config-parser/v5 v5.1.0 h1:gdifNXscsx4x++GQWw9Oj3JDpJMgSLtCiXgdQqxsYQU=
179179
github.com/haproxytech/config-parser/v5 v5.1.0/go.mod h1:iy8nBB1eopwYbyeh3FQpjxZUxfcIDyTV9bW0F1t+cVA=

pkg/annotations/common/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var DefaultValues = map[string]string{
6262
"scale-server-slots": "42",
6363
"client-crt-optional": "false",
6464
"tls-alpn": "h2,http/1.1",
65+
"quic-alt-svc-max-age": "60",
6566
}
6667

6768
// Returns the first annotation value in the set of maps of annotations along with the indice of which map in argument provided the value.

pkg/controller/handler.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,31 @@ func (c *HAProxyController) initHandlers() {
5454
c.updateStatusManager,
5555
}
5656

57-
c.updateHandlers = append(c.updateHandlers, handler.Refresh{})
57+
defer func() { c.updateHandlers = append(c.updateHandlers, handler.Refresh{}) }()
5858

5959
c.beforeUpdateHandlers = []UpdateHandler{}
6060
// Need to be before Refresh. If after, maps are refreshed without pprof content
6161
if c.osArgs.PprofEnabled {
6262
c.beforeUpdateHandlers = append(c.beforeUpdateHandlers, handler.Pprof{})
6363
}
64+
65+
if !c.osArgs.DisableQuic {
66+
c.updateHandlers = append(c.updateHandlers, &handler.Quic{
67+
IPv4: !c.osArgs.DisableIPV4,
68+
AddrIPv4: c.osArgs.IPV4BindAddr,
69+
IPv6: !c.osArgs.DisableIPV6,
70+
AddrIPv6: c.osArgs.IPV6BindAddr,
71+
Port: c.osArgs.HTTPSBindPort,
72+
CertDir: c.haproxy.Certs.FrontendDir,
73+
QuicAnnouncePort: func() int64 {
74+
if c.osArgs.QuicAnnouncePort != 0 {
75+
return c.osArgs.QuicAnnouncePort
76+
}
77+
return c.osArgs.HTTPSBindPort
78+
}(),
79+
MaxAge: "0",
80+
})
81+
}
6482
}
6583

6684
func (c *HAProxyController) startupHandlers() error {

pkg/handler/quic.go

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package handler
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/haproxytech/client-native/v5/models"
7+
"github.com/haproxytech/kubernetes-ingress/pkg/annotations"
8+
"github.com/haproxytech/kubernetes-ingress/pkg/annotations/common"
9+
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy"
10+
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/instance"
11+
"github.com/haproxytech/kubernetes-ingress/pkg/haproxy/rules"
12+
"github.com/haproxytech/kubernetes-ingress/pkg/store"
13+
"github.com/haproxytech/kubernetes-ingress/pkg/utils"
14+
)
15+
16+
const (
17+
QUIC4BIND = "quicv4"
18+
QUIC6BIND = "quicv6"
19+
)
20+
21+
type Quic struct {
22+
AddrIPv4 string
23+
AddrIPv6 string
24+
IPv4 bool
25+
IPv6 bool
26+
Port int64
27+
CertDir string
28+
QuicAnnouncePort int64
29+
MaxAge string
30+
}
31+
32+
func (q *Quic) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) {
33+
var errs utils.Errors
34+
defer func() {
35+
err = errs.Result()
36+
}()
37+
var bindv4Present, bindv6Present bool
38+
binds, errBindsGet := h.FrontendBindsGet(h.FrontHTTPS)
39+
if errBindsGet != nil {
40+
errs.Add(errBindsGet)
41+
return
42+
}
43+
44+
for _, bind := range binds {
45+
bindv4Present = bindv4Present || bind.Name == QUIC4BIND
46+
bindv6Present = bindv6Present || bind.Name == QUIC6BIND
47+
}
48+
49+
ipv4Func := func() {
50+
if bindv4Present {
51+
return
52+
}
53+
54+
errFrontendBindCreate := h.FrontendBindCreate(h.FrontHTTPS, models.Bind{
55+
Address: func() (addr string) {
56+
addr = "quic4@" + q.AddrIPv4
57+
return
58+
}(),
59+
Port: utils.PtrInt64(q.Port),
60+
BindParams: models.BindParams{
61+
Name: QUIC4BIND,
62+
Ssl: true,
63+
SslCertificate: q.CertDir,
64+
Alpn: "h3",
65+
},
66+
})
67+
errs.Add(errFrontendBindCreate)
68+
instance.ReloadIf(errFrontendBindCreate == nil, "quic binding v4 created")
69+
}
70+
71+
ipv6Func := func() {
72+
if bindv6Present {
73+
return
74+
}
75+
errFrontendBindCreate := h.FrontendBindCreate(h.FrontHTTPS, models.Bind{
76+
Address: func() (addr string) {
77+
addr = "quic6@" + q.AddrIPv6
78+
return
79+
}(),
80+
Port: utils.PtrInt64(q.Port),
81+
BindParams: models.BindParams{
82+
Name: QUIC6BIND,
83+
Ssl: true,
84+
SslCertificate: q.CertDir,
85+
Alpn: "h3",
86+
},
87+
})
88+
errs.Add(errFrontendBindCreate)
89+
instance.ReloadIf(errFrontendBindCreate == nil, "quic binding v6 created")
90+
}
91+
92+
ipv4DeleteFunc := func() {
93+
if !bindv4Present {
94+
return
95+
}
96+
errFrontendBindDelete := h.FrontendBindDelete(h.FrontHTTPS, QUIC4BIND)
97+
errs.Add(errFrontendBindDelete)
98+
instance.ReloadIf(errFrontendBindDelete == nil, "quic binding v4 removed")
99+
}
100+
101+
ipv6DeleteFunc := func() {
102+
if !bindv6Present {
103+
return
104+
}
105+
errFrontendBindDelete := h.FrontendBindDelete(h.FrontHTTPS, QUIC6BIND)
106+
errs.Add(errFrontendBindDelete)
107+
instance.ReloadIf(errFrontendBindDelete == nil, "quic binding v6 removed")
108+
}
109+
110+
maxAge := common.GetValue("quic-alt-svc-max-age", k.ConfigMaps.Main.Annotations)
111+
updatedMaxAge := maxAge != q.MaxAge
112+
if updatedMaxAge {
113+
instance.Reload("quic max age updated from %s to %s", q.MaxAge, maxAge)
114+
q.MaxAge = maxAge
115+
}
116+
117+
nsSslCertificateAnn, nameSslCertificateAnn, err := common.GetK8sPath("ssl-certificate", k.ConfigMaps.Main.Annotations)
118+
if err != nil || (nameSslCertificateAnn == "") {
119+
errs.Add(err)
120+
ipv4Func = ipv4DeleteFunc
121+
ipv6Func = ipv6DeleteFunc
122+
} else {
123+
namespaceSslCertificate := k.Namespaces[nsSslCertificateAnn]
124+
var sslSecret *store.Secret
125+
if namespaceSslCertificate != nil {
126+
sslSecret = namespaceSslCertificate.Secret[nameSslCertificateAnn]
127+
}
128+
129+
if sslSecret == nil || sslSecret.Status == store.DELETED {
130+
ipv4Func = ipv4DeleteFunc
131+
ipv6Func = ipv6DeleteFunc
132+
} else {
133+
logger.Debug("quic redirect rule to be created")
134+
errs.Add(h.AddRule(h.FrontHTTPS, rules.RequestRedirectQuic{}, false))
135+
logger.Debug("quic set header rule to be created")
136+
errs.Add(h.AddRule(h.FrontHTTPS, rules.SetHdr{
137+
HdrName: "alt-svc",
138+
Response: true,
139+
HdrFormat: fmt.Sprintf("\"h3=\\\":%d\\\";ma="+maxAge+";\"", q.QuicAnnouncePort),
140+
}, false))
141+
}
142+
}
143+
144+
if q.IPv4 {
145+
ipv4Func()
146+
}
147+
148+
if q.IPv6 {
149+
ipv6Func()
150+
}
151+
152+
return
153+
}

pkg/haproxy/api/api.go

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type HAProxyClient interface { //nolint:interfacebloat
5151
FrontendBindsGet(frontend string) (models.Binds, error)
5252
FrontendBindCreate(frontend string, bind models.Bind) error
5353
FrontendBindEdit(frontend string, bind models.Bind) error
54+
FrontendBindDelete(frontend string, bind string) error
5455
FrontendHTTPRequestRuleCreate(frontend string, rule models.HTTPRequestRule, ingressACL string) error
5556
FrontendHTTPResponseRuleCreate(frontend string, rule models.HTTPResponseRule, ingressACL string) error
5657
FrontendTCPRequestRuleCreate(frontend string, rule models.TCPRequestRule, ingressACL string) error

pkg/haproxy/api/frontend.go

+9
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ func (c *clientNative) FrontendBindEdit(frontend string, bind models.Bind) error
156156
return configuration.EditBind(bind.Name, "frontend", frontend, &bind, c.activeTransaction, 0)
157157
}
158158

159+
func (c *clientNative) FrontendBindDelete(frontend string, bind string) error {
160+
configuration, err := c.nativeAPI.Configuration()
161+
if err != nil {
162+
return err
163+
}
164+
c.activeTransactionHasChanges = true
165+
return configuration.DeleteBind(bind, "frontend", frontend, c.activeTransaction, 0)
166+
}
167+
159168
func (c *clientNative) FrontendHTTPRequestRuleCreate(frontend string, rule models.HTTPRequestRule, ingressACL string) error {
160169
configuration, err := c.nativeAPI.Configuration()
161170
if err != nil {

pkg/haproxy/env/defaults.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func SetGlobal(global *models.Global, logTargets *models.LogTargets, env Env) {
6868
global.DefaultPath = &models.GlobalDefaultPath{
6969
Type: "config",
7070
}
71+
global.LimitedQuic = true
7172
}
7273

7374
// SetDefaults will set default values for Defaults section config.

0 commit comments

Comments
 (0)