Skip to content

Commit 054ed63

Browse files
authored
reorg api gvks (#10742)
1 parent 7621168 commit 054ed63

File tree

22 files changed

+115
-146
lines changed

22 files changed

+115
-146
lines changed

api/v1alpha1/groupversion_info.go

-51
This file was deleted.

internal/kgateway/admin/resources.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"k8s.io/apimachinery/pkg/runtime/schema"
77

8-
"github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
98
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
109
)
1110

@@ -33,7 +32,7 @@ var (
3332
}
3433

3534
KubernetesGatewayIntegrationPolicyGVKs = []schema.GroupVersionKind{
36-
v1alpha1.GatewayParametersGVK,
35+
wellknown.GatewayParametersGVK,
3736

3837
// While these are in fact Policy APIs, they are only enabled if the Kubernetes Gateway Integration is turned on
3938
// gatewayv1.ListenerOptionGVK,

internal/kgateway/controller/scheme.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
gwv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
1313
gwv1b1 "sigs.k8s.io/gateway-api/apis/v1beta1"
1414

15-
sologatewayv1alpha1 "github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
15+
kgwv1a1 "github.com/kgateway-dev/kgateway/v2/api/v1alpha1"
1616
)
1717

1818
// SchemeBuilder contains all the Schemes for registering the CRDs with which Gloo Gateway interacts.
@@ -32,7 +32,7 @@ var SchemeBuilder = runtime.SchemeBuilder{
3232
apiextensionsv1.AddToScheme,
3333

3434
// Solo Kubernetes Gateway API resources
35-
sologatewayv1alpha1.Install,
35+
kgwv1a1.Install,
3636
}
3737

