Skip to content

Commit

Permalink
feat: kpb refs refactoring
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Aug 7, 2024
1 parent 15e20a6 commit 8e0251f
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 158 deletions.
36 changes: 24 additions & 12 deletions api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,15 @@ type KongPluginBindingSpec struct {
// KongClusterPlugin can be replaced by kongPluginBindings with no Kong references. This way we'd be
// more coherent with the Konnect approach.
// https://github.com/Kong/kubernetes-configuration/issues/7
Kong *KongReferences `json:"kong,omitempty"`

// TODO(mlavacca): let's defer this one to the future as we are not sure about the shape we want to give it.
// https://github.com/Kong/kubernetes-configuration/issues/8
// EntityReference *GenericEntityRef `json:"genericEntityRef,omitempty"`
}

type KongReferences struct {
RouteReference *EntityRef `json:"routeRef,omitempty"`
ServiceReference *EntityRef `json:"serviceRef,omitempty"`
ConsumerReference *EntityRef `json:"consumerRef,omitempty"`
ConsumerGroupReference *EntityRef `json:"consumerGroupRef,omitempty"`
// TODO(mlavacca): RouteReference allows references to KongRoute, Ingress, HTTPRoute, or GCPRoute resource.
// TODO(mlavacca): ServiceReference allows Service or KongService resource.
// TODO(mlavacca): In case the routeRef references a KongRoute, the ServiceRef should be unset or set to a KongService.
// The same applies the other way around.
RouteReference *TargetRefWithGroupKind `json:"routeRef,omitempty"`
ServiceReference *TargetRefWithGroupKind `json:"serviceRef,omitempty"`
ConsumerReference *TargetRef `json:"consumerRef,omitempty"`
ConsumerGroupReference *TargetRef `json:"consumerGroupRef,omitempty"`
}

type PluginRef struct {
Expand All @@ -115,12 +112,27 @@ type PluginRef struct {
Kind *string `json:"kind,omitempty"`
}

type EntityRef struct {
type TargetRef struct {
// Name is the name of the entity.
// +kubebuilder:validation:Required
Name string `json:"name"`
}

// TODO(mlavacca): add xvalidation between group and kind
type TargetRefWithGroupKind struct {
// Name is the name of the entity.
// +kubebuilder:validation:Required
Name string `json:"name"`

// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=KongService;KongRoute;Service;HTTPRoute;GCPRoute;Ingress
Kind string `json:"kind"`

// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum="";core;gateway.networking.k8s.io;networking.k8s.io
Group string `json:"group"`
}

// type GenericEntityRef struct {
// // Name is the name of the generic entity.
// // +kubebuilder:validation:Required
Expand Down
103 changes: 49 additions & 54 deletions api/configuration/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 72 additions & 58 deletions config/crd/bases/configuration.konghq.com_kongpluginbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,65 +53,21 @@ spec:
spec:
description: KongPluginBindingSpec defines specification of a KongPluginBinding.
properties:
kong:
description: |-
Kong contains the Kong entity references. It is possible to set multiple combinations
of references, as described in https://docs.konghq.com/gateway/latest/key-concepts/plugins/#precedence
The complete set of allowed combinations and their order of precedence for plugins
configured to multiple entities is:
1. Consumer + route + service
2. Consumer group + service + route
3. Consumer + route
4. Consumer + service
5. Consumer group + route
6. Consumer group + service
7. Route + service
8. Consumer
9. Consumer group
10. Route
11. Service
12. Global
TODO(mlavacca): we need to figure out how to deal with global plugins. By means of this new API,
KongClusterPlugin can be replaced by kongPluginBindings with no Kong references. This way we'd be
more coherent with the Konnect approach.
https://github.com/Kong/kubernetes-configuration/issues/7
consumerGroupRef:
properties:
consumerGroupRef:
properties:
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
consumerRef:
properties:
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
routeRef:
properties:
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
serviceRef:
properties:
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
consumerRef:
properties:
name:
description: Name is the name of the entity.
type: string
required:
- name
type: object
pluginRef:
description: PluginReference is a reference to the KongPlugin or KongClusterPlugin
Expand All @@ -132,6 +88,64 @@ spec:
required:
- name
type: object
routeRef:
description: |-
TODO(mlavacca): RouteReference allows references to KongRoute, Ingress, HTTPRoute, or GCPRoute resource.
TODO(mlavacca): ServiceReference allows Service or KongService resource.
TODO(mlavacca): In case the routeRef references a KongRoute, the ServiceRef should be unset or set to a KongService.
The same applies the other way around.
properties:
group:
enum:
- ""
- core
- gateway.networking.k8s.io
- networking.k8s.io
type: string
kind:
enum:
- KongService
- KongRoute
- Service
- HTTPRoute
- GCPRoute
- Ingress
type: string
name:
description: Name is the name of the entity.
type: string
required:
- group
- kind
- name
type: object
serviceRef:
description: 'TODO(mlavacca): add xvalidation between group and kind'
properties:
group:
enum:
- ""
- core
- gateway.networking.k8s.io
- networking.k8s.io
type: string
kind:
enum:
- KongService
- KongRoute
- Service
- HTTPRoute
- GCPRoute
- Ingress
type: string
name:
description: Name is the name of the entity.
type: string
required:
- group
- kind
- name
type: object
required:
- pluginRef
type: object
Expand Down
Loading

0 comments on commit 8e0251f

Please sign in to comment.