Skip to content

Commit 887af1b

Browse files
committed
add gatewayclass matching to gateways.
1 parent 91e7f94 commit 887af1b

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

controllers/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func syncGatewaysAtStart(r *GatewayReconciler, ctx context.Context) error {
3535
return fmt.Errorf("unable to list gateways: %s", err.Error())
3636
} else {
3737
for _, gw := range gws.Items {
38+
if gw.Spec.GatewayClassName != gatewayv1beta1.ObjectName(pkg.ActiveSIGs.GatewayClass) {
39+
continue
40+
}
3841
zlog.V(1).Info("found gw: " + utils.Keyname(gw.Namespace, gw.Name))
3942
pkg.ActiveSIGs.SetGateway(gw.DeepCopy())
4043
}

main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,15 @@ func init() {
6464
// 531 kubebuilder create api --group gateways --version v1 --kind Adc
6565

6666
func main() {
67-
var metricsAddr string
68-
var enableLeaderElection bool
69-
var probeAddr string
70-
var bigipUrl string
71-
var bigipUsername string
72-
var bigipPassword string
67+
var (
68+
metricsAddr string
69+
enableLeaderElection bool
70+
probeAddr string
71+
bigipUrl string
72+
bigipUsername string
73+
bigipPassword string
74+
gtcName string
75+
)
7376

7477
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7578
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
@@ -80,13 +83,15 @@ func main() {
8083
flag.StringVar(&bigipUrl, "bigip-url", "", "The BIG-IP management IP address for provision resources.")
8184
flag.StringVar(&bigipUsername, "bigip-username", "admin", "The BIG-IP username for connection.")
8285
flag.StringVar(&bigipPassword, "bigip-password", "", "The BI-IP password for connection.")
86+
flag.StringVar(&gtcName, "gateway-class", "bigip", "The BI-IP password for connection.")
8387

8488
opts := zap.Options{
8589
Development: true,
8690
}
8791
opts.BindFlags(flag.CommandLine)
8892
flag.Parse()
8993

94+
pkg.ActiveSIGs.GatewayClass = gtcName
9095
bigip := f5_bigip.Initialize(bigipUrl, bigipUsername, bigipPassword, "debug")
9196
utils.Initialize("debug")
9297

pkg/types.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ type ParseRequest struct {
2020
}
2121

2222
type SIGCache struct {
23-
mutex sync.RWMutex
24-
Gateway map[string]*gatewayv1beta1.Gateway
25-
HTTPRoute map[string]*gatewayv1beta1.HTTPRoute
26-
Endpoints map[string]*v1.Endpoints
27-
Service map[string]*v1.Service
23+
mutex sync.RWMutex
24+
GatewayClass string
25+
Gateway map[string]*gatewayv1beta1.Gateway
26+
HTTPRoute map[string]*gatewayv1beta1.HTTPRoute
27+
Endpoints map[string]*v1.Endpoints
28+
Service map[string]*v1.Service
2829
// Node map[string]*v1.Node
2930
}
3031

pkg/utils.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ func init() {
1818
PendingParses = make(chan ParseRequest, 16)
1919
slog = utils.SetupLog("", "debug")
2020
ActiveSIGs = &SIGCache{
21-
mutex: sync.RWMutex{},
22-
Gateway: map[string]*gatewayv1beta1.Gateway{},
23-
HTTPRoute: map[string]*gatewayv1beta1.HTTPRoute{},
24-
Endpoints: map[string]*v1.Endpoints{},
25-
Service: map[string]*v1.Service{},
21+
mutex: sync.RWMutex{},
22+
GatewayClass: "",
23+
Gateway: map[string]*gatewayv1beta1.Gateway{},
24+
HTTPRoute: map[string]*gatewayv1beta1.HTTPRoute{},
25+
Endpoints: map[string]*v1.Endpoints{},
26+
Service: map[string]*v1.Service{},
2627
// Node: map[string]*v1.Node{},
2728
}
2829
}
@@ -32,7 +33,12 @@ func (c *SIGCache) SetGateway(obj *gatewayv1beta1.Gateway) {
3233
defer c.mutex.Unlock()
3334

3435
if obj != nil {
35-
c.Gateway[utils.Keyname(obj.Namespace, obj.Name)] = obj
36+
keyname := utils.Keyname(obj.Namespace, obj.Name)
37+
if obj.Spec.GatewayClassName == gatewayv1beta1.ObjectName(c.GatewayClass) {
38+
c.Gateway[keyname] = obj
39+
} else {
40+
delete(c.Gateway, keyname)
41+
}
3642
}
3743
}
3844

0 commit comments

Comments
 (0)