Skip to content

Commit cdb5566

Browse files
authored
Merge branch 'main' into add-cors-policy
2 parents b7839b3 + 3913ba2 commit cdb5566

File tree

165 files changed

+4503
-1536
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+4503
-1536
lines changed

.github/workflows/.env/nightly-tests/max_versions.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ kind_version='v0.27.0'
44
helm_version='v3.17.1'
55
argocd_version='v2.14.2'
66
istio_version='1.23.0'
7-
kgateway_api_version='v1.2.0'
7+
kgateway_api_version='v1.3.0'

.github/workflows/pr-kubernetes-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# May 19, 2025: ~19 minutes
3030
- cluster-name: 'cluster-one'
3131
go-test-args: '-v -timeout=25m'
32-
go-test-run-regex: '^TestKgateway$$/^BasicRouting$$|^TestKgateway$$/^HTTPRouteServices$$|^TestKgateway$$/^TLSRouteServices$$|^TestKgateway$$/^GRPCRouteServices$$'
32+
go-test-run-regex: '^TestKgateway$$/^BasicRouting$$|^TestKgateway$$/^HTTPRouteServices$$|^TestKgateway$$/^TLSRouteServices$$|^TestKgateway$$/^GRPCRouteServices$$|^TestListenerSet$$'
3333
localstack: 'false'
3434
# May 19, 2025: ~25 minutes
3535
- cluster-name: 'cluster-two'

.github/workflows/pr-unit-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
# TODO(tim): rename this job or consolidate with the other workflows.
1717
name: projects/gateway2
1818
runs-on: ubuntu-22.04
19-
timeout-minutes: 15
19+
timeout-minutes: 25
2020
steps:
2121
- uses: actions/checkout@v4
2222
- name: Setup Go

api/v1alpha1/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ package v1alpha1
55

66
// Gateway API resources with status management
77
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses;gateways;httproutes;grpcroutes;tcproutes;tlsroutes;referencegrants;backendtlspolicies,verbs=get;list;watch
8+
// +kubebuilder:rbac:groups=gateway.networking.x-k8s.io,resources=xlistenersets,verbs=get;list;watch
89
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses/status;gateways/status;httproutes/status;grpcroutes/status;tcproutes/status;tlsroutes/status;backendtlspolicies/status,verbs=patch;update
10+
// +kubebuilder:rbac:groups=gateway.networking.x-k8s.io,resources=xlistenersets/status,verbs=patch;update
911
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gatewayclasses,verbs=create
1012

1113
// Controller resources

install/helm/kgateway/templates/role.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ rules:
132132
- get
133133
- list
134134
- watch
135+
- apiGroups:
136+
- gateway.networking.x-k8s.io
137+
resources:
138+
- xlistenersets
139+
verbs:
140+
- get
141+
- list
142+
- watch
143+
- apiGroups:
144+
- gateway.networking.x-k8s.io
145+
resources:
146+
- xlistenersets/status
147+
verbs:
148+
- patch
149+
- update
135150
- apiGroups:
136151
- networking.istio.io
137152
resources:

internal/kgateway/controller/controller.go

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"context"
55
"fmt"
66

7+
"istio.io/istio/pkg/kube/krt"
78
"istio.io/istio/pkg/kube/kubetypes"
89
"k8s.io/apimachinery/pkg/api/meta"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/fields"
1112
"k8s.io/apimachinery/pkg/runtime"
1213
"k8s.io/apimachinery/pkg/runtime/schema"
14+
"k8s.io/apimachinery/pkg/types"
1315
ctrl "sigs.k8s.io/controller-runtime"
1416
"sigs.k8s.io/controller-runtime/pkg/builder"
1517
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -19,12 +21,15 @@ import (
1921
"sigs.k8s.io/controller-runtime/pkg/manager"
2022
"sigs.k8s.io/controller-runtime/pkg/predicate"
2123
"sigs.k8s.io/controller-runtime/pkg/reconcile"
24+
"sigs.k8s.io/controller-runtime/pkg/source"
2225
infextv1a2 "sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
2326
apiv1 "sigs.k8s.io/gateway-api/apis/v1"
2427

2528
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
2629
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/deployer"
30+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2731
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
32+
common "github.com/kgateway-dev/kgateway/v2/pkg/pluginsdk/collections"
2833
)
2934

