diff --git a/api/configuration/v1alpha1/kong_target_types.go b/api/configuration/v1alpha1/kong_target_types.go index 2c28281..f9a98ea 100644 --- a/api/configuration/v1alpha1/kong_target_types.go +++ b/api/configuration/v1alpha1/kong_target_types.go @@ -30,8 +30,6 @@ import ( // +kubebuilder:storageversion // +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="(!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="oldSelf.spec.upstreamRef == self.spec.upstreamRef", message="spec.upstreamRef is immutable" type KongTarget struct { metav1.TypeMeta `json:",inline"` @@ -43,7 +41,7 @@ type KongTarget struct { } func (t *KongTarget) initKonnectStatus() { - t.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{} + t.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndUpstreamRefs{} } // GetKonnectStatus returns the Konnect status contained in the KongTarget status. @@ -102,9 +100,6 @@ func (t *KongTarget) SetConditions(conditions []metav1.Condition) { } type KongTargetSpec struct { - // ControlPlaneRef is a reference to a ControlPlane this KongTarget is associated with. - // +optional - ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"` // UpstreamRef is a reference to a KongUpstream this KongTarget is attached to. UpstreamRef TargetRef `json:"upstreamRef"` // KongTargetAPISpec are the attributes of the Kong Target itself. @@ -126,7 +121,7 @@ type KongTargetAPISpec struct { type KongTargetStatus struct { // Konnect contains the Konnect entity status. // +optional - Konnect *konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"` + Konnect *konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndUpstreamRefs `json:"konnect,omitempty"` // Conditions describe the status of the Konnect entity. // +listType=map diff --git a/api/configuration/v1alpha1/zz_generated.deepcopy.go b/api/configuration/v1alpha1/zz_generated.deepcopy.go index 59d57ff..293dd75 100644 --- a/api/configuration/v1alpha1/zz_generated.deepcopy.go +++ b/api/configuration/v1alpha1/zz_generated.deepcopy.go @@ -1116,11 +1116,6 @@ func (in *KongTargetList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KongTargetSpec) DeepCopyInto(out *KongTargetSpec) { *out = *in - if in.ControlPlaneRef != nil { - in, out := &in.ControlPlaneRef, &out.ControlPlaneRef - *out = new(ControlPlaneRef) - (*in).DeepCopyInto(*out) - } out.UpstreamRef = in.UpstreamRef in.KongTargetAPISpec.DeepCopyInto(&out.KongTargetAPISpec) } @@ -1140,7 +1135,7 @@ func (in *KongTargetStatus) DeepCopyInto(out *KongTargetStatus) { *out = *in if in.Konnect != nil { in, out := &in.Konnect, &out.Konnect - *out = new(konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef) + *out = new(konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndUpstreamRefs) **out = **in } if in.Conditions != nil { diff --git a/api/konnect/v1alpha1/konnect_entity_status.go b/api/konnect/v1alpha1/konnect_entity_status.go index 72a8b2c..4e098af 100644 --- a/api/konnect/v1alpha1/konnect_entity_status.go +++ b/api/konnect/v1alpha1/konnect_entity_status.go @@ -87,3 +87,13 @@ func (in *KonnectEntityStatusWithControlPlaneAndServiceRefs) SetControlPlaneID(i func (in *KonnectEntityStatusWithControlPlaneAndServiceRefs) GetControlPlaneID() string { return in.ControlPlaneID } + +type KonnectEntityStatusWithControlPlaneAndUpstreamRefs struct { + KonnectEntityStatus `json:",inline"` + + // ControlPlaneID is the Konnect ID of the ControlPlane this entity is associated with. + ControlPlaneID string `json:"controlPlaneID,omitempty"` + + // UpstreamID is the Konnect ID of the Upstream this entity is associated with. + UpstreamID string `json:"upstreamID,omitempty"` +} diff --git a/api/konnect/v1alpha1/zz_generated.deepcopy.go b/api/konnect/v1alpha1/zz_generated.deepcopy.go index 7e5a540..4da9aea 100644 --- a/api/konnect/v1alpha1/zz_generated.deepcopy.go +++ b/api/konnect/v1alpha1/zz_generated.deepcopy.go @@ -173,6 +173,22 @@ func (in *KonnectEntityStatusWithControlPlaneAndServiceRefs) DeepCopy() *Konnect return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *KonnectEntityStatusWithControlPlaneAndUpstreamRefs) DeepCopyInto(out *KonnectEntityStatusWithControlPlaneAndUpstreamRefs) { + *out = *in + out.KonnectEntityStatus = in.KonnectEntityStatus +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KonnectEntityStatusWithControlPlaneAndUpstreamRefs. +func (in *KonnectEntityStatusWithControlPlaneAndUpstreamRefs) DeepCopy() *KonnectEntityStatusWithControlPlaneAndUpstreamRefs { + if in == nil { + return nil + } + out := new(KonnectEntityStatusWithControlPlaneAndUpstreamRefs) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KonnectEntityStatusWithControlPlaneRef) DeepCopyInto(out *KonnectEntityStatusWithControlPlaneRef) { *out = *in diff --git a/config/crd/bases/configuration.konghq.com_kongtargets.yaml b/config/crd/bases/configuration.konghq.com_kongtargets.yaml index 2ad63e7..ad258ac 100644 --- a/config/crd/bases/configuration.konghq.com_kongtargets.yaml +++ b/config/crd/bases/configuration.konghq.com_kongtargets.yaml @@ -44,44 +44,6 @@ spec: type: object spec: properties: - controlPlaneRef: - description: ControlPlaneRef is a reference to a ControlPlane this - KongTarget is associated with. - properties: - konnectID: - description: |- - KonnectID is the schema for the KonnectID type. - This field is required when the Type is konnectID. - type: string - konnectNamespacedRef: - description: |- - 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. - properties: - name: - description: Name is the name of the Konnect Control Plane. - type: string - required: - - name - type: object - type: - description: |- - Type can be one of: - - konnectID - - konnectNamespacedRef - enum: - - konnectID - - konnectNamespacedRef - type: string - type: object - x-kubernetes-validations: - - message: when type is konnectNamespacedRef, konnectNamespacedRef - must be set - rule: 'self.type == ''konnectNamespacedRef'' ? has(self.konnectNamespacedRef) - : true' - - message: when type is konnectID, konnectID must be set - rule: 'self.type == ''konnectID'' ? has(self.konnectID) : true' tags: description: Tags is an optional set of strings associated with the Target for grouping and filtering. @@ -189,7 +151,7 @@ spec: properties: controlPlaneID: description: ControlPlaneID is the Konnect ID of the ControlPlane - this Route is associated with. + this entity is associated with. type: string id: description: |- @@ -204,17 +166,16 @@ spec: description: ServerURL is the URL of the Konnect server in which the entity exists. type: string + upstreamID: + description: UpstreamID is the Konnect ID of the Upstream this + entity is associated with. + type: string type: object type: object required: - spec type: object x-kubernetes-validations: - - message: controlPlaneRef is required once set - rule: '!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)' - - 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.upstreamRef is immutable rule: oldSelf.spec.upstreamRef == self.spec.upstreamRef served: true diff --git a/docs/api-reference.md b/docs/api-reference.md index 5c21439..ac5c816 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -525,7 +525,6 @@ _Appears in:_ - [KongConsumerSpec](#kongconsumerspec) - [KongPluginBindingSpec](#kongpluginbindingspec) - [KongServiceSpec](#kongservicespec) -- [KongTargetSpec](#kongtargetspec) - [KongUpstreamSpec](#kongupstreamspec) - [KongVaultSpec](#kongvaultspec) @@ -856,7 +855,6 @@ _Appears in:_ | Field | Description | | --- | --- | -| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this KongTarget is associated with. | | `upstreamRef` _[TargetRef](#targetref)_ | UpstreamRef is a reference to a KongUpstream this KongTarget is attached to. | | `target` _string_ | Target is the target address of the upstream. | | `weight` _integer_ | Weight is the weight this target gets within the upstream loadbalancer. | diff --git a/docs/konnect-api-reference.md b/docs/konnect-api-reference.md index 6eaa578..8dacc75 100644 --- a/docs/konnect-api-reference.md +++ b/docs/konnect-api-reference.md @@ -123,6 +123,7 @@ _Appears in:_ _Appears in:_ - [KonnectEntityStatusWithControlPlaneAndServiceRefs](#konnectentitystatuswithcontrolplaneandservicerefs) +- [KonnectEntityStatusWithControlPlaneAndUpstreamRefs](#konnectentitystatuswithcontrolplaneandupstreamrefs) - [KonnectEntityStatusWithControlPlaneRef](#konnectentitystatuswithcontrolplaneref) - [KonnectGatewayControlPlaneStatus](#konnectgatewaycontrolplanestatus) @@ -130,6 +131,8 @@ _Appears in:_ + + #### KonnectGatewayControlPlaneSpec diff --git a/test/crdsvalidation/kongtarget/testcases/common.go b/test/crdsvalidation/kongtarget/testcases/common.go index 00b61e3..8fa2c2f 100644 --- a/test/crdsvalidation/kongtarget/testcases/common.go +++ b/test/crdsvalidation/kongtarget/testcases/common.go @@ -25,7 +25,7 @@ type testCasesGroup struct { var TestCases = []testCasesGroup{} func init() { - TestCases = append(TestCases, controlPlaneRef, upstreamRef, kongTargetAPISpec) + TestCases = append(TestCases, upstreamRef, kongTargetAPISpec) } var commonObjectMeta = metav1.ObjectMeta{ diff --git a/test/crdsvalidation/kongtarget/testcases/controlplaneref.go b/test/crdsvalidation/kongtarget/testcases/controlplaneref.go deleted file mode 100644 index 7b03f3c..0000000 --- a/test/crdsvalidation/kongtarget/testcases/controlplaneref.go +++ /dev/null @@ -1,99 +0,0 @@ -package testcases - -import ( - "github.com/samber/lo" - 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" -) - -var controlPlaneRef = testCasesGroup{ - Name: "controlPlaneRef", - TestCases: []testCase{ - { - Name: "no control plane ref to have control plane ref in valid", - KongTarget: configurationv1alpha1.KongTarget{ - ObjectMeta: commonObjectMeta, - Spec: configurationv1alpha1.KongTargetSpec{ - UpstreamRef: configurationv1alpha1.TargetRef{ - Name: "upstream", - }, - KongTargetAPISpec: configurationv1alpha1.KongTargetAPISpec{ - Target: "example.com", - Weight: 100, - }, - }, - }, - Update: func(kt *configurationv1alpha1.KongTarget) { - kt.Spec.ControlPlaneRef = &configurationv1alpha1.ControlPlaneRef{ - Type: configurationv1alpha1.ControlPlaneRefKonnectID, - KonnectID: lo.ToPtr("konnect-1"), - } - }, - }, - { - Name: "have control plane to no control plane is invalid", - KongTarget: configurationv1alpha1.KongTarget{ - ObjectMeta: commonObjectMeta, - Spec: configurationv1alpha1.KongTargetSpec{ - ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{ - Type: configurationv1alpha1.ControlPlaneRefKonnectID, - KonnectID: lo.ToPtr("konnect-1"), - }, - UpstreamRef: configurationv1alpha1.TargetRef{ - Name: "upstream", - }, - KongTargetAPISpec: configurationv1alpha1.KongTargetAPISpec{ - Target: "example.com", - Weight: 100, - }, - }, - }, - Update: func(kt *configurationv1alpha1.KongTarget) { - kt.Spec.ControlPlaneRef = nil - }, - ExpectedUpdateErrorMessage: lo.ToPtr("controlPlaneRef is required once set"), - }, - { - Name: "control plane is immutable once programmed", - KongTarget: configurationv1alpha1.KongTarget{ - ObjectMeta: commonObjectMeta, - Spec: configurationv1alpha1.KongTargetSpec{ - ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{ - Type: configurationv1alpha1.ControlPlaneRefKonnectID, - KonnectID: lo.ToPtr("konnect-1"), - }, - UpstreamRef: configurationv1alpha1.TargetRef{ - Name: "upstream", - }, - KongTargetAPISpec: configurationv1alpha1.KongTargetAPISpec{ - Target: "example.com", - Weight: 100, - }, - }, - }, - KongTargetStatus: &configurationv1alpha1.KongTargetStatus{ - Konnect: &konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef{ - ControlPlaneID: "konnect-1", - }, - Conditions: []metav1.Condition{ - { - Type: "Programmed", - Status: metav1.ConditionTrue, - ObservedGeneration: 1, - Reason: "Programmed", - LastTransitionTime: metav1.Now(), - }, - }, - }, - Update: func(kt *configurationv1alpha1.KongTarget) { - kt.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"), - }, - }, -} diff --git a/test/crdsvalidation/kongtarget/testcases/kongtargetapispec.go b/test/crdsvalidation/kongtarget/testcases/kongtargetapispec.go index 2f121d3..52eea0d 100644 --- a/test/crdsvalidation/kongtarget/testcases/kongtargetapispec.go +++ b/test/crdsvalidation/kongtarget/testcases/kongtargetapispec.go @@ -14,10 +14,6 @@ var kongTargetAPISpec = testCasesGroup{ KongTarget: configurationv1alpha1.KongTarget{ ObjectMeta: commonObjectMeta, Spec: configurationv1alpha1.KongTargetSpec{ - ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{ - Type: configurationv1alpha1.ControlPlaneRefKonnectID, - KonnectID: lo.ToPtr("konnect-1"), - }, UpstreamRef: configurationv1alpha1.TargetRef{ Name: "upstream", }, diff --git a/test/crdsvalidation/kongtarget/testcases/upstreamref.go b/test/crdsvalidation/kongtarget/testcases/upstreamref.go index 3c04d1f..9dfaf43 100644 --- a/test/crdsvalidation/kongtarget/testcases/upstreamref.go +++ b/test/crdsvalidation/kongtarget/testcases/upstreamref.go @@ -14,10 +14,6 @@ var upstreamRef = testCasesGroup{ KongTarget: configurationv1alpha1.KongTarget{ ObjectMeta: commonObjectMeta, Spec: configurationv1alpha1.KongTargetSpec{ - ControlPlaneRef: &configurationv1alpha1.ControlPlaneRef{ - Type: configurationv1alpha1.ControlPlaneRefKonnectID, - KonnectID: lo.ToPtr("konnect-1"), - }, UpstreamRef: configurationv1alpha1.TargetRef{ Name: "upstream", },