Skip to content

Commit

Permalink
feat: Support GatewayAPI route attachment restriction (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
stillfox-lee authored Mar 17, 2023
1 parent d871a2c commit a431dd0
Show file tree
Hide file tree
Showing 20 changed files with 872 additions and 35 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
k8s.io/apimachinery v0.26.2
k8s.io/client-go v0.26.2
k8s.io/code-generator v0.26.2
sigs.k8s.io/controller-runtime v0.13.0
sigs.k8s.io/gateway-api v0.6.0
sigs.k8s.io/yaml v1.3.0
)
Expand All @@ -36,6 +37,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
Expand Down Expand Up @@ -82,7 +84,7 @@ require (
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/tools v0.4.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
Expand Down
18 changes: 15 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch/v5 v5.6.0 h1:b91NhWfaz02IuVxO9faSllyAtNXHMPkC5J8sJCLunww=
github.com/evanphx/json-patch/v5 v5.6.0/go.mod h1:G79N1coSVB93tBe7j6PhzjmR3/2VvlbKOFpnXhI9Bw4=
github.com/flowstack/go-jsonschema v0.1.1/go.mod h1:yL7fNggx1o8rm9RlgXv7hTBWxdBM0rVwpMwimd3F3N0=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
Expand All @@ -100,6 +103,7 @@ github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTg
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.2.3 h1:a9vnzlIBPQBBkeaR9IuMUfmVOrQlkoC4YfPoFkX3T7A=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
Expand Down Expand Up @@ -207,6 +211,7 @@ github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7P
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/incubator4/go-resty-expr v0.1.1 h1:9ur1M+p0wDzL1bprdGzHugGkfK0Yd3Ba/ijcgvL+a1k=
github.com/incubator4/go-resty-expr v0.1.1/go.mod h1:w9YQkQLUs1cArOb4O7SGJwJL/L8kuAo6y5CVS2o9eag=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down Expand Up @@ -254,6 +259,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo/v2 v2.4.0 h1:+Ig9nvqgS5OBSACXNk15PLdp0U9XPYROt9CFzVdFGIs=
github.com/onsi/gomega v1.23.0 h1:/oxKu9c2HVap+F3PfKort2Hw5DEU+HGlW8n+tguWsys=
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
Expand Down Expand Up @@ -343,7 +350,7 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI=
go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ=
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
Expand Down Expand Up @@ -505,8 +512,8 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 h1:vVKdlvoWBphwdxWKrFZEuM0kGgGLxUOYcY4U/2Vjg44=
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 h1:Dpdu/EMxGMFgq0CeYMh4fazTD2vtlZRYE7wyynxJb9U=
golang.org/x/time v0.0.0-20220609170525-579cf78fd858/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down Expand Up @@ -556,6 +563,7 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gomodules.xyz/jsonpatch/v2 v2.2.0 h1:4pT439QV83L+G9FkcCriY6EkpcK6r6bK+A5FBUMI7qY=
gomodules.xyz/jsonpatch/v3 v3.0.1 h1:Te7hKxV52TKCbNYq3t84tzKav3xhThdvSsSp/W89IyI=
gomodules.xyz/orderedmap v0.1.0 h1:fM/+TGh/O1KkqGR5xjTKg6bU8OKBkg7p0Y+x/J9m8Os=
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
Expand Down Expand Up @@ -653,6 +661,7 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc=
gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand All @@ -676,6 +685,7 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8s.io/api v0.26.2 h1:dM3cinp3PGB6asOySalOZxEG4CZ0IAdJsrYZXE/ovGQ=
k8s.io/api v0.26.2/go.mod h1:1kjMQsFE+QHPfskEcVNgL3+Hp88B80uj0QtSOlj8itU=
k8s.io/apiextensions-apiserver v0.26.0 h1:Gy93Xo1eg2ZIkNX/8vy5xviVSxwQulsnUdQ00nEdpDo=
k8s.io/apimachinery v0.26.2 h1:da1u3D5wfR5u2RpLhE/ZtZS2P7QvDgLZTi9wrNZl/tQ=
k8s.io/apimachinery v0.26.2/go.mod h1:ats7nN1LExKHvJ9TmwootT00Yz05MuYqPXEXaVeOy5I=
k8s.io/client-go v0.26.2 h1:s1WkVujHX3kTp4Zn4yGNFK+dlDXy1bAAkIl+cFAiuYI=
Expand All @@ -695,6 +705,8 @@ rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.13.0 h1:iqa5RNciy7ADWnIc8QxCbOX5FEKVR3uxVxKHRMc2WIQ=
sigs.k8s.io/controller-runtime v0.13.0/go.mod h1:Zbz+el8Yg31jubvAEyglRZGdLAjplZl+PgtYNI6WNTI=
sigs.k8s.io/gateway-api v0.6.0 h1:v2FqrN2ROWZLrSnI2o91taHR8Sj3s+Eh3QU7gLNWIqA=
sigs.k8s.io/gateway-api v0.6.0/go.mod h1:EYJT+jlPWTeNskjV0JTki/03WX1cyAnBhwBJfYHpV/0=
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 h1:iXTIw73aPyC+oRdyqqvVJuloN1p0AC/kzH07hu3NE+k=
Expand Down
15 changes: 13 additions & 2 deletions pkg/providers/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package gateway

import (
"context"
"fmt"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -126,7 +127,8 @@ func (c *gatewayController) sync(ctx context.Context, ev *types.Event) error {
return err
}
} else {
if c.controller.HasGatewayClass(string(gateway.Spec.GatewayClassName)) {
gatewayClassName := string(gateway.Spec.GatewayClassName)
if c.controller.HasGatewayClass(gatewayClassName) {
// TODO: handle listeners
listeners, err := c.controller.translator.TranslateGatewayV1beta1(gateway)
if err != nil {
Expand All @@ -137,6 +139,15 @@ func (c *gatewayController) sync(ctx context.Context, ev *types.Event) error {
if err != nil {
return err
}
} else {
gatewayClass, err := c.controller.gatewayClassLister.Get(gatewayClassName)
if err != nil {
return err
}
if gatewayClass.Spec.ControllerName == GatewayClassName {
log.Warn("gatewayClass not synced")
return fmt.Errorf("wait gatewayClass %s synced", gatewayClassName)
}
}
}

Expand Down Expand Up @@ -193,8 +204,8 @@ func (c *gatewayController) onAdd(obj interface{}) {
Object: key,
})
}
func (c *gatewayController) onUpdate(oldObj, newObj interface{}) {

func (c *gatewayController) onUpdate(oldObj, newObj interface{}) {
}

func (c *gatewayController) OnDelete(obj interface{}) {
Expand Down
3 changes: 0 additions & 3 deletions pkg/providers/gateway/gateway_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ func (c *gatewayClassController) onAdd(obj interface{}) {
)
return
}
if !c.controller.NamespaceProvider.IsWatchingNamespace(key) {
return
}
log.Debugw("gateway class add event arrived",
zap.Any("object", obj),
)
Expand Down
8 changes: 8 additions & 0 deletions pkg/providers/gateway/gateway_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ func (c *gatewayHTTPRouteController) sync(ctx context.Context, ev *types.Event)
}
httpRoute = ev.Tombstone.(*gatewayv1beta1.HTTPRoute)
}
err = c.controller.validator.ValidateCommonRoute(httpRoute)
if err != nil {
log.Errorw("failed to validate gateway HTTPRoute",
zap.Error(err),
zap.Any("object", httpRoute),
)
return err
}

tctx, err := c.controller.translator.TranslateGatewayHTTPRouteV1beta1(httpRoute)

Expand Down
9 changes: 9 additions & 0 deletions pkg/providers/gateway/gateway_tcproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ func (c *gatewayTCPRouteController) sync(ctx context.Context, ev *types.Event) e
}
tcpRoute = ev.Tombstone.(*gatewayv1alpha2.TCPRoute)
}
err = c.controller.validator.ValidateCommonRoute(tcpRoute)
if err != nil {
log.Errorw("failed to validate gateway TCPRoute",
zap.Error(err),
zap.Any("object", tcpRoute),
)
return err
}

