diff --git a/api/configuration/v1/zz_generated_konnect_funcs.go b/api/configuration/v1/zz_generated_konnect_funcs.go
index 7a333fb..c61e07a 100644
--- a/api/configuration/v1/zz_generated_konnect_funcs.go
+++ b/api/configuration/v1/zz_generated_konnect_funcs.go
@@ -4,6 +4,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
+ configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)
// Code generated by scripts/apitypes-funcs/main.go; DO NOT EDIT.
@@ -66,3 +67,11 @@ func (obj *KongConsumer) SetControlPlaneID(id string) {
}
obj.Status.Konnect.ControlPlaneID = id
}
+
+func (obj *KongConsumer) SetControlPlaneRef(ref *configurationv1alpha1.ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongConsumer) GetControlPlaneRef() *configurationv1alpha1.ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
diff --git a/api/configuration/v1alpha1/kong_ca_certificate.go b/api/configuration/v1alpha1/kong_ca_certificate.go
index db79cb8..41af240 100644
--- a/api/configuration/v1alpha1/kong_ca_certificate.go
+++ b/api/configuration/v1alpha1/kong_ca_certificate.go
@@ -17,7 +17,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +apireference:kgo:include
// +kong:channels=gateway-operator
diff --git a/api/configuration/v1alpha1/kong_certificate.go b/api/configuration/v1alpha1/kong_certificate.go
index 99fce21..3dad920 100644
--- a/api/configuration/v1alpha1/kong_certificate.go
+++ b/api/configuration/v1alpha1/kong_certificate.go
@@ -17,6 +17,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +apireference:kgo:include
// +kong:channels=gateway-operator
diff --git a/api/configuration/v1alpha1/kongdataplaneclientcertificate_types.go b/api/configuration/v1alpha1/kongdataplaneclientcertificate_types.go
index 7d04e0c..7237357 100644
--- a/api/configuration/v1alpha1/kongdataplaneclientcertificate_types.go
+++ b/api/configuration/v1alpha1/kongdataplaneclientcertificate_types.go
@@ -34,7 +34,7 @@ import (
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : (!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.cert == self.spec.cert", message="spec.cert is immutable when an entity is already Programmed"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongDataPlaneClientCertificate struct {
diff --git a/api/configuration/v1alpha1/kongkey_types.go b/api/configuration/v1alpha1/kongkey_types.go
index 14bbeb6..00e4fb2 100644
--- a/api/configuration/v1alpha1/kongkey_types.go
+++ b/api/configuration/v1alpha1/kongkey_types.go
@@ -34,7 +34,7 @@ import (
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongKey struct {
diff --git a/api/configuration/v1alpha1/kongkeyset_types.go b/api/configuration/v1alpha1/kongkeyset_types.go
index 5d5d883..d7cc60c 100644
--- a/api/configuration/v1alpha1/kongkeyset_types.go
+++ b/api/configuration/v1alpha1/kongkeyset_types.go
@@ -33,7 +33,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongKeySet struct {
diff --git a/api/configuration/v1alpha1/kongpluginbinding_types.go b/api/configuration/v1alpha1/kongpluginbinding_types.go
index 8fc7f60..30cc8cf 100644
--- a/api/configuration/v1alpha1/kongpluginbinding_types.go
+++ b/api/configuration/v1alpha1/kongpluginbinding_types.go
@@ -35,6 +35,7 @@ import (
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec) || !has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongPluginBinding struct {
diff --git a/api/configuration/v1alpha1/kongroute_types.go b/api/configuration/v1alpha1/kongroute_types.go
index 504d183..ae16ff4 100644
--- a/api/configuration/v1alpha1/kongroute_types.go
+++ b/api/configuration/v1alpha1/kongroute_types.go
@@ -39,8 +39,8 @@ import (
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.serviceRef) || has(self.spec.serviceRef)", message="serviceRef is required once set"
// +kubebuilder:validation:XValidation:rule="has(self.spec.protocols) && self.spec.protocols.exists(p, p == 'http') ? (has(self.spec.hosts) || has(self.spec.methods) || has(self.spec.paths) || has(self.spec.paths) || has(self.spec.paths) || has(self.spec.headers) ) : true", message="If protocols has 'http', at least one of 'hosts', 'methods', 'paths' or 'headers' must be set"
-// +kubebuilder:validation:XValidation:rule="has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) || !has(self.spec.controlPlaneRef) && has(self.spec.serviceRef)", message="Only one of controlPlaneRef or serviceRef can be set"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
+// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) || has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) || !has(self.spec.controlPlaneRef) && has(self.spec.serviceRef)", message="Cannot set both controlPlaneRef or serviceRef at the same time"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.serviceRef) ? true : (!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.serviceRef == self.spec.serviceRef", message="spec.serviceRef is immutable when an entity is already Programmed"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef) ? true :(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +apireference:kgo:include
diff --git a/api/configuration/v1alpha1/kongservice_types.go b/api/configuration/v1alpha1/kongservice_types.go
index d979dfb..a610383 100644
--- a/api/configuration/v1alpha1/kongservice_types.go
+++ b/api/configuration/v1alpha1/kongservice_types.go
@@ -37,8 +37,8 @@ import (
// +kubebuilder:printcolumn:name="Protocol",type=string,JSONPath=`.spec.procol`,description="Protocol of the service"
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
-// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef)) ? true : (!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongService struct {
diff --git a/api/configuration/v1alpha1/kongupstream_types.go b/api/configuration/v1alpha1/kongupstream_types.go
index e4b4b22..a15513d 100644
--- a/api/configuration/v1alpha1/kongupstream_types.go
+++ b/api/configuration/v1alpha1/kongupstream_types.go
@@ -35,7 +35,7 @@ import (
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
-// +kubebuilder:validation:XValidation:rule="!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
+// +kubebuilder:validation:XValidation:rule="(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef)) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)", message="spec.controlPlaneRef cannot specify namespace for namespaced resource"
// +kubebuilder:validation:XValidation:rule="(!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef", message="spec.controlPlaneRef is immutable when an entity is already Programmed"
// +apireference:kgo:include
// +kong:channels=gateway-operator
diff --git a/api/configuration/v1alpha1/konnect_controlplaneref_types.go b/api/configuration/v1alpha1/konnect_controlplaneref_types.go
index d2cbaa8..8fecea5 100644
--- a/api/configuration/v1alpha1/konnect_controlplaneref_types.go
+++ b/api/configuration/v1alpha1/konnect_controlplaneref_types.go
@@ -15,20 +15,26 @@ const (
// ControlPlaneRef is the schema for the ControlPlaneRef type.
// It is used to reference a Control Plane entity.
-// +kubebuilder:validation:XValidation:rule="self.type == 'konnectNamespacedRef' ? has(self.konnectNamespacedRef) : true", message="when type is konnectNamespacedRef, konnectNamespacedRef must be set"
-// +kubebuilder:validation:XValidation:rule="self.type == 'konnectNamespacedRef' ? !has(self.konnectID) : true", message="when type is konnectNamespacedRef, konnectID must not be set"
-// +kubebuilder:validation:XValidation:rule="self.type == 'konnectID' ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
-// +kubebuilder:validation:XValidation:rule="self.type == 'konnectID' ? !has(self.konnectNamespacedRef) : true", message="when type is konnectID, konnectNamespacedRef must not be set"
-// +kubebuilder:validation:XValidation:rule="self.type == 'kic' ? !has(self.konnectID) : true", message="when type is kic, konnectID must not be set"
-// +kubebuilder:validation:XValidation:rule="self.type == 'kic' ? !has(self.konnectNamespacedRef) : true", message="when type is kic, konnectNamespacedRef must not be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? has(self.konnectNamespacedRef) : true", message="when type is konnectNamespacedRef, konnectNamespacedRef must be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? !has(self.konnectID) : true", message="when type is konnectNamespacedRef, konnectID must not be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? !has(self.konnectNamespacedRef) : true", message="when type is konnectID, konnectNamespacedRef must not be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectID) : true", message="when type is kic, konnectID must not be set"
+// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectNamespacedRef) : true", message="when type is kic, konnectNamespacedRef must not be set"
+// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectID) : true", message="when type is unset, konnectID must not be set"
+// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectNamespacedRef) : true", message="when type is unset, konnectNamespacedRef must not be set"
// +apireference:kgo:include
type ControlPlaneRef struct {
- // Type can be one of:
+ // Type indicates the type of the control plane being referenced. Allowed values:
// - konnectID
// - konnectNamespacedRef
// - kic
+ //
+ // The default is kic, which implies that the Control Plane is KIC.
+ //
// +kubebuilder:validation:Enum=konnectID;konnectNamespacedRef;kic
- Type string `json:"type"`
+ // +kubebuilder:default:=kic
+ Type string `json:"type,omitempty"`
// KonnectID is the schema for the KonnectID type.
// This field is required when the Type is konnectID.
diff --git a/api/configuration/v1alpha1/zz_generated_konnect_funcs.go b/api/configuration/v1alpha1/zz_generated_konnect_funcs.go
index b9e712d..ca81620 100644
--- a/api/configuration/v1alpha1/zz_generated_konnect_funcs.go
+++ b/api/configuration/v1alpha1/zz_generated_konnect_funcs.go
@@ -67,6 +67,14 @@ func (obj *KongKey) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongKey) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongKey) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongKeySet) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}
@@ -126,6 +134,14 @@ func (obj *KongKeySet) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongKeySet) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongKeySet) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongCredentialBasicAuth) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndConsumerRefs{}
}
@@ -535,6 +551,14 @@ func (obj *KongCACertificate) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongCACertificate) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongCACertificate) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongCertificate) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}
@@ -594,6 +618,14 @@ func (obj *KongCertificate) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongCertificate) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongCertificate) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongPluginBinding) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}
@@ -653,6 +685,14 @@ func (obj *KongPluginBinding) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongPluginBinding) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongPluginBinding) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongService) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}
@@ -712,6 +752,14 @@ func (obj *KongService) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongService) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongService) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongRoute) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs{}
}
@@ -771,6 +819,14 @@ func (obj *KongRoute) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongRoute) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongRoute) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongUpstream) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{}
}
@@ -830,6 +886,14 @@ func (obj *KongUpstream) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongUpstream) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongUpstream) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongTarget) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndUpstreamRefs{}
}
@@ -948,6 +1012,14 @@ func (obj *KongVault) SetControlPlaneID(id string) {
obj.Status.Konnect.ControlPlaneID = id
}
+func (obj *KongVault) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongVault) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
+
func (obj *KongSNI) initKonnectStatus() {
obj.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndCertificateRefs{}
}
@@ -1065,3 +1137,11 @@ func (obj *KongDataPlaneClientCertificate) SetControlPlaneID(id string) {
}
obj.Status.Konnect.ControlPlaneID = id
}
+
+func (obj *KongDataPlaneClientCertificate) SetControlPlaneRef(ref *ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongDataPlaneClientCertificate) GetControlPlaneRef() *ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
diff --git a/api/configuration/v1beta1/zz_generated_konnect_funcs.go b/api/configuration/v1beta1/zz_generated_konnect_funcs.go
index f2b72e9..14e304b 100644
--- a/api/configuration/v1beta1/zz_generated_konnect_funcs.go
+++ b/api/configuration/v1beta1/zz_generated_konnect_funcs.go
@@ -4,6 +4,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
+ configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)
// Code generated by scripts/apitypes-funcs/main.go; DO NOT EDIT.
@@ -66,3 +67,11 @@ func (obj *KongConsumerGroup) SetControlPlaneID(id string) {
}
obj.Status.Konnect.ControlPlaneID = id
}
+
+func (obj *KongConsumerGroup) SetControlPlaneRef(ref *configurationv1alpha1.ControlPlaneRef) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *KongConsumerGroup) GetControlPlaneRef() *configurationv1alpha1.ControlPlaneRef {
+ return obj.Spec.ControlPlaneRef
+}
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml
index 7089066..07e7030 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml
@@ -76,39 +76,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
tags:
description: Tags is an optional set of tags applied to the certificate.
items:
@@ -222,7 +229,8 @@ spec:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- rule: '!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
- message: spec.controlPlaneRef is immutable when an entity is already Programmed
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml
index 6885215..e3b61c9 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml
@@ -82,39 +82,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
key:
description: Key is the PEM-encoded private key.
type: string
@@ -238,6 +245,9 @@ spec:
x-kubernetes-validations:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
+ - message: spec.controlPlaneRef cannot specify namespace for namespaced resource
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
- message: spec.controlPlaneRef is immutable when an entity is already Programmed
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml
index 96cff4d..3eae93c 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml
@@ -78,39 +78,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
name:
description: Name is the name of the ConsumerGroup in Kong.
type: string
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml
index 979995c..bfa9ca5 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml
@@ -103,39 +103,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
tags:
description: Tags is an optional set of tags applied to the consumer.
items:
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml
index 659a3df..19a1280 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml
@@ -78,39 +78,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
required:
- cert
type: object
@@ -223,8 +230,7 @@ spec:
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.cert == self.spec.cert'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- - it's not supported yet
- rule: '!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef)
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
served: true
storage: true
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml
index 10fbe85..6430613 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml
@@ -72,39 +72,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
jwk:
description: |-
JWK is a JSON Web Key represented as a string.
@@ -302,8 +309,7 @@ spec:
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- - it's not supported yet
- rule: '!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef)
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
served: true
storage: true
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml
index 111988f..3e3c57c 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml
@@ -72,39 +72,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
name:
description: Name is a name of the KeySet.
minLength: 1
@@ -224,8 +231,8 @@ spec:
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- - it's not supported yet
- rule: '!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
served: true
storage: true
subresources:
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml
index 2dd6df6..5f96bc2 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml
@@ -80,39 +80,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
pluginRef:
description: PluginReference is a reference to the KongPlugin or KongClusterPlugin
resource.
@@ -376,6 +383,9 @@ spec:
- message: spec.controlPlaneRef is immutable when an entity is already Programmed
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
+ - message: spec.controlPlaneRef cannot specify namespace for namespaced resource
+ rule: '(!has(self.spec) || !has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
served: true
storage: true
subresources:
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml
index 5556088..d591f19 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml
@@ -73,39 +73,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
destinations:
description: A list of IP destinations of incoming connections that
match this Route when using stream routing. Each entry is an object
@@ -370,11 +377,12 @@ spec:
? (has(self.spec.hosts) || has(self.spec.methods) || has(self.spec.paths)
|| has(self.spec.paths) || has(self.spec.paths) || has(self.spec.headers)
) : true'
- - message: Only one of controlPlaneRef or serviceRef can be set
- rule: has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) || !has(self.spec.controlPlaneRef)
- && has(self.spec.serviceRef)
+ - message: Cannot set both controlPlaneRef or serviceRef at the same time
+ rule: '!has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) ||
+ has(self.spec.controlPlaneRef) && !has(self.spec.serviceRef) || !has(self.spec.controlPlaneRef)
+ && has(self.spec.serviceRef)'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- rule: '!has(self.spec.controlPlaneRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef)
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
- message: spec.serviceRef is immutable when an entity is already Programmed
rule: '!has(self.spec.serviceRef) ? true : (!self.status.conditions.exists(c,
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml
index aa883c4..9ea2397 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml
@@ -85,39 +85,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
enabled:
description: 'Whether the Service is active. If set to `false`, the
proxy behavior will be as if any routes attached to it do not exist
@@ -282,9 +289,11 @@ spec:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- rule: '!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
- message: spec.controlPlaneRef is immutable when an entity is already Programmed
- rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
+ rule: '(!has(self.spec.controlPlaneRef)) ? true : (!has(self.status) ||
+ !self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
served: true
storage: true
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml
index 06ad62e..2c17228 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml
@@ -82,39 +82,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
hash_fallback:
description: What to use as hashing input if the primary `hash_on`
does not return a hash (eg. header is missing, or no Consumer identified).
@@ -414,7 +421,8 @@ spec:
- message: controlPlaneRef is required once set
rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)'
- message: spec.controlPlaneRef cannot specify namespace for namespaced resource
- rule: '!has(self.spec.controlPlaneRef.konnectNamespacedRef) ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
+ rule: '(!has(self.spec.controlPlaneRef) || !has(self.spec.controlPlaneRef.konnectNamespacedRef))
+ ? true : !has(self.spec.controlPlaneRef.konnectNamespacedRef.__namespace__)'
- message: spec.controlPlaneRef is immutable when an entity is already Programmed
rule: '(!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml
index d13fdd9..dae73e2 100644
--- a/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml
+++ b/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml
@@ -105,39 +105,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
description:
description: Description is the additional information about the vault.
type: string
diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml
index 96cff4d..3eae93c 100644
--- a/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml
+++ b/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml
@@ -78,39 +78,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
name:
description: Name is the name of the ConsumerGroup in Kong.
type: string
diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml
index 979995c..bfa9ca5 100644
--- a/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml
+++ b/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml
@@ -103,39 +103,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
tags:
description: Tags is an optional set of tags applied to the consumer.
items:
diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml
index d13fdd9..dae73e2 100644
--- a/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml
+++ b/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml
@@ -105,39 +105,46 @@ spec:
- name
type: object
type:
+ default: kic
description: |-
- Type can be one of:
+ Type indicates the type of the control plane being referenced. Allowed values:
- konnectID
- konnectNamespacedRef
- kic
+
+ The default is kic, which implies that the Control Plane is KIC.
enum:
- konnectID
- konnectNamespacedRef
- kic
type: string
- required:
- - type
type: object
x-kubernetes-validations:
- message: when type is konnectNamespacedRef, konnectNamespacedRef
must be set
- rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? has(self.konnectNamespacedRef) : true'
- message: when type is konnectNamespacedRef, konnectID must not be
set
- rule: 'self.type == ''konnectNamespacedRef'' ? !has(self.konnectID)
- : true'
+ rule: '(has(self.type) && self.type == ''konnectNamespacedRef'')
+ ? !has(self.konnectID) : true'
- message: when type is konnectID, konnectID must be set
- rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''konnectID'') ? has(self.konnectID)
+ : true'
- message: when type is konnectID, konnectNamespacedRef must not be
set
- rule: 'self.type == ''konnectID'' ? !has(self.konnectNamespacedRef)
+ rule: '(has(self.type) && self.type == ''konnectID'') ? !has(self.konnectNamespacedRef)
: true'
- message: when type is kic, konnectID must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectID) : true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectID)
+ : true'
- message: when type is kic, konnectNamespacedRef must not be set
- rule: 'self.type == ''kic'' ? !has(self.konnectNamespacedRef) :
- true'
+ rule: '(has(self.type) && self.type == ''kic'') ? !has(self.konnectNamespacedRef)
+ : true'
+ - message: when type is unset, konnectID must not be set
+ rule: '!has(self.type) ? !has(self.konnectID) : true'
+ - message: when type is unset, konnectNamespacedRef must not be set
+ rule: '!has(self.type) ? !has(self.konnectNamespacedRef) : true'
description:
description: Description is the additional information about the vault.
type: string
diff --git a/docs/api-reference.md b/docs/api-reference.md
index 2a29b07..023c61e 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -685,7 +685,7 @@ It is used to reference a Control Plane entity.
| Field | Description |
| --- | --- |
-| `type` _string_ | Type can be one of: - konnectID - konnectNamespacedRef - kic |
+| `type` _string_ | Type indicates the type of the control plane being referenced. Allowed values: - konnectID - konnectNamespacedRef - kic
The default is kic, which implies that the Control Plane is KIC. |
| `konnectID` _string_ | KonnectID is the schema for the KonnectID type. This field is required when the Type is konnectID. |
| `konnectNamespacedRef` _[KonnectNamespacedRef](#konnectnamespacedref)_ | KonnectNamespacedRef is a reference to a Konnect Control Plane entity inside the cluster. It contains the name of the Konnect Control Plane. This field is required when the Type is konnectNamespacedRef. |
diff --git a/scripts/apitypes-funcs/main.go b/scripts/apitypes-funcs/main.go
index f9937cf..610828c 100644
--- a/scripts/apitypes-funcs/main.go
+++ b/scripts/apitypes-funcs/main.go
@@ -13,6 +13,8 @@ import (
type supportedTypesT struct {
PackageVersion string
+ AdditionalImports []string
+
Types []templateDataT
}
@@ -23,6 +25,8 @@ type templateDataT struct {
// KonnectStatusType is the name of the konnect status type (.status.konnect).
// If it's not provided Konnect status functions will not be generated.
KonnectStatusType string
+
+ ControlPlaneRefType string
}
const (
diff --git a/scripts/apitypes-funcs/supportedtypes.go b/scripts/apitypes-funcs/supportedtypes.go
index 9f50a07..4525b1d 100644
--- a/scripts/apitypes-funcs/supportedtypes.go
+++ b/scripts/apitypes-funcs/supportedtypes.go
@@ -3,19 +3,27 @@ package main
var supportedKonnectTypesControlPlaneConfig = []supportedTypesT{
{
PackageVersion: "v1",
+ AdditionalImports: []string{
+ `configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"`,
+ },
Types: []templateDataT{
{
- Type: "KongConsumer",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongConsumer",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "configurationv1alpha1.ControlPlaneRef",
},
},
},
{
PackageVersion: "v1beta1",
+ AdditionalImports: []string{
+ `configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"`,
+ },
Types: []templateDataT{
{
- Type: "KongConsumerGroup",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongConsumerGroup",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "configurationv1alpha1.ControlPlaneRef",
},
},
},
@@ -23,12 +31,14 @@ var supportedKonnectTypesControlPlaneConfig = []supportedTypesT{
PackageVersion: "v1alpha1",
Types: []templateDataT{
{
- Type: "KongKey",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndKeySetRef",
+ Type: "KongKey",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndKeySetRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongKeySet",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongKeySet",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
Type: "KongCredentialBasicAuth",
@@ -51,44 +61,52 @@ var supportedKonnectTypesControlPlaneConfig = []supportedTypesT{
KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndConsumerRefs",
},
{
- Type: "KongCACertificate",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongCACertificate",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongCertificate",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongCertificate",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongPluginBinding",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongPluginBinding",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongService",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongService",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongRoute",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs",
+ Type: "KongRoute",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
- Type: "KongUpstream",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongUpstream",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
Type: "KongTarget",
KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndUpstreamRefs",
},
{
- Type: "KongVault",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongVault",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
{
Type: "KongSNI",
KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndCertificateRefs",
},
{
- Type: "KongDataPlaneClientCertificate",
- KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ Type: "KongDataPlaneClientCertificate",
+ KonnectStatusType: "konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef",
+ ControlPlaneRefType: "ControlPlaneRef",
},
},
},
diff --git a/scripts/apitypes-funcs/templates.go b/scripts/apitypes-funcs/templates.go
index be79d6e..69018ef 100644
--- a/scripts/apitypes-funcs/templates.go
+++ b/scripts/apitypes-funcs/templates.go
@@ -8,6 +8,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
+{{- range .AdditionalImports }}
+ {{ . }}
+{{- end }}
)
// Code generated by scripts/apitypes-funcs/main.go; DO NOT EDIT.
@@ -73,6 +76,17 @@ func (obj *{{ .Type }}) SetControlPlaneID(id string) {
}
obj.Status.Konnect.ControlPlaneID = id
}
+{{- if .ControlPlaneRefType }}
+
+func (obj *{{ .Type }}) SetControlPlaneRef(ref *{{ .ControlPlaneRefType }}) {
+ obj.Spec.ControlPlaneRef = ref
+}
+
+func (obj *{{ .Type }}) GetControlPlaneRef() *{{ .ControlPlaneRefType }} {
+ return obj.Spec.ControlPlaneRef
+}
+{{- end }}
+
{{- if hasSuffix "KonnectEntityStatusWithControlPlaneAndConsumerRefs" .KonnectStatusType }}
func (obj *{{ .Type }}) SetKonnectConsumerIDInStatus(id string) {
diff --git a/test/crdsvalidation/kongcacertificate_test.go b/test/crdsvalidation/kongcacertificate_test.go
index f288c05..9e42d12 100644
--- a/test/crdsvalidation/kongcacertificate_test.go
+++ b/test/crdsvalidation/kongcacertificate_test.go
@@ -1,7 +1,6 @@
package crdsvalidation_test
import (
- "fmt"
"testing"
"github.com/samber/lo"
@@ -32,192 +31,20 @@ func TestKongCACertificate(t *testing.T) {
}.Run(t)
})
- t.Run("cp ref validation", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongCACertificate]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- },
- },
- },
+ t.Run("cp ref", func(t *testing.T) {
+ obj := &configurationv1alpha1.KongCACertificate{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongCACertificate",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- },
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongCACertificateSpec{
+ KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
+ Cert: "cert",
},
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
},
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- },
- },
- Status: configurationv1alpha1.KongCACertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongCACertificate) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- },
- },
- Status: configurationv1alpha1.KongCACertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongCACertificate) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- }.Run(t)
+ }
- t.Run("tags validation", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongCACertificate]{
- {
- Name: "up to 20 tags are allowed",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- Tags: func() []string {
- var tags []string
- for i := range 20 {
- tags = append(tags, fmt.Sprintf("tag-%d", i))
- }
- return tags
- }(),
- },
- },
- },
- },
- {
- Name: "more than 20 tags are not allowed",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- Tags: func() []string {
- var tags []string
- for i := range 21 {
- tags = append(tags, fmt.Sprintf("tag-%d", i))
- }
- return tags
- }(),
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.tags: Too many: 21: must have at most 20 items"),
- },
- {
- Name: "tags entries must not be longer than 128 characters",
- TestObject: &configurationv1alpha1.KongCACertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCACertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCACertificateAPISpec: configurationv1alpha1.KongCACertificateAPISpec{
- Cert: "cert",
- Tags: []string{
- lo.RandomString(129, lo.AlphanumericCharset),
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("tags entries must not be longer than 128 characters"),
- },
- }.Run(t)
- })
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
}
diff --git a/test/crdsvalidation/kongcertificate_test.go b/test/crdsvalidation/kongcertificate_test.go
index db0f20b..13fcb0a 100644
--- a/test/crdsvalidation/kongcertificate_test.go
+++ b/test/crdsvalidation/kongcertificate_test.go
@@ -5,129 +5,28 @@ import (
"testing"
"github.com/samber/lo"
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestKongCertificate(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongCertificate]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
- Cert: "cert",
- Key: "key",
- },
- },
- },
- },
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
- Cert: "cert",
- Key: "key",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
- Cert: "cert",
- Key: "key",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
+ obj := &configurationv1alpha1.KongCertificate{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongCertificate",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
- Cert: "cert",
- Key: "key",
- },
- },
- Status: configurationv1alpha1.KongCertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongCertificate) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongCertificateSpec{
+ KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
+ Cert: "test-cert",
+ Key: "test-key",
},
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
},
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongCertificateAPISpec: configurationv1alpha1.KongCertificateAPISpec{
- Cert: "cert",
- Key: "key",
- },
- },
- Status: configurationv1alpha1.KongCertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongCertificate) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("required fields", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongconsumer_test.go b/test/crdsvalidation/kongconsumer_test.go
index 27554a1..0a18e74 100644
--- a/test/crdsvalidation/kongconsumer_test.go
+++ b/test/crdsvalidation/kongconsumer_test.go
@@ -9,183 +9,20 @@ import (
configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
- konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)
func TestKongConsumer(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1.KongConsumer]{
- {
- // Since KongConsumers managed by KIC do not require spec.controlPlane, KongConsumers without spec.controlPlaneRef should be allowed.
- Name: "no cpRef is valid",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Username: "username-1",
- },
- },
- {
- Name: "cpRef cannot have namespace",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "another-namespace",
- },
- },
- },
- Username: "username-1",
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
- },
- {
- Name: "providing konnectID when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
+ obj := &configurationv1.KongConsumer{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongConsumer",
+ APIVersion: configurationv1.GroupVersion.String(),
},
+ ObjectMeta: commonObjectMeta,
+ Username: "username-1",
+ }
- {
- Name: "providing konnectNamespacedRef when type is konnectID yields an error",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
- },
- {
- Name: "providing konnectID and konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectID must not be set"),
- },
- }.Run(t)
- })
-
- t.Run("cp ref update", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1.KongConsumer]{
- {
- Name: "cpRef change is not allowed for Programmed=True",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- Username: "username-1",
- Status: configurationv1.KongConsumerStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Valid",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(c *configurationv1.KongConsumer) {
- c.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "cpRef change is allowed when cp is not Programmed=True nor APIAuthValid=True",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1.KongConsumerSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- Username: "username-3",
- Status: configurationv1.KongConsumerStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionFalse,
- Reason: "NotProgrammed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(c *configurationv1.KongConsumer) {
- c.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- },
- {
- Name: "updates with Programmed = True when no cpRef is allowed",
- TestObject: &configurationv1.KongConsumer{
- ObjectMeta: commonObjectMeta,
- Username: "username-4",
- Status: configurationv1.KongConsumerStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionFalse,
- Reason: "NotProgrammed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(c *configurationv1.KongConsumer) {
- c.Credentials = []string{"new-credentials"}
- },
- },
- }.Run(t)
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("required fields", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongconsumergroup_test.go b/test/crdsvalidation/kongconsumergroup_test.go
index bba67dc..602b269 100644
--- a/test/crdsvalidation/kongconsumergroup_test.go
+++ b/test/crdsvalidation/kongconsumergroup_test.go
@@ -14,95 +14,18 @@ import (
func TestKongConsumerGroup(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1beta1.KongConsumerGroup]{
- {
- // Since KongConsumerGroups managed by KIC do not require spec.controlPlane, KongConsumerGroups without spec.controlPlaneRef should be allowed.
- Name: "no CPRef is valid",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- Name: "test",
- },
- },
- },
- {
- Name: "cpRef cannot have namespace",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "another-namespace",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
+ obj := &configurationv1beta1.KongConsumerGroup{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongConsumer",
+ APIVersion: configurationv1beta1.GroupVersion.String(),
},
- {
- Name: "providing konnectID when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1beta1.KongConsumerGroupSpec{
+ Name: "group1",
},
+ }
- {
- Name: "providing konnectNamespacedRef when type is konnectID yields an error",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
- },
- {
- Name: "providing konnectID and konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1beta1.KongConsumerGroup{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1beta1.KongConsumerGroupSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectID must not be set"),
- },
- }.Run(t)
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("cp ref update", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongdataplaneclientcertificate_test.go b/test/crdsvalidation/kongdataplaneclientcertificate_test.go
index 951dcc6..8543e3c 100644
--- a/test/crdsvalidation/kongdataplaneclientcertificate_test.go
+++ b/test/crdsvalidation/kongdataplaneclientcertificate_test.go
@@ -11,136 +11,20 @@ import (
func TestKongDataPlaneClientCertificate(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongDataPlaneClientCertificate]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
- },
+ obj := &configurationv1alpha1.KongDataPlaneClientCertificate{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongDataPlaneClientCertificate",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
+ KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
+ Cert: "cert",
},
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
},
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
- Status: configurationv1alpha1.KongDataPlaneClientCertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongDataPlaneClientCertificate) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
- Status: configurationv1alpha1.KongDataPlaneClientCertificateStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongDataPlaneClientCertificate) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespaced reference cannot set namespace as it's not supported yet",
- TestObject: &configurationv1alpha1.KongDataPlaneClientCertificate{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongDataPlaneClientCertificateSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "default",
- },
- },
- KongDataPlaneClientCertificateAPISpec: configurationv1alpha1.KongDataPlaneClientCertificateAPISpec{
- Cert: "cert",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"),
- },
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("spec", func(t *testing.T) {
@@ -214,5 +98,4 @@ func TestKongDataPlaneClientCertificate(t *testing.T) {
},
}.Run(t)
})
-
}
diff --git a/test/crdsvalidation/kongkey_test.go b/test/crdsvalidation/kongkey_test.go
index 4f8317f..87cccc1 100644
--- a/test/crdsvalidation/kongkey_test.go
+++ b/test/crdsvalidation/kongkey_test.go
@@ -11,139 +11,42 @@ import (
)
func TestKongKey(t *testing.T) {
- t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongKey]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}"),
- },
- },
- },
+ t.Run("jwk/cp ref", func(t *testing.T) {
+ obj := &configurationv1alpha1.KongKey{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongKey",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}"),
- },
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongKeySpec{
+ KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
+ KID: "1",
+ JWK: lo.ToPtr("jwk"),
},
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
},
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}")},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}")},
- },
- Status: configurationv1alpha1.KongKeyStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongKey) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}")},
- },
- Status: configurationv1alpha1.KongKeyStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongKey) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
+ })
+ t.Run("pem/cp ref", func(t *testing.T) {
+ obj := &configurationv1alpha1.KongKey{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongKey",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "konnectNamespaced reference cannot set namespace as it's not supported yet",
- TestObject: &configurationv1alpha1.KongKey{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "default",
- },
- },
- KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
- KID: "1",
- JWK: lo.ToPtr("{}")},
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongKeySpec{
+ KongKeyAPISpec: configurationv1alpha1.KongKeyAPISpec{
+ KID: "1",
+ PEM: &configurationv1alpha1.PEMKeyPair{
+ PublicKey: "public",
+ PrivateKey: "private",
},
},
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"),
},
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("spec", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongkeyset_test.go b/test/crdsvalidation/kongkeyset_test.go
index 77e5e90..e0774fd 100644
--- a/test/crdsvalidation/kongkeyset_test.go
+++ b/test/crdsvalidation/kongkeyset_test.go
@@ -12,136 +12,20 @@ import (
func TestKongKeySet(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongKeySet]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
- },
- },
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
- Status: configurationv1alpha1.KongKeySetStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongKeySet) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ obj := &configurationv1alpha1.KongKeySet{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongKeySet",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
- Status: configurationv1alpha1.KongKeySetStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongKeySet) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespaced reference cannot set namespace as it's not supported yet",
- TestObject: &configurationv1alpha1.KongKeySet{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongKeySetSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "default",
- },
- },
- KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
- Name: "name",
- },
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongKeySetSpec{
+ KongKeySetAPISpec: configurationv1alpha1.KongKeySetAPISpec{
+ Name: "keyset",
},
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource - it's not supported yet"),
},
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("spec", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongpluginbindings_test.go b/test/crdsvalidation/kongpluginbindings_test.go
index c0ad79c..b224643 100644
--- a/test/crdsvalidation/kongpluginbindings_test.go
+++ b/test/crdsvalidation/kongpluginbindings_test.go
@@ -7,92 +7,31 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
- konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)
func TestKongPluginBindings(t *testing.T) {
- t.Run("update not allowed for status conditions", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongPluginBinding]{
- {
- Name: "cpRef change is not allowed for Programmed=True",
- TestObject: &configurationv1alpha1.KongPluginBinding{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongPluginBindingSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- PluginReference: configurationv1alpha1.PluginRef{
- Kind: lo.ToPtr("KongPlugin"),
- Name: "test-plugin",
- },
- Targets: configurationv1alpha1.KongPluginBindingTargets{
- ServiceReference: &configurationv1alpha1.TargetRefWithGroupKind{
- Name: "test-service",
- Kind: "Service",
- Group: "core",
- },
- },
- },
- Status: configurationv1alpha1.KongPluginBindingStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Valid",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(c *configurationv1alpha1.KongPluginBinding) {
- c.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ t.Run("cp ref", func(t *testing.T) {
+ obj := &configurationv1alpha1.KongPluginBinding{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongPluginBinding",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "cpRef change is allowed when cp is not Programmed=True nor APIAuthValid=True",
- TestObject: &configurationv1alpha1.KongPluginBinding{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongPluginBindingSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- PluginReference: configurationv1alpha1.PluginRef{
- Kind: lo.ToPtr("KongPlugin"),
- Name: "test-plugin",
- },
- Targets: configurationv1alpha1.KongPluginBindingTargets{
- ServiceReference: &configurationv1alpha1.TargetRefWithGroupKind{
- Name: "test-service",
- Kind: "Service",
- Group: "core",
- },
- },
- },
- Status: configurationv1alpha1.KongPluginBindingStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{},
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionFalse,
- Reason: "NotProgrammed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongPluginBindingSpec{
+ PluginReference: configurationv1alpha1.PluginRef{
+ Name: "rate-limiting",
},
- Update: func(c *configurationv1alpha1.KongPluginBinding) {
- c.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
+ Targets: configurationv1alpha1.KongPluginBindingTargets{
+ ServiceReference: &configurationv1alpha1.TargetRefWithGroupKind{
+ Name: "test-service",
+ Kind: "KongService",
+ Group: "configuration.konghq.com",
+ },
},
},
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("plugin ref", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongroute_test.go b/test/crdsvalidation/kongroute_test.go
index 8c73fec..829cb85 100644
--- a/test/crdsvalidation/kongroute_test.go
+++ b/test/crdsvalidation/kongroute_test.go
@@ -14,207 +14,15 @@ import (
func TestKongRoute(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongRoute]{
- {
- Name: "cannot specify with service ref",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- ServiceRef: &configurationv1alpha1.ServiceRef{
- Type: configurationv1alpha1.ServiceRefNamespacedRef,
- NamespacedRef: &configurationv1alpha1.KongObjectRef{
- Name: "test-konnect-service",
- },
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("Only one of controlPlaneRef or serviceRef can be set"),
- },
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- },
- },
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing namespace in konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "another-namespace",
- },
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
- },
- {
- Name: "providing konnectID when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
+ obj := &configurationv1alpha1.KongRoute{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongRoute",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
+ ObjectMeta: commonObjectMeta,
+ }
- {
- Name: "providing konnectNamespacedRef when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
- },
- {
- Name: "providing konnectID and konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectID must not be set"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- Status: configurationv1alpha1.KongRouteStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongRoute) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongRoute{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongRouteSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongRouteAPISpec: configurationv1alpha1.KongRouteAPISpec{},
- },
- Status: configurationv1alpha1.KongRouteStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongRoute) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- }.Run(t)
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("protocols", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongservice_test.go b/test/crdsvalidation/kongservice_test.go
index c986744..139b301 100644
--- a/test/crdsvalidation/kongservice_test.go
+++ b/test/crdsvalidation/kongservice_test.go
@@ -12,209 +12,15 @@ import (
func TestKongService(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongService]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- },
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing konnectID when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
+ obj := &configurationv1alpha1.KongService{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongService",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
+ ObjectMeta: commonObjectMeta,
+ }
- {
- Name: "providing konnectNamespacedRef when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
- },
- {
- Name: "providing konnectID and konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectID: lo.ToPtr("123456"),
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectID must not be set"),
- },
- {
- Name: "providing namespace in konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "another-namespace",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- Status: configurationv1alpha1.KongServiceStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongService) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongService{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongServiceSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongServiceAPISpec: configurationv1alpha1.KongServiceAPISpec{
- Host: "example.com",
- },
- },
- Status: configurationv1alpha1.KongServiceStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongService) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- }.Run(t)
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("tags validation", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongupstream_test.go b/test/crdsvalidation/kongupstream_test.go
index a69481b..d88b4d4 100644
--- a/test/crdsvalidation/kongupstream_test.go
+++ b/test/crdsvalidation/kongupstream_test.go
@@ -14,124 +14,15 @@ import (
func TestKongUpstream(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongUpstream]{
- {
- Name: "konnectNamespacedRef reference is valid",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- },
- },
- {
- Name: "not providing konnectNamespacedRef when type is konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
- },
- {
- Name: "not providing konnectID when type is konnectID yields an error",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
- },
- {
- Name: "providing namespace in konnectNamespacedRef yields an error",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- Namespace: "another-namespace",
- },
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- },
- ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
- },
- {
- Name: "konnectNamespacedRef reference name cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- Status: configurationv1alpha1.KongUpstreamStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongUpstream) {
- ks.Spec.ControlPlaneRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "konnectNamespacedRef reference type cannot be changed when an entity is Programmed",
- TestObject: &configurationv1alpha1.KongUpstream{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongUpstreamSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
- KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
- Name: "test-konnect-control-plane",
- },
- },
- KongUpstreamAPISpec: configurationv1alpha1.KongUpstreamAPISpec{},
- },
- Status: configurationv1alpha1.KongUpstreamStatus{
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(ks *configurationv1alpha1.KongUpstream) {
- ks.Spec.ControlPlaneRef.Type = configurationv1alpha1.ControlPlaneRefKonnectID
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ obj := &configurationv1alpha1.KongUpstream{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongUpstream",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- }.Run(t)
+ ObjectMeta: commonObjectMeta,
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("required fields", func(t *testing.T) {
diff --git a/test/crdsvalidation/kongvault_test.go b/test/crdsvalidation/kongvault_test.go
index 2989587..e98e756 100644
--- a/test/crdsvalidation/kongvault_test.go
+++ b/test/crdsvalidation/kongvault_test.go
@@ -8,140 +8,23 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
- konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)
func TestKongVault(t *testing.T) {
t.Run("cp ref", func(t *testing.T) {
- CRDValidationTestCasesGroup[*configurationv1alpha1.KongVault]{
- {
- Name: "no control plane ref to have control plane ref in valid",
- TestObject: &configurationv1alpha1.KongVault{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongVaultSpec{
- Backend: "aws",
- Prefix: "aws-vault",
- },
- },
- Update: func(v *configurationv1alpha1.KongVault) {
- v.Spec.ControlPlaneRef = &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("konnect-1"),
- }
- },
- },
- {
- Name: "have control plane to no control plane is invalid",
- TestObject: &configurationv1alpha1.KongVault{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongVaultSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("konnect-1"),
- },
- Backend: "aws",
- Prefix: "aws-vault",
- },
- },
- Update: func(v *configurationv1alpha1.KongVault) {
- v.Spec.ControlPlaneRef = nil
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("controlPlaneRef is required once set"),
- },
- {
- Name: "control plane is immutable once programmed (non-empty -> non-empty)",
- TestObject: &configurationv1alpha1.KongVault{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongVaultSpec{
- ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("konnect-1"),
- },
- Backend: "aws",
- Prefix: "aws-vault",
- },
- Status: configurationv1alpha1.KongVaultStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{
- ControlPlaneID: "konnect-1",
- },
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- ObservedGeneration: 1,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(v *configurationv1alpha1.KongVault) {
- v.Spec.ControlPlaneRef = &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("konnect-2"),
- }
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
- },
- {
- Name: "control plane is immutable once programmed (empty -> non-empty)",
- TestObject: &configurationv1alpha1.KongVault{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongVaultSpec{
- Backend: "aws",
- Prefix: "aws-vault",
- },
- Status: configurationv1alpha1.KongVaultStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{
- ControlPlaneID: "konnect-1",
- },
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- ObservedGeneration: 1,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(v *configurationv1alpha1.KongVault) {
- v.Spec.ControlPlaneRef = &configurationv1alpha1.ControlPlaneRef{
- Type: configurationv1alpha1.ControlPlaneRefKonnectID,
- KonnectID: lo.ToPtr("konnect"),
- }
- },
- ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ obj := &configurationv1alpha1.KongVault{
+ TypeMeta: metav1.TypeMeta{
+ Kind: "KongVault",
+ APIVersion: configurationv1alpha1.GroupVersion.String(),
},
- {
- Name: "programmed object can be updated when no controlPlaneRef set",
- TestObject: &configurationv1alpha1.KongVault{
- ObjectMeta: commonObjectMeta,
- Spec: configurationv1alpha1.KongVaultSpec{
- Backend: "aws",
- Prefix: "aws-vault",
- },
- Status: configurationv1alpha1.KongVaultStatus{
- Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{
- ControlPlaneID: "konnect-1",
- },
- Conditions: []metav1.Condition{
- {
- Type: "Programmed",
- Status: metav1.ConditionTrue,
- ObservedGeneration: 1,
- Reason: "Programmed",
- LastTransitionTime: metav1.Now(),
- },
- },
- },
- },
- Update: func(v *configurationv1alpha1.KongVault) {
- v.Spec.Backend = "aws-2"
- },
+ ObjectMeta: commonObjectMeta,
+ Spec: configurationv1alpha1.KongVaultSpec{
+ Backend: "aws",
+ Prefix: "aws-vault",
},
- }.Run(t)
+ }
+
+ NewCRDValidationTestCasesGroupCPRefChange(t, obj).Run(t)
})
t.Run("spec", func(t *testing.T) {
diff --git a/test/crdsvalidation/suite_crd_ref_change_test.go b/test/crdsvalidation/suite_crd_ref_change_test.go
new file mode 100644
index 0000000..cc3a08d
--- /dev/null
+++ b/test/crdsvalidation/suite_crd_ref_change_test.go
@@ -0,0 +1,312 @@
+package crdsvalidation_test
+
+import (
+ "testing"
+
+ configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
+ "github.com/samber/lo"
+ "github.com/stretchr/testify/require"
+ "k8s.io/apimachinery/pkg/api/meta"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/client-go/discovery"
+ "k8s.io/client-go/restmapper"
+ "sigs.k8s.io/controller-runtime/pkg/client"
+ "sigs.k8s.io/controller-runtime/pkg/client/config"
+)
+
+type Scope byte
+
+const (
+ ScopeCluster Scope = iota
+ ScopeNamespace
+)
+
+func getGroupKindScope(t *testing.T, obj client.Object) meta.RESTScopeName {
+ config, err := config.GetConfig()
+ require.NoError(t, err)
+
+ dc := discovery.NewDiscoveryClientForConfigOrDie(config)
+ groupResources, err := restmapper.GetAPIGroupResources(dc)
+ require.NoError(t, err)
+
+ gk := obj.GetObjectKind().GroupVersionKind().GroupKind()
+ r, err := restmapper.NewDiscoveryRESTMapper(groupResources).RESTMapping(gk)
+ require.NoError(t, err)
+ return r.Scope.Name()
+}
+
+func NewCRDValidationTestCasesGroupCPRefChange[
+ T interface {
+ client.Object
+ DeepCopy() T
+ SetConditions([]metav1.Condition)
+ SetControlPlaneRef(*configurationv1alpha1.ControlPlaneRef)
+ GetControlPlaneRef() *configurationv1alpha1.ControlPlaneRef
+ },
+](t *testing.T, obj T) CRDValidationTestCasesGroup[T] {
+ var (
+ ret = CRDValidationTestCasesGroup[T]{}
+
+ programmedConditionTrue = metav1.Condition{
+ Type: "Programmed",
+ Status: metav1.ConditionTrue,
+ Reason: "Valid",
+ LastTransitionTime: metav1.Now(),
+ }
+ programmedConditionFalse = metav1.Condition{
+ Type: "Programmed",
+ Status: metav1.ConditionFalse,
+ Reason: "NotProgrammed",
+ LastTransitionTime: metav1.Now(),
+ }
+ objScope = getGroupKindScope(t, obj)
+ )
+
+ {
+ // Since objects managed by KIC do not require spec.controlPlane,
+ // object without spec.controlPlaneRef should be allowed.
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(nil)
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "no cpRef is valid",
+ TestObject: obj,
+ })
+ }
+ {
+ if objScope == meta.RESTScopeNameNamespace {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ Namespace: "another-namespace",
+ },
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef (type=konnectNamespacedRef) cannot have namespace",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("spec.controlPlaneRef cannot specify namespace for namespaced resource"),
+ })
+ }
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectID: lo.ToPtr("123456"),
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectID when type is konnectNamespacedRef yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectNamespacedRef must be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectID,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectNamespacedRef when type is konnectID yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectID must be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectID,
+ KonnectID: lo.ToPtr("123456"),
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectNamespacedRef and konnectID when type is konnectID yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is konnectID, konnectNamespacedRef must not be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectID: lo.ToPtr("123456"),
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectID and konnectNamespacedRef when type is konnectNamespacedRef yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is konnectNamespacedRef, konnectID must not be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKIC,
+ KonnectID: lo.ToPtr("123456"),
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectID when type is kic yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is kic, konnectID must not be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKIC,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "providing konnectNamespaceRef when type is kic yields an error",
+ TestObject: obj,
+ ExpectedErrorMessage: lo.ToPtr("when type is kic, konnectNamespacedRef must not be set"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKIC,
+ })
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "kic control plane ref is allowed",
+ TestObject: obj,
+ })
+ }
+
+ // Updates: KonnectNamespacedRef
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ obj.SetConditions([]metav1.Condition{programmedConditionTrue})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=konnectNamespacedRef) is not allowed for Programmed=True",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := obj.GetControlPlaneRef()
+ cpRef.KonnectNamespacedRef.Name = "new-konnect-control-plane"
+ obj.SetControlPlaneRef(cpRef)
+ },
+ ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "test-konnect-control-plane",
+ },
+ })
+ obj.SetConditions([]metav1.Condition{programmedConditionFalse})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=konnectNamespacedRef) is allowed when object is Programmed=False",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := &configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "new-konnect-control-plane",
+ },
+ }
+ obj.SetControlPlaneRef(cpRef)
+ },
+ })
+ }
+
+ // Updates: KIC
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKIC,
+ })
+ obj.SetConditions([]metav1.Condition{programmedConditionTrue})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=kic) is not allowed for Programmed=True",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := &configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "new-konnect-control-plane",
+ },
+ }
+ obj.SetControlPlaneRef(cpRef)
+ },
+ ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKIC,
+ })
+ obj.SetConditions([]metav1.Condition{programmedConditionFalse})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=kic) is allowed when object is not Programmed=True",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := &configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "new-konnect-control-plane",
+ },
+ }
+ obj.SetControlPlaneRef(cpRef)
+ },
+ })
+ }
+
+ // Updates: ControlPlane ref is unset
+ {
+ obj := obj.DeepCopy()
+ obj.SetConditions([]metav1.Condition{programmedConditionFalse})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=) is allowed when object is Programmed=False",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := &configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "new-konnect-control-plane",
+ },
+ }
+ obj.SetControlPlaneRef(cpRef)
+ },
+ })
+ }
+ {
+ obj := obj.DeepCopy()
+ obj.SetControlPlaneRef(&configurationv1alpha1.ControlPlaneRef{})
+ obj.SetConditions([]metav1.Condition{programmedConditionTrue})
+ ret = append(ret, CRDValidationTestCase[T]{
+ Name: "cpRef change (type=) is not allowed for Programmed=True",
+ TestObject: obj,
+ Update: func(obj T) {
+ cpRef := &configurationv1alpha1.ControlPlaneRef{
+ Type: configurationv1alpha1.ControlPlaneRefKonnectNamespacedRef,
+ KonnectNamespacedRef: &configurationv1alpha1.KonnectNamespacedRef{
+ Name: "new-konnect-control-plane",
+ },
+ }
+ obj.SetControlPlaneRef(cpRef)
+ },
+ ExpectedUpdateErrorMessage: lo.ToPtr("spec.controlPlaneRef is immutable when an entity is already Programmed"),
+ })
+ }
+
+ return ret
+}