3838
func AddToScheme(s *runtime.Scheme) error {

internal/kgateway/deployer/deployer_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ var _ = Describe("Deployer", func() {
145145
ControllerName: wellknown.GatewayControllerName,
146146
ParametersRef: &api.ParametersReference{
147147
Group: gw2_v1alpha1.GroupName,
148-
Kind: gw2_v1alpha1.GatewayParametersKind,
148+
Kind: api.Kind(wellknown.GatewayParametersGVK.Kind),
149149
Name: wellknown.DefaultGatewayParametersName,
150150
Namespace: ptr.To(api.Namespace(defaultNamespace)),
151151
},
@@ -180,7 +180,7 @@ var _ = Describe("Deployer", func() {
180180
defaultGatewayParams = func() *gw2_v1alpha1.GatewayParameters {
181181
return &gw2_v1alpha1.GatewayParameters{
182182
TypeMeta: metav1.TypeMeta{
183-
Kind: gw2_v1alpha1.GatewayParametersKind,
183+
Kind: wellknown.GatewayParametersGVK.Kind,
184184
// The parsing expects GROUP/VERSION format in this field
185185
APIVersion: gw2_v1alpha1.GroupVersion.String(),
186186
},
@@ -255,7 +255,7 @@ var _ = Describe("Deployer", func() {
255255
selfManagedGatewayParam = func(name string) *gw2_v1alpha1.GatewayParameters {
256256
return &gw2_v1alpha1.GatewayParameters{
257257
TypeMeta: metav1.TypeMeta{
258-
Kind: gw2_v1alpha1.GatewayParametersKind,
258+
Kind: wellknown.GatewayParametersGVK.Kind,
259259
// The parsing expects GROUP/VERSION format in this field
260260
APIVersion: gw2_v1alpha1.GroupVersion.String(),
261261
},
@@ -282,15 +282,15 @@ var _ = Describe("Deployer", func() {
282282
ControllerName: wellknown.GatewayControllerName,
283283
ParametersRef: &api.ParametersReference{
284284
Group: gw2_v1alpha1.GroupName,
285-
Kind: gw2_v1alpha1.GatewayParametersKind,
285+
Kind: api.Kind(wellknown.GatewayParametersGVK.Kind),
286286
Name: wellknown.DefaultGatewayParametersName,
287287
Namespace: ptr.To(api.Namespace(defaultNamespace)),
288288
},
289289
},
290290
}
291291
gwParams := &gw2_v1alpha1.GatewayParameters{
292292
TypeMeta: metav1.TypeMeta{
293-
Kind: gw2_v1alpha1.GatewayParametersKind,
293+
Kind: wellknown.GatewayParametersGVK.Kind,
294294
// The parsing expects GROUP/VERSION format in this field
295295
APIVersion: gw2_v1alpha1.GroupVersion.String(),
296296
},
@@ -562,7 +562,7 @@ var _ = Describe("Deployer", func() {
562562
defaultGatewayParamsOverride = func() *gw2_v1alpha1.GatewayParameters {
563563
return &gw2_v1alpha1.GatewayParameters{
564564
TypeMeta: metav1.TypeMeta{
565-
Kind: gw2_v1alpha1.GatewayParametersKind,
565+
Kind: wellknown.GatewayParametersGVK.Kind,
566566
// The parsing expects GROUP/VERSION format in this field
567567
APIVersion: gw2_v1alpha1.GroupVersion.String(),
568568
},
@@ -626,7 +626,7 @@ var _ = Describe("Deployer", func() {
626626
mergedGatewayParams = func() *gw2_v1alpha1.GatewayParameters {
627627
return &gw2_v1alpha1.GatewayParameters{
628628
TypeMeta: metav1.TypeMeta{
629-
Kind: gw2_v1alpha1.GatewayParametersKind,
629+
Kind: wellknown.GatewayParametersGVK.Kind,
630630
// The parsing expects GROUP/VERSION format in this field
631631
APIVersion: gw2_v1alpha1.GroupVersion.String(),
632632
},
@@ -694,7 +694,7 @@ var _ = Describe("Deployer", func() {
694694
gatewayParamsOverrideWithSds = func() *gw2_v1alpha1.GatewayParameters {
695695
return &gw2_v1alpha1.GatewayParameters{
696696
TypeMeta: metav1.TypeMeta{
697-
Kind: gw2_v1alpha1.GatewayParametersKind,
697+
Kind: wellknown.GatewayParametersGVK.Kind,
698698
// The parsing expects GROUP/VERSION format in this field
699699
APIVersion: gw2_v1alpha1.GroupVersion.String(),
700700
},
@@ -750,7 +750,7 @@ var _ = Describe("Deployer", func() {
750750
gatewayParamsOverrideWithoutStats = func() *gw2_v1alpha1.GatewayParameters {
751751
return &gw2_v1alpha1.GatewayParameters{
752752
TypeMeta: metav1.TypeMeta{
753-
Kind: gw2_v1alpha1.GatewayParametersKind,
753+
Kind: wellknown.GatewayParametersGVK.Kind,
754754
// The parsing expects GROUP/VERSION format in this field
755755
APIVersion: gw2_v1alpha1.GroupVersion.String(),
756756
},
@@ -1452,7 +1452,7 @@ func newFakeClientWithObjs(objs ...client.Object) client.Client {
14521452
func fullyDefinedGatewayParameters(name, namespace string) *gw2_v1alpha1.GatewayParameters {
14531453
return &gw2_v1alpha1.GatewayParameters{
14541454
TypeMeta: metav1.TypeMeta{
1455-
Kind: gw2_v1alpha1.GatewayParametersKind,
1455+
Kind: wellknown.GatewayParametersGVK.Kind,
14561456
// The parsing expects GROUP/VERSION format in this field
14571457
APIVersion: gw2_v1alpha1.GroupVersion.String(),
14581458
},

internal/kgateway/extensions2/plugin/plugin.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ type PolicyPlugin struct {
5959

6060
Policies krt.Collection[ir.PolicyWrapper]
6161
GlobalPolicies func(krt.HandlerContext, AttachmentPoints) ir.PolicyIR
62-
PoliciesFetch func(n, ns string) ir.PolicyIR
62+
// PoliciesFetch can optionally be set if the plugin needs a custom mechanism for fetching the policy IR,
63+
// rather than the default behavior of fetching by name from the aggregated policy KRT collection
64+
PoliciesFetch func(n, ns string) ir.PolicyIR
6365
}
6466

6567
type BackendPlugin struct {

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ type backendPlugin struct {
115115

116116
func registerTypes(ourCli versioned.Interface) {
117117
kubeclient.Register[*v1alpha1.Backend](
118-
v1alpha1.BackendGVK.GroupVersion().WithResource("backends"),
119-
v1alpha1.BackendGVK,
118+
wellknown.BackendGVK.GroupVersion().WithResource("backends"),
119+
wellknown.BackendGVK,
120120
func(c kubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
121121
return ourCli.GatewayV1alpha1().Backends(namespace).List(context.Background(), o)
122122
},
@@ -131,7 +131,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
131131

132132
col := krt.WrapClient(kclient.New[*v1alpha1.Backend](commoncol.Client), commoncol.KrtOpts.ToOptions("Backends")...)
133133

134-
gk := v1alpha1.BackendGVK.GroupKind()
134+
gk := wellknown.BackendGVK.GroupKind()
135135
translate := buildTranslateFunc(ctx, commoncol.Secrets)
136136
ucol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.Backend) *ir.BackendObjectIR {
137137
// resolve secrets
@@ -174,7 +174,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
174174
}
175175
},
176176
},
177-
v1alpha1.BackendGVK.GroupKind(): {
177+
wellknown.BackendGVK.GroupKind(): {
178178
Name: "backend",
179179
NewGatewayTranslationPass: newPlug,
180180
// AttachmentPoints: []ir.AttachmentPoints{ir.HttpBackendRefAttachmentPoint},

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
extensionplug "github.com/kgateway-dev/kgateway/v2/internal/kgateway/extensions2/plugin"
2525
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2626
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
27+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
2728
"github.com/kgateway-dev/kgateway/v2/pkg/client/clientset/versioned"
2829
)
2930

@@ -61,8 +62,8 @@ func (p *directResponsePluginGwPass) ApplyForBackend(ctx context.Context, pCtx *
6162

6263
func registerTypes(ourCli versioned.Interface) {
6364
skubeclient.Register[*v1alpha1.DirectResponse](
64-
v1alpha1.DirectResponseGVK.GroupVersion().WithResource("directresponses"),
65-
v1alpha1.DirectResponseGVK,
65+
wellknown.DirectResponseGVK.GroupVersion().WithResource("directresponses"),
66+
wellknown.DirectResponseGVK,
6667
func(c skubeclient.ClientGetter, namespace string, o metav1.ListOptions) (runtime.Object, error) {
6768
return ourCli.GatewayV1alpha1().DirectResponses(namespace).List(context.Background(), o)
6869
},
@@ -77,7 +78,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
7778

7879
col := krt.WrapClient(kclient.New[*v1alpha1.DirectResponse](commoncol.Client), commoncol.KrtOpts.ToOptions("DirectResponse")...)
7980

80-
gk := v1alpha1.DirectResponseGVK.GroupKind()
81+
gk := wellknown.DirectResponseGVK.GroupKind()
8182
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.DirectResponse) *ir.PolicyWrapper {
8283
var pol = &ir.PolicyWrapper{
8384
ObjectSource: ir.ObjectSource{
@@ -95,7 +96,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
9596

9697
return extensionplug.Plugin{
9798
ContributesPolicies: map[schema.GroupKind]extensionplug.PolicyPlugin{
98-
v1alpha1.DirectResponseGVK.GroupKind(): {
99+
wellknown.DirectResponseGVK.GroupKind(): {
99100
Name: "directresponse",
100101
// AttachmentPoints: []ir.AttachmentPoints{ir.HttpAttachmentPoint},
101102
Policies: policyCol,

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ func convertAccessLogConfig(
4848
grpcBackends := make(map[string]*ir.BackendObjectIR, len(policy.Spec.AccessLog))
4949
for idx, log := range configs {
5050
if log.GrpcService != nil && log.GrpcService.BackendRef != nil {
51-
upstream, err := commoncol.Backends.GetBackendFromRef(krtctx, parentSrc, log.GrpcService.BackendRef.BackendObjectReference)
51+
backend, err := commoncol.Backends.GetBackendFromRef(krtctx, parentSrc, log.GrpcService.BackendRef.BackendObjectReference)
5252
if err != nil {
53-
return nil, fmt.Errorf("failed to get upstream from ref: %s", err.Error())
53+
return nil, fmt.Errorf("failed to get backend from ref: %s", err.Error())
5454
}
55-
grpcBackends[getLogId(log.GrpcService.LogName, idx)] = upstream
55+
grpcBackends[getLogId(log.GrpcService.LogName, idx)] = backend
5656
}
5757
}
5858

@@ -393,15 +393,15 @@ func copyGrpcSettings(cfg *envoygrpc.HttpGrpcAccessLogConfig, grpcService *v1alp
393393
return errors.New("grpc service log name cannot be empty")
394394
}
395395

396-
upstream := grpcBackends[getLogId(grpcService.LogName, accessLogId)]
397-
if upstream == nil {
398-
return errors.New("upstream backend ref not found")
396+
backend := grpcBackends[getLogId(grpcService.LogName, accessLogId)]
397+
if backend == nil {
398+
return errors.New("backend ref not found")
399399
}
400400

401401
svc := &envoycore.GrpcService{
402402
TargetSpecifier: &envoycore.GrpcService_EnvoyGrpc_{
403403
EnvoyGrpc: &envoycore.GrpcService_EnvoyGrpc{
404-
ClusterName: upstream.GetName(),
404+
ClusterName: backend.GetName(),
405405
},
406406
},
407407
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2323
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
2424
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
25+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
2526
)
2627

2728
type httpListenerPolicy struct {
@@ -76,7 +77,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
7677
v1alpha1.SchemeGroupVersion.WithResource("httplistenerpolicies"),
7778
commoncol.KrtOpts.ToOptions("HTTPListenerPolicy")...,
7879
)
79-
gk := v1alpha1.HTTPListenerPolicyGVK.GroupKind()
80+
gk := wellknown.HTTPListenerPolicyGVK.GroupKind()
8081
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.HTTPListenerPolicy) *ir.PolicyWrapper {
8182
objSrc := ir.ObjectSource{
8283
Group: gk.Group,
@@ -109,7 +110,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
109110

110111
return extensionplug.Plugin{
111112
ContributesPolicies: map[schema.GroupKind]extensionsplug.PolicyPlugin{
112-
v1alpha1.HTTPListenerPolicyGVK.GroupKind(): {
113+
wellknown.HTTPListenerPolicyGVK.GroupKind(): {
113114
//AttachmentPoints: []ir.AttachmentPoints{ir.HttpAttachmentPoint},
114115
NewGatewayTranslationPass: NewGatewayTranslationPass,
115116
Policies: policyCol,

internal/kgateway/extensions2/plugins/kubernetes/k8s.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ func NewPluginFromCollections(
4343
Kind: "Service",
4444
}
4545

46+
// TODO: reevaluate knative dep, dedupe with pkg/utils/kubeutils/dns.go
4647
clusterDomain := network.GetClusterDomainName()
47-
k8sServiceUpstreams := krt.NewManyCollection(services, func(kctx krt.HandlerContext, svc *corev1.Service) []ir.BackendObjectIR {
48+
k8sServiceBackends := krt.NewManyCollection(services, func(kctx krt.HandlerContext, svc *corev1.Service) []ir.BackendObjectIR {
4849
uss := []ir.BackendObjectIR{}
4950
for _, port := range svc.Spec.Ports {
5051
uss = append(uss, ir.BackendObjectIR{
@@ -62,19 +63,19 @@ func NewPluginFromCollections(
6263
})
6364
}
6465
return uss
65-
}, krtOpts.ToOptions("KubernetesServiceUpstreams")...)
66+
}, krtOpts.ToOptions("KubernetesServiceBackends")...)
6667

67-
inputs := krtcollections.NewGlooK8sEndpointInputs(stngs, krtOpts, endpointSlices, pods, k8sServiceUpstreams)
68+
inputs := krtcollections.NewGlooK8sEndpointInputs(stngs, krtOpts, endpointSlices, pods, k8sServiceBackends)
6869
k8sServiceEndpoints := krtcollections.NewGlooK8sEndpoints(ctx, inputs)
6970

7071
return extensionsplug.Plugin{
7172
ContributesBackends: map[schema.GroupKind]extensionsplug.BackendPlugin{
7273
gk: {
7374
BackendInit: ir.BackendInit{
74-
InitBackend: processUpstream,
75+
InitBackend: processBackend,
7576
},
7677
Endpoints: k8sServiceEndpoints,
77-
Backends: k8sServiceUpstreams,
78+
Backends: k8sServiceBackends,
7879
},
7980
},
8081
}
@@ -92,7 +93,7 @@ func translateAppProtocol(appProtocol *string) ir.AppProtocol {
9293
}
9394
}
9495

95-
func processUpstream(ctx context.Context, in ir.BackendObjectIR, out *envoy_config_cluster_v3.Cluster) {
96+
func processBackend(ctx context.Context, in ir.BackendObjectIR, out *envoy_config_cluster_v3.Cluster) {
9697
out.ClusterDiscoveryType = &envoy_config_cluster_v3.Cluster_Type{
9798
Type: envoy_config_cluster_v3.Cluster_EDS,
9899
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/ir"
2020
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/plugins"
2121
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/utils/krtutil"
22+
"github.com/kgateway-dev/kgateway/v2/internal/kgateway/wellknown"
2223
)
2324

2425
type listenerPolicy struct {
@@ -54,7 +55,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
5455
v1alpha1.SchemeGroupVersion.WithResource("listenerpolicies"),
5556
commoncol.KrtOpts.ToOptions("ListenerPolicy")...,
5657
)
57-
gk := v1alpha1.ListenerPolicyGVK.GroupKind()
58+
gk := wellknown.ListenerPolicyGVK.GroupKind()
5859
policyCol := krt.NewCollection(col, func(krtctx krt.HandlerContext, i *v1alpha1.ListenerPolicy) *ir.PolicyWrapper {
5960
var pol = &ir.PolicyWrapper{
6061
ObjectSource: ir.ObjectSource{
@@ -72,7 +73,7 @@ func NewPlugin(ctx context.Context, commoncol *common.CommonCollections) extensi
7273

7374
return extensionplug.Plugin{
7475
ContributesPolicies: map[schema.GroupKind]extensionsplug.PolicyPlugin{
75-
v1alpha1.ListenerPolicyGVK.GroupKind(): {
76+
wellknown.ListenerPolicyGVK.GroupKind(): {
7677
//AttachmentPoints: []ir.AttachmentPoints{ir.HttpAttachmentPoint},
7778
NewGatewayTranslationPass: NewGatewayTranslationPass,
7879
Policies: policyCol,

0 commit comments

Comments
 (0)