Skip to content

Commit

Permalink
remove controlPlaneRef in KongTarget because it always refers to Kong…
Browse files Browse the repository at this point in the history
…Upstream (#84)

* remove controlPlaneRef in KongTarget because it always refers to KongUpstream

* update konnect status of KongTarget to include upstreamID

* fix description of ControlPlaneID
  • Loading branch information
randmonkey authored Sep 19, 2024
1 parent c8c38fe commit 120a257
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 167 deletions.
9 changes: 2 additions & 7 deletions api/configuration/v1alpha1/kong_target_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
7 changes: 1 addition & 6 deletions api/configuration/v1alpha1/zz_generated.deepcopy.go

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

10 changes: 10 additions & 0 deletions api/konnect/v1alpha1/konnect_entity_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
16 changes: 16 additions & 0 deletions api/konnect/v1alpha1/zz_generated.deepcopy.go

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

49 changes: 5 additions & 44 deletions config/crd/bases/configuration.konghq.com_kongtargets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: |-
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,6 @@ _Appears in:_
- [KongConsumerSpec](#kongconsumerspec)
- [KongPluginBindingSpec](#kongpluginbindingspec)
- [KongServiceSpec](#kongservicespec)
- [KongTargetSpec](#kongtargetspec)
- [KongUpstreamSpec](#kongupstreamspec)
- [KongVaultSpec](#kongvaultspec)

Expand Down Expand Up @@ -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. |
Expand Down
3 changes: 3 additions & 0 deletions docs/konnect-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,16 @@ _Appears in:_

_Appears in:_
- [KonnectEntityStatusWithControlPlaneAndServiceRefs](#konnectentitystatuswithcontrolplaneandservicerefs)
- [KonnectEntityStatusWithControlPlaneAndUpstreamRefs](#konnectentitystatuswithcontrolplaneandupstreamrefs)
- [KonnectEntityStatusWithControlPlaneRef](#konnectentitystatuswithcontrolplaneref)
- [KonnectGatewayControlPlaneStatus](#konnectgatewaycontrolplanestatus)







#### KonnectGatewayControlPlaneSpec


Expand Down
2 changes: 1 addition & 1 deletion test/crdsvalidation/kongtarget/testcases/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
99 changes: 0 additions & 99 deletions test/crdsvalidation/kongtarget/testcases/controlplaneref.go

This file was deleted.

4 changes: 0 additions & 4 deletions test/crdsvalidation/kongtarget/testcases/kongtargetapispec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down
4 changes: 0 additions & 4 deletions test/crdsvalidation/kongtarget/testcases/upstreamref.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand Down

0 comments on commit 120a257

Please sign in to comment.