tctx, err := c.controller.translator.TranslateGatewayTCPRouteV1Alpha2(tcpRoute)
if err != nil {
log.Errorw("failed to translate gateway TCPRoute",
Expand Down
9 changes: 8 additions & 1 deletion pkg/providers/gateway/gateway_tlsroute.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,16 @@ func (c *gatewayTLSRouteController) sync(ctx context.Context, ev *types.Event) e
}
tlsRoute = ev.Tombstone.(*gatewayv1alpha2.TLSRoute)
}
err = c.controller.validator.ValidateCommonRoute(tlsRoute)
if err != nil {
log.Errorw("failed to validate gateway HTTPRoute",
zap.Error(err),
zap.Any("object", tlsRoute),
)
return err
}

tctx, err := c.controller.translator.TranslateGatewayTLSRouteV1Alpha2(tlsRoute)

if err != nil {
log.Warnw("failed to translate gateway TLSRoute",
zap.Error(err),
Expand Down
10 changes: 8 additions & 2 deletions pkg/providers/gateway/gateway_udproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,15 @@ func (c *gatewayUDPRouteController) sync(ctx context.Context, ev *types.Event) e
}
udpRoute = ev.Tombstone.(*gatewayv1alpha2.UDPRoute)
}

err = c.controller.validator.ValidateCommonRoute(udpRoute)
if err != nil {
log.Errorw("failed to validate gateway UDPRoute",
zap.Error(err),
zap.Any("object", udpRoute),
)
return err
}
tctx, err := c.controller.translator.TranslateGatewayUDPRouteV1Alpha2(udpRoute)