3035
const (
@@ -68,6 +73,8 @@ type GatewayConfig struct {
6873
ClassInfo map[string]*ClassInfo
6974
// DiscoveryNamespaceFilter filters namespaced objects based on the discovery namespace filter.
7075
DiscoveryNamespaceFilter kubetypes.DynamicObjectFilter
76+
// CommonCollections used to fetch ir.Gateways for the deployer to generate the ports for the proxy service
77+
CommonCollections *common.CommonCollections
7178
}
7279

7380
func NewBaseGatewayController(ctx context.Context, cfg GatewayConfig) error {
@@ -77,8 +84,9 @@ func NewBaseGatewayController(ctx context.Context, cfg GatewayConfig) error {
7784
controllerBuilder := &controllerBuilder{
7885
cfg: cfg,
7986
reconciler: &controllerReconciler{
80-
cli: cfg.Mgr.GetClient(),
81-
scheme: cfg.Mgr.GetScheme(),
87+
cli: cfg.Mgr.GetClient(),
88+
scheme: cfg.Mgr.GetScheme(),
89+
customEvents: make(chan event.TypedGenericEvent[ir.Gateway], 1024),
8290
},
8391
}
8492

@@ -105,8 +113,9 @@ func NewBaseInferencePoolController(ctx context.Context, poolCfg *InferencePoolC
105113
cfg: *gwCfg,
106114
poolCfg: poolCfg,
107115
reconciler: &controllerReconciler{
108-
cli: poolCfg.Mgr.GetClient(),
109-
scheme: poolCfg.Mgr.GetScheme(),
116+
cli: poolCfg.Mgr.GetClient(),
117+
scheme: poolCfg.Mgr.GetScheme(),
118+
customEvents: make(chan event.TypedGenericEvent[ir.Gateway], 1024),
110119
},
111120
}
112121

@@ -173,6 +182,7 @@ func (c *controllerBuilder) watchGw(ctx context.Context) error {
173182
IstioAutoMtlsEnabled: c.cfg.IstioAutoMtlsEnabled,
174183
ControlPlane: c.cfg.ControlPlane,
175184
ImageInfo: c.cfg.ImageInfo,
185+
CommonCollections: c.cfg.CommonCollections,
176186
})
177187
if err != nil {
178188
return err
@@ -224,6 +234,7 @@ func (c *controllerBuilder) watchGw(ctx context.Context) error {
224234
}),
225235
builder.WithPredicates(discoveryNamespaceFilterPredicate),
226236
)
237+
227238
// watch for gatewayclasses managed by our controller and enqueue related gateways
228239
buildr.Watches(
229240
&apiv1.GatewayClass{},
@@ -260,6 +271,28 @@ func (c *controllerBuilder) watchGw(ctx context.Context) error {
260271
),
261272
)
262273

274+
// Trigger an event when the gateway changes. This can even be a change in listener sets attached to the gateway
275+
c.cfg.CommonCollections.GatewayIndex.Gateways.Register(func(o krt.Event[ir.Gateway]) {
276+
gw := o.Latest()
277+
c.reconciler.customEvents <- event.TypedGenericEvent[ir.Gateway]{
278+
Object: gw,
279+
}
280+
})
281+
buildr.WatchesRawSource(
282+
// Add channel source for custom events
283+
source.Channel(
284+
c.reconciler.customEvents,
285+
handler.TypedEnqueueRequestsFromMapFunc(func(ctx context.Context, obj ir.Gateway) []reconcile.Request {
286+
// Convert the generic event to a reconcile request
287+
return []reconcile.Request{
288+
{
289+
NamespacedName: types.NamespacedName{Namespace: obj.Namespace, Name: obj.Name},
290+
},
291+
}
292+
}),
293+
),
294+
)
295+
263296
for _, gvk := range gvks {
264297
obj, err := c.cfg.Mgr.GetScheme().New(gvk)
265298
if err != nil {
@@ -379,6 +412,7 @@ func (c *controllerBuilder) watchInferencePool(ctx context.Context) error {
379412
ControllerName: c.cfg.ControllerName,
380413
ImageInfo: c.cfg.ImageInfo,
381414
InferenceExtension: c.poolCfg.InferenceExt,
415+
CommonCollections: c.cfg.CommonCollections,
382416
})
383417
if err != nil {
384418
return err
@@ -440,8 +474,9 @@ func (c *controllerBuilder) watchGwClass(_ context.Context) error {
440474
}
441475

442476
type controllerReconciler struct {
443-
cli client.Client
444-
scheme *runtime.Scheme
477+
cli client.Client
478+
scheme *runtime.Scheme
479+
customEvents chan event.TypedGenericEvent[ir.Gateway]
445480
}
446481

447482
func (r *controllerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {

internal/kgateway/controller/controller_suite_test.go

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import (
99
"strings"
1010
"testing"
1111

12+
"github.com/go-logr/logr"
1213
. "github.com/onsi/ginkgo/v2"
1314
. "github.com/onsi/gomega"
15+
"istio.io/istio/pkg/kube"
1416
istiosets "istio.io/istio/pkg/util/sets"
1517
rbacv1 "k8s.io/api/rbac/v1"
1618
"k8s.io/apimachinery/pkg/runtime"
@@ -31,6 +33,14 @@ import (
3133

3234
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/controller"
3335
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/deployer"
36+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/registry"
37+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/settings"
38+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/krtcollections"
39+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/setup"
40+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
41+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
42+
"github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
43+
"github.com/kgateway-dev/kgateway/v2/pkg/pluginsdk/collections"
3444
"github.com/kgateway-dev/kgateway/v2/pkg/schemes"
3545
)
3646

@@ -187,6 +197,8 @@ func createManager(
187197
return nil, err
188198
}
189199

200+
ctx, cancel := context.WithCancel(parentCtx)
201+
kubeClient, _ := setup.CreateKubeClient(cfg)
190202
gwCfg := controller.GatewayConfig{
191203
Mgr: mgr,
192204
ControllerName: gatewayControllerName,
@@ -196,8 +208,10 @@ func createManager(
196208
Tag: "latest",
197209
},
198210
DiscoveryNamespaceFilter: fakeDiscoveryNamespaceFilter{},
211+
CommonCollections: newCommonCols(ctx, kubeClient),
199212
}
200213
if err := controller.NewBaseGatewayController(parentCtx, gwCfg); err != nil {
214+
cancel()
201215
return nil, err
202216
}
203217

@@ -213,6 +227,7 @@ func createManager(
213227
}
214228

215229
if err := controller.NewGatewayClassProvisioner(mgr, gatewayControllerName, classConfigs); err != nil {
230+
cancel()
216231
return nil, err
217232
}
218233

@@ -222,16 +237,44 @@ func createManager(
222237
InferenceExt: inferenceExt,
223238
}
224239
if err := controller.NewBaseInferencePoolController(parentCtx, poolCfg, &gwCfg); err != nil {
240+
cancel()
225241
return nil, err
226242
}
227243

228-
ctx, cancel := context.WithCancel(parentCtx)
229244
go func() {
230245
defer GinkgoRecover()
231246
kubeconfig = generateKubeConfiguration(cfg)
232247
mgr.GetLogger().Info("starting manager", "kubeconfig", kubeconfig)
233248
Expect(mgr.Start(ctx)).ToNot(HaveOccurred())
234249
}()
235250

236-
return cancel, nil
251+
return func() {
252+
cancel()
253+
kubeClient.Shutdown()
254+
}, nil
255+
}
256+
257+
func newCommonCols(ctx context.Context, kubeClient kube.Client) *collections.CommonCollections {
258+
krtopts := krtutil.NewKrtOptions(ctx.Done(), nil)
259+
cli, err := versioned.NewForConfig(cfg)
260+
if err != nil {
261+
Expect(err).ToNot(HaveOccurred())
262+
}
263+
264+
settings, err := settings.BuildSettings()
265+
if err != nil {
266+
Expect(err).ToNot(HaveOccurred())
267+
}
268+
commoncol, err := collections.NewCommonCollections(ctx, krtopts, kubeClient, cli, nil, wellknown.GatewayControllerName, logr.Discard(), *settings)
269+
if err != nil {
270+
Expect(err).ToNot(HaveOccurred())
271+
}
272+
273+
plugins := registry.Plugins(ctx, commoncol)
274+
plugins = append(plugins, krtcollections.NewBuiltinPlugin(ctx))
275+
extensions := registry.MergePlugins(plugins...)
276+
277+
commoncol.InitPlugins(ctx, extensions)
278+
kubeClient.RunAndWait(ctx.Done())
279+
return commoncol
237280
}

internal/kgateway/controller/scheme.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1313
gwv1a3 "sigs.k8s.io/gateway-api/apis/v1alpha3"
1414
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
15+
gwxv1a1 "sigs.k8s.io/gateway-api/apisx/v1alpha1"
1516

1617
kgwv1a1 "github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
1718
)
@@ -24,6 +25,7 @@ var SchemeBuilder = runtime.SchemeBuilder{
2425
gwv1a2.Install,
2526
gwv1a3.Install,
2627
gwv1b1.Install,
28+
gwxv1a1.Install,
2729

2830
// Kubernetes Core resources
2931
corev1.AddToScheme,
@@ -60,5 +62,8 @@ func GatewayScheme() *runtime.Scheme {
6062
if err := gwv1b1.Install(s); err != nil {
6163
panic(fmt.Sprintf("Failed to install gateway v1beta1 scheme: %v", err))
6264
}
65+
if err := gwxv1a1.Install(s); err != nil {
66+
panic(fmt.Sprintf("Failed to install gateway experimental v1alpha1 scheme: %v", err))
67+
}
6368
return s
6469
}

internal/kgateway/controller/start.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ type ControllerBuilder struct {
8686
proxySyncer *proxy_syncer.ProxySyncer
8787
cfg StartConfig
8888
mgr ctrl.Manager
89+
commoncol *common.CommonCollections
8990

9091
ready atomic.Bool
9192
}
@@ -219,6 +220,7 @@ func NewControllerBuilder(ctx context.Context, cfg StartConfig) (*ControllerBuil
219220
proxySyncer: proxySyncer,
220221
cfg: cfg,
221222
mgr: mgr,
223+
commoncol: commoncol,
222224
}
223225

224226
// wait for the ControllerBuilder to Start
@@ -279,6 +281,7 @@ func (c *ControllerBuilder) Start(ctx context.Context) error {
279281
PullPolicy: globalSettings.DefaultImagePullPolicy,
280282
},
281283
DiscoveryNamespaceFilter: c.cfg.Client.ObjectFilter(),
284+
CommonCollections: c.commoncol,
282285
}
283286

284287
setupLog.Info("creating gateway class provisioner")

internal/kgateway/deployer/deployer.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ import (
3333

3434
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
3535
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/helm"
36+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
3637
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
3738
"github.com/kgateway-dev/kgateway/v2/internal/version"
39+
common "github.com/kgateway-dev/kgateway/v2/pkg/pluginsdk/collections"
3840
)
3941

4042
var (
@@ -71,6 +73,7 @@ type Inputs struct {
7173
ControlPlane ControlPlaneInfo
7274
InferenceExtension *InferenceExtInfo
7375
ImageInfo *ImageInfo
76+
CommonCollections *common.CommonCollections
7477
}
7578

7679
type ImageInfo struct {
@@ -302,13 +305,21 @@ func (d *Deployer) getGatewayClassFromGateway(ctx context.Context, gw *api.Gatew
302305
}
303306

304307
func (d *Deployer) getValues(gw *api.Gateway, gwParam *v1alpha1.GatewayParameters) (*helmConfig, error) {
308+
gwKey := ir.ObjectSource{
309+
Group: wellknown.GatewayGVK.GroupKind().Group,
310+
Kind: wellknown.GatewayGVK.GroupKind().Kind,
311+
Name: gw.GetName(),
312+
Namespace: gw.GetNamespace(),
313+
}
314+
irGW := d.inputs.CommonCollections.GatewayIndex.Gateways.GetKey(gwKey.ResourceName())
315+
305316
// construct the default values
306317
vals := &helmConfig{
307318
Gateway: &helmGateway{
308319
Name: &gw.Name,
309320
GatewayName: &gw.Name,
310321
GatewayNamespace: &gw.Namespace,
311-
Ports: getPortsValues(gw, gwParam),
322+
Ports: getPortsValues(irGW, gwParam),
312323
Xds: &helmXds{
313324
// The xds host/port MUST map to the Service definition for the Control Plane
314325
// This is the socket address that the Proxy will connect to on startup, to receive xds updates

0 commit comments

Comments
 (0)