Skip to content

Commit

Permalink
complex rule split into two simpler ones
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Aug 8, 2024
1 parent c341796 commit 085feef
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type KongPluginBinding struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// +kubebuilder:validation:XValidation:message="One field between global and targets must be set",rule="(((has(self.global) && self.global == true) ? !has(self.targets) : true) && (((!has(self.global) || self.global == false) ? has(self.targets) : true) || (!has(self.targets) ? (has(self.global) && self.global == true) : true)))"
// +kubebuilder:validation:XValidation:message="When global is set, target refs cannot be used",rule="(has(self.global) && self.global == true) ? !has(self.targets) : true"
// +kubebuilder:validation:XValidation:message="When global is unset, target refs have to be used",rule="(!has(self.global) || self.global == false) ? has(self.targets) : true"
Spec KongPluginBindingSpec `json:"spec"`
Status KongPluginBindingStatus `json:"status,omitempty"`
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,12 @@ spec:
- pluginRef
type: object
x-kubernetes-validations:
- message: One field between global and targets must be set
rule: '(((has(self.global) && self.global == true) ? !has(self.targets)
: true) && (((!has(self.global) || self.global == false) ? has(self.targets)
: true) || (!has(self.targets) ? (has(self.global) && self.global
== true) : true)))'
- message: When global is set, target refs cannot be used
rule: '(has(self.global) && self.global == true) ? !has(self.targets)
: true'
- message: When global is unset, target refs have to be used
rule: '(!has(self.global) || self.global == false) ? has(self.targets)
: true'
status:
description: KongPluginBindingStatus represents the current status of
the KongBinding resource.
Expand Down

0 comments on commit 085feef

Please sign in to comment.