if err != nil {
log.Errorw("failed to translate gateway UDPRoute",
zap.Error(err),
Expand Down
36 changes: 36 additions & 0 deletions pkg/providers/gateway/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import (
"sync"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
runtimeclient "sigs.k8s.io/controller-runtime/pkg/client"
gatewayv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
gatewayexternalversions "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
Expand All @@ -46,6 +48,8 @@ const (
ProviderName = "GatewayAPI"
)

var ErrListenerNotExist = fmt.Errorf("ListenerConf not exist")

type Provider struct {
name string

Expand All @@ -60,8 +64,10 @@ type Provider struct {

*ProviderOptions
gatewayClient gatewayclientset.Interface
runtimeClient runtimeclient.Client

translator gatewaytranslation.Translator
validator Validator

gatewayController *gatewayController
gatewayInformer cache.SharedIndexInformer
Expand Down Expand Up @@ -114,6 +120,10 @@ func NewGatewayProvider(opts *ProviderOptions) (*Provider, error) {
if err != nil {
return nil, err
}
rClient, err := runtimeclient.New(opts.RestConfig, runtimeclient.Options{Scheme: scheme.Scheme})
if err != nil {
return nil, err
}

p := &Provider{
name: ProviderName,
Expand All @@ -125,6 +135,7 @@ func NewGatewayProvider(opts *ProviderOptions) (*Provider, error) {

ProviderOptions: opts,
gatewayClient: gatewayKubeClient,
runtimeClient: rClient,

translator: gatewaytranslation.NewTranslator(&gatewaytranslation.TranslatorOptions{
KubeTranslator: opts.KubeTranslator,
Expand Down Expand Up @@ -152,6 +163,7 @@ func NewGatewayProvider(opts *ProviderOptions) (*Provider, error) {
p.gatewayUDPRouteInformer = gatewayFactory.Gateway().V1alpha2().UDPRoutes().Informer()

p.gatewayController = newGatewayController(p)
p.validator = *newValidator(p)

p.gatewayClassController, err = newGatewayClassController(p)
if err != nil {
Expand Down Expand Up @@ -277,6 +289,30 @@ func (p *Provider) RemoveListeners(ns, name string) error {
}

func (p *Provider) FindListener(ns, name, sectionName string) (*types.ListenerConf, error) {
p.listenersLock.RLock()
defer p.listenersLock.RUnlock()

key := ns + "/" + name
listeners, exist := p.listeners[key]
if !exist {
return nil, ErrListenerNotExist
}
for _, listener := range listeners {
if listener.SectionName == sectionName {
return listener, nil
}
}
return nil, nil
}

func (p *Provider) QueryListeners(ns, name string) (map[string]*types.ListenerConf, error) {
p.listenersLock.RLock()
defer p.listenersLock.RUnlock()

key := ns + "/" + name
listeners, exist := p.listeners[key]
if !exist {
return nil, ErrListenerNotExist
}
return listeners, nil
}
Loading

0 comments on commit a431dd0

Please sign in to comment.