Skip to content

Commit d42308c

Browse files
authored
register types (#10847)
1 parent 75af11e commit d42308c

File tree

7 files changed

+80
-89
lines changed

7 files changed

+80
-89
lines changed

internal/kgateway/extensions2/plugins/backend/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (u *BackendIr) Equals(other any) bool {
8686

8787
func registerTypes(ourCli versioned.Interface) {
8888
kubeclient.Register[*v1alpha1.Backend](
89-
wellknown.BackendGVK.GroupVersion().WithResource("backends"),
89+
wellknown.BackendGVR,
9090
wellknown.BackendGVK,
9191
func(c kubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
9292
return ourCli.GatewayV1alpha1().Backends(namespace).List(context.Background(), o)

internal/kgateway/extensions2/plugins/directresponse/direct_response_plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (p *directResponsePluginGwPass) ApplyForBackend(ctx context.Context, pCtx *
6262

6363
func registerTypes(ourCli versioned.Interface) {
6464
skubeclient.Register[*v1alpha1.DirectResponse](
65-
wellknown.DirectResponseGVK.GroupVersion().WithResource("directresponses"),
65+
wellknown.DirectResponseGVR,
6666
wellknown.DirectResponseGVK,
6767
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
6868
return ourCli.GatewayV1alpha1().DirectResponses(namespace).List(context.Background(), o)

internal/kgateway/extensions2/plugins/httplistenerpolicy/httplistener_plugin.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,22 @@ import (
1212
envoy_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
1313
"github.com/solo-io/go-utils/contextutils"
1414
"google.golang.org/protobuf/proto"
15+
skubeclient "istio.io/istio/pkg/config/schema/kubeclient"
16+
"istio.io/istio/pkg/kube/kclient"
1517
"istio.io/istio/pkg/kube/krt"
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
"k8s.io/apimachinery/pkg/runtime"
1620
"k8s.io/apimachinery/pkg/runtime/schema"
21+
"k8s.io/apimachinery/pkg/watch"
1722

1823
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
1924
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/common"
2025
extensionplug "github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/plugin"
2126
extensionsplug "github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/plugin"
2227
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2328
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
24-
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
2529
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
30+
"github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
2631
)
2732

2833
type httpListenerPolicy struct {
@@ -69,14 +74,23 @@ func (p *httpListenerPolicyPluginGwPass) ApplyListenerPlugin(ctx context.Context
6974
// no op
7075
}
7176

72-
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionplug.Plugin {
73-
// need upstreams for backend refs
74-
col := krtutil.SetupCollectionDynamic[v1alpha1.HTTPListenerPolicy](
75-
ctx,
76-
commoncol.Client,
77-
v1alpha1.SchemeGroupVersion.WithResource("httplistenerpolicies"),
78-
commoncol.KrtOpts.ToOptions("HTTPListenerPolicy")...,
77+
func registerTypes(ourCli versioned.Interface) {
78+
skubeclient.Register[*v1alpha1.HTTPListenerPolicy](
79+
wellknown.HTTPListenerPolicyGVR,
80+
wellknown.HTTPListenerPolicyGVK,
81+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
82+
return ourCli.GatewayV1alpha1().HTTPListenerPolicies(namespace).List(context.Background(), o)
83+
},
84+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (watch.Interface, error) {
85+
return ourCli.GatewayV1alpha1().HTTPListenerPolicies(namespace).Watch(context.Background(), o)
86+
},
7987
)
88+
}
89+
90+
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionplug.Plugin {
91+
registerTypes(commoncol.OurClient)
92+
93+
col := krt.WrapClient(kclient.New[*v1alpha1.HTTPListenerPolicy](commoncol.Client), commoncol.KrtOpts.ToOptions("HTTPListenerPolicy")...)
8094
gk := wellknown.HTTPListenerPolicyGVK.GroupKind()
8195
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.HTTPListenerPolicy) *ir.PolicyWrapper {
8296
objSrc := ir.ObjectSource{

internal/kgateway/extensions2/plugins/listenerpolicy/listener_policy_plugin.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ import (
44
"context"
55
"time"
66

7-
envoy_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
8-
"k8s.io/apimachinery/pkg/runtime/schema"
9-
107
envoy_config_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
118
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
9+
envoy_hcm "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
1210
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"
11+
skubeclient "istio.io/istio/pkg/config/schema/kubeclient"
12+
"istio.io/istio/pkg/kube/kclient"
1313
"istio.io/istio/pkg/kube/krt"
14+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15+
"k8s.io/apimachinery/pkg/runtime"
16+
"k8s.io/apimachinery/pkg/runtime/schema"
17+
"k8s.io/apimachinery/pkg/watch"
1418

1519
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
1620
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/common"
1721
extensionplug "github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/plugin"
1822
extensionsplug "github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/plugin"
1923
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2024
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
21-
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
2225
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
26+
"github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
2327
)
2428

2529
type listenerPolicy struct {
@@ -48,13 +52,23 @@ func (p *listenerPolicyPluginGwPass) ApplyForBackend(ctx context.Context, pCtx *
4852
return nil
4953
}
5054

51-
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionplug.Plugin {
52-
col := krtutil.SetupCollectionDynamic[v1alpha1.ListenerPolicy](
53-
ctx,
54-
commoncol.Client,
55-
v1alpha1.SchemeGroupVersion.WithResource("listenerpolicies"),
56-
commoncol.KrtOpts.ToOptions("ListenerPolicy")...,
55+
func registerTypes(ourCli versioned.Interface) {
56+
skubeclient.Register[*v1alpha1.ListenerPolicy](
57+
wellknown.ListenerPolicyGVR,
58+
wellknown.ListenerPolicyGVK,
59+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
60+
return ourCli.GatewayV1alpha1().ListenerPolicies(namespace).List(context.Background(), o)
61+
},
62+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (watch.Interface, error) {
63+
return ourCli.GatewayV1alpha1().ListenerPolicies(namespace).Watch(context.Background(), o)
64+
},
5765
)
66+
}
67+
68+
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionplug.Plugin {
69+
registerTypes(commoncol.OurClient)
70+
71+
col := krt.WrapClient(kclient.New[*v1alpha1.ListenerPolicy](commoncol.Client), commoncol.KrtOpts.ToOptions("ListenerPolicy")...)
5872
gk := wellknown.ListenerPolicyGVK.GroupKind()
5973
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.ListenerPolicy) *ir.PolicyWrapper {
6074
var pol = &ir.PolicyWrapper{

internal/kgateway/extensions2/plugins/routepolicy/route_policy_plugin.go

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@ import (
77
"strconv"
88
"time"
99

10+
envoy_config_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
11+
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
1012
exteniondynamicmodulev3 "github.com/envoyproxy/go-control-plane/envoy/extensions/dynamic_modules/v3"
1113
dynamicmodulesv3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/dynamic_modules/v3"
14+
envoy_ext_proc_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3"
1215
envoyhttp "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/http_connection_manager/v3"
1316
"google.golang.org/protobuf/proto"
1417
"google.golang.org/protobuf/types/known/anypb"
18+
skubeclient "istio.io/istio/pkg/config/schema/kubeclient"
19+
"istio.io/istio/pkg/kube/kclient"
1520
"istio.io/istio/pkg/kube/krt"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
"k8s.io/apimachinery/pkg/runtime"
1623
"k8s.io/apimachinery/pkg/runtime/schema"
17-
18-
envoy_config_listener_v3 "github.com/envoyproxy/go-control-plane/envoy/config/listener/v3"
19-
envoy_config_route_v3 "github.com/envoyproxy/go-control-plane/envoy/config/route/v3"
20-
envoy_ext_proc_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/ext_proc/v3"
24+
"k8s.io/apimachinery/pkg/watch"
2125

2226
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
2327
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/common"
@@ -28,8 +32,8 @@ import (
2832
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/krtcollections"
2933
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
3034
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils"
31-
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
3235
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
36+
"github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
3337

3438
// TODO(nfuden): remove once rustformations are able to be used in a production environment
3539
transformationpb "github.com/solo-io/envoy-gloo/go/config/filter/http/transformation/v2"
@@ -102,15 +106,25 @@ func (p *routePolicyPluginGwPass) ApplyHCM(ctx context.Context, pCtx *ir.HcmCont
102106

103107
var useRustformations bool
104108

109+
func registerTypes(ourCli versioned.Interface) {
110+
skubeclient.Register[*v1alpha1.RoutePolicy](
111+
wellknown.RoutePolicyGVR,
112+
wellknown.RoutePolicyGVK,
113+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
114+
return ourCli.GatewayV1alpha1().RoutePolicies(namespace).List(context.Background(), o)
115+
},
116+
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (watch.Interface, error) {
117+
return ourCli.GatewayV1alpha1().RoutePolicies(namespace).Watch(context.Background(), o)
118+
},
119+
)
120+
}
121+
105122
func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensionplug.Plugin {
123+
registerTypes(commoncol.OurClient)
124+
106125
useRustformations = commoncol.Settings.UseRustFormations // stash the state of the env setup for rustformation usage
107126

108-
col := krtutil.SetupCollectionDynamic[v1alpha1.RoutePolicy](
109-
ctx,
110-
commoncol.Client,
111-
v1alpha1.SchemeGroupVersion.WithResource("routepolicies"),
112-
commoncol.KrtOpts.ToOptions("RoutePolicy")...,
113-
)
127+
col := krt.WrapClient(kclient.New[*v1alpha1.RoutePolicy](commoncol.Client), commoncol.KrtOpts.ToOptions("RoutePolicy")...)
114128
gk := wellknown.RoutePolicyGVK.GroupKind()
115129
translate := buildTranslateFunc(ctx, commoncol.Secrets)
116130
// RoutePolicy IR will have TypedConfig -> implement backendroute method to add prompt guard, etc.

internal/kgateway/utils/krtutil/dynamic_col.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

internal/kgateway/wellknown/kgw.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,11 @@ var (
2323
RoutePolicyGVK = buildKgatewayGvk("RoutePolicy")
2424
ListenerPolicyGVK = buildKgatewayGvk("ListenerPolicy")
2525
HTTPListenerPolicyGVK = buildKgatewayGvk("HTTPListenerPolicy")
26+
27+
GatewayParametersGVR = GatewayParametersGVK.GroupVersion().WithResource("gatewayparameters")
28+
DirectResponseGVR = DirectResponseGVK.GroupVersion().WithResource("directresponses")
29+
BackendGVR = BackendGVK.GroupVersion().WithResource("backends")
30+
RoutePolicyGVR = RoutePolicyGVK.GroupVersion().WithResource("routepolicies")
31+
ListenerPolicyGVR = ListenerPolicyGVK.GroupVersion().WithResource("listenerpolicies")
32+
HTTPListenerPolicyGVR = HTTPListenerPolicyGVK.GroupVersion().WithResource("httplistenerpolicies")
2633
)

0 commit comments

Comments
 (0)