Skip to content

Commit

Permalink
feat: added cel to pluginbinding kong field
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Jul 25, 2024
1 parent da37fe0 commit aa710cf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 1 addition & 2 deletions api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
// +kubebuilder:printcolumn:name="Plugin-kind",type=string,JSONPath=`.spec.pluginReference.kind`,description="Kind of the plugin"
// +kubebuilder:printcolumn:name="Plugin-name",type=string,JSONPath=`.spec.pluginReference.name`,description="Name of the plugin"
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="(has(self.spec.kong.consumerRef) && has(self.spec.kong.routeRef) && has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerGroupRef) && has(self.spec.kong.serviceRef) && has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerRef)) || (has(self.spec.kong.consumerRef) && has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef) && !has(self.spec.kong.serviceRef)) || (has(self.spec.kong.consumerRef) && has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerGroupRef) && has(self.spec.kong.routeRef) && !has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef)) || (has(self.spec.kong.consumerGroupRef) && has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef) && !has(self.spec.kong.routeRef)) || (has(self.spec.kong.routeRef) && has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef) && !has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerRef) && !has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerGroupRef) && !has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerRef)) || (has(self.spec.kong.routeRef) && !has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef) && !has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef) && !has(self.spec.kong.consumerRef))", message="The combinations of entities set is not allowed"
type KongPluginBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -90,8 +91,6 @@ type KongPluginBindingSpec struct {

type KongReferences struct {
// TODO(mlavacca): add validation that at least one of the following field is properly set.
// TODO(mlavacca): add validation to ensure that when genericEntityReference is set, no other reference is set.

RouteReference *EntityRef `json:"routeRef,omitempty"`
ServiceReference *EntityRef `json:"serviceRef,omitempty"`
ConsumerReference *EntityRef `json:"consumerRef,omitempty"`
Expand Down
26 changes: 26 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongpluginbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ spec:
- name
type: object
routeRef:
description: 'TODO(mlavacca): add validation that at least one
of the following field is properly set.'
properties:
name:
description: Name is the name of the entity.
Expand Down Expand Up @@ -244,6 +246,30 @@ spec:
required:
- spec
type: object
x-kubernetes-validations:
- message: The combinations of entities set is not allowed
rule: (has(self.spec.kong.consumerRef) && has(self.spec.kong.routeRef) &&
has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerGroupRef))
|| (has(self.spec.kong.consumerGroupRef) && has(self.spec.kong.serviceRef)
&& has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerRef)) ||
(has(self.spec.kong.consumerRef) && has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef)
&& !has(self.spec.kong.serviceRef)) || (has(self.spec.kong.consumerRef)
&& has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) &&
!has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerGroupRef)
&& has(self.spec.kong.routeRef) && !has(self.spec.kong.serviceRef) &&
!has(self.spec.kong.consumerRef)) || (has(self.spec.kong.consumerGroupRef)
&& has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef)
&& !has(self.spec.kong.routeRef)) || (has(self.spec.kong.routeRef) &&
has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef) &&
!has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerRef)
&& !has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) &&
!has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.consumerGroupRef)
&& !has(self.spec.kong.serviceRef) && !has(self.spec.kong.routeRef) &&
!has(self.spec.kong.consumerRef)) || (has(self.spec.kong.routeRef) &&
!has(self.spec.kong.serviceRef) && !has(self.spec.kong.consumerRef) &&
!has(self.spec.kong.consumerGroupRef)) || (has(self.spec.kong.serviceRef)
&& !has(self.spec.kong.routeRef) && !has(self.spec.kong.consumerGroupRef)
&& !has(self.spec.kong.consumerRef))
served: true
storage: true
subresources:
Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `routeRef` _[EntityRef](#entityref)_ | |
| `routeRef` _[EntityRef](#entityref)_ | TODO(mlavacca): add validation that at least one of the following field is properly set. |
| `serviceRef` _[EntityRef](#entityref)_ | |
| `consumerRef` _[EntityRef](#entityref)_ | |
| `consumerGroupRef` _[EntityRef](#entityref)_ | |
Expand Down

0 comments on commit aa710cf

Please sign in to comment.