Skip to content

Feat(Konnect): add fields for adopting existing konnect entities #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions api/configuration/v1alpha1/kongservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ 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) || !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"
// +kubebuilder:validation:XValidation:rule="(!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : !has(self.spec.konnect) || !has(self.spec.konnect.adopt) || (has(oldSelf.spec.konnect) && has(oldSelf.spec.konnect.adopt))", message="Cannot add spec.konnect.adopt when an entity is already programmed"
// +kubebuilder:validation:XValidation:rule="(!has(self.spec.konnect) || !has(self.spec.konnect.adopt) || !has(oldSelf.spec.konnect) || !has(oldSelf.spec.konnect.adopt)) ? true : (!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True')) ? true : oldSelf.spec.konnect.adopt == self.spec.konnect.adopt", message="spec.konnect.adopt is immutable when an entity is already Programmed"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KongService struct {
Expand All @@ -53,12 +55,17 @@ type KongService struct {

// KongServiceSpec defines specification of a Kong Service.
// +kubebuilder:validation:XValidation:rule="!has(self.controlPlaneRef) ? true : self.controlPlaneRef.type != 'kic'", message="KIC is not supported as control plane"
// +kubebuilder:validation:XValidation:rule="(has(self.controlPlaneRef) && (self.controlPlaneRef.type == 'konnectNamespacedRef' || self.controlPlaneRef.type == 'konnectID')) ? true : !has(self.konnect)", message="Cannot specify Konnect specific options when control plane is not Konnect"
// +apireference:kgo:include
type KongServiceSpec struct {
// ControlPlaneRef is a reference to a ControlPlane this KongService is associated with.
// +kubebuilder:validation:Required
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef"`

// KonnectOptions includes options specific to Konnect.
// Only used when we manage the KongService by Konnect entity controller.
KonnectOptions *konnectv1alpha1.KonnectEntityOptions `json:"konnect,omitempty"`

KongServiceAPISpec `json:",inline"`
}

Expand Down
5 changes: 5 additions & 0 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.

12 changes: 12 additions & 0 deletions api/konnect/v1alpha1/konnect_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,15 @@ type KonnectConfiguration struct {
// This is a good place to add fields like "class" which could reference a cluster-wide
// configuration for Konnect (similar to what Gateway API's GatewayClass).
}

// KonnectEntityOptions stores the options of entities specific to Konnect.
// +apireference:kgo:include
type KonnectEntityOptions struct {
Adopt *KonnectAdoptOptions `json:"adopt,omitempty"`
}

// KonnectAdoptOptions stores the options for adopting existing Konnect entities.
// +apireference:kgo:include
type KonnectAdoptOptions struct {
ID string `json:"id"`
}
4 changes: 4 additions & 0 deletions api/konnect/v1alpha1/konnect_gateway_controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func init() {
// +kubebuilder:printcolumn:name="OrgID",description="Konnect Organization ID this resource belongs to.",type=string,JSONPath=`.status.organizationID`
// +kubebuilder:validation:XValidation:message="spec.konnect.authRef is immutable when an entity is already Programmed", rule="!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True') ? true : self.spec.konnect.authRef == oldSelf.spec.konnect.authRef"
// +kubebuilder:validation:XValidation:message="spec.konnect.authRef is immutable when an entity refers to a Valid API Auth Configuration", rule="!self.status.conditions.exists(c, c.type == 'APIAuthValid' && c.status == 'True') ? true : self.spec.konnect.authRef == oldSelf.spec.konnect.authRef"
// +kubebuilder:validation:XValidation:message="Cannot add spec.adopt when an entitiy is already Programmed", rule="!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True') ? true : (!has(self.spec.adopt) || has(oldSelf.spec.adopt))"
// +kubebuilder:validation:XValidation:message="spec.adopt is immutable when an entitiy is already Programmed", rule="!self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True') ? true : ((!has(self.spec.adopt) || !has(oldSelf.spec.adopt)) ? true : self.spec.adopt == oldSelf.spec.adopt)"
// +apireference:kgo:include
// +kong:channels=gateway-operator
type KonnectGatewayControlPlane struct {
Expand Down Expand Up @@ -53,6 +55,8 @@ type KonnectGatewayControlPlaneSpec struct {
// Only applicable for ControlPlanes that are created as groups.
Members []corev1.LocalObjectReference `json:"members,omitempty"`

Adopt *KonnectAdoptOptions `json:"adopt,omitempty"`

KonnectConfiguration KonnectConfiguration `json:"konnect,omitempty"`
}

Expand Down
40 changes: 40 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.

Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ spec:
description: The host of the upstream server. Note that the host value
is case sensitive.
type: string
konnect:
description: |-
KonnectOptions includes options specific to Konnect.
Only used when we manage the KongService by Konnect entity controller.
properties:
adopt:
description: KonnectAdoptOptions stores the options for adopting
existing Konnect entities.
properties:
id:
type: string
required:
- id
type: object
type: object
name:
description: The Service name.
type: string
Expand Down Expand Up @@ -193,6 +208,10 @@ spec:
- message: KIC is not supported as control plane
rule: '!has(self.controlPlaneRef) ? true : self.controlPlaneRef.type
!= ''kic'''
- message: Cannot specify Konnect specific options when control plane
is not Konnect
rule: '(has(self.controlPlaneRef) && (self.controlPlaneRef.type == ''konnectNamespacedRef''
|| self.controlPlaneRef.type == ''konnectID'')) ? true : !has(self.konnect)'
status:
default:
conditions:
Expand Down Expand Up @@ -301,6 +320,15 @@ spec:
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: Cannot add spec.konnect.adopt when an entity is already programmed
rule: '(!has(self.status) || !self.status.conditions.exists(c, c.type ==
''Programmed'' && c.status == ''True'')) ? true : !has(self.spec.konnect)
|| !has(self.spec.konnect.adopt) || (has(oldSelf.spec.konnect) && has(oldSelf.spec.konnect.adopt))'
- message: spec.konnect.adopt is immutable when an entity is already Programmed
rule: '(!has(self.spec.konnect) || !has(self.spec.konnect.adopt) || !has(oldSelf.spec.konnect)
|| !has(oldSelf.spec.konnect.adopt)) ? true : (!has(self.status) || !self.status.conditions.exists(c,
c.type == ''Programmed'' && c.status == ''True'')) ? true : oldSelf.spec.konnect.adopt
== self.spec.konnect.adopt'
served: true
storage: true
subresources:
Expand Down

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

1 change: 1 addition & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,7 @@ KongServiceSpec defines specification of a Kong Service.
| Field | Description |
| --- | --- |
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this KongService is associated with. |
| `konnect` _[KonnectEntityOptions](#konnectentityoptions)_ | KonnectOptions includes options specific to Konnect. Only used when we manage the KongService by Konnect entity controller. |
| `url` _string_ | Helper field to set `protocol`, `host`, `port` and `path` using a URL. This field is write-only and is not returned in responses. |
| `connect_timeout` _integer_ | The timeout in milliseconds for establishing a connection to the upstream server. |
| `enabled` _boolean_ | Whether the Service is active. If set to `false`, the proxy behavior will be as if any routes attached to it do not exist (404). Default: `true`. |
Expand Down
19 changes: 19 additions & 0 deletions docs/konnect-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ KonnectAPIAuthType is the type of authentication used to authenticate with the K
_Appears in:_
- [KonnectAPIAuthConfigurationSpec](#konnectapiauthconfigurationspec)

#### KonnectAdoptOptions


KonnectAdoptOptions stores the options for adopting existing Konnect entities.



| Field | Description |
| --- | --- |
| `id` _string_ | |


_Appears in:_
- [KonnectEntityOptions](#konnectentityoptions)
- [KonnectGatewayControlPlaneSpec](#konnectgatewaycontrolplanespec)

#### KonnectConfiguration


Expand All @@ -107,6 +123,8 @@ KonnectConfiguration is the Schema for the KonnectConfiguration API.
_Appears in:_
- [KonnectGatewayControlPlaneSpec](#konnectgatewaycontrolplanespec)



#### KonnectEntityStatus


Expand Down Expand Up @@ -159,6 +177,7 @@ KonnectGatewayControlPlaneSpec defines the desired state of KonnectGatewayContro
| `proxy_urls` _[ProxyURL](#proxyurl) array_ | Array of proxy URLs associated with reaching the data-planes connected to a control-plane. |
| `labels` _object (keys:string, values:string)_ | Labels store metadata of an entity that can be used for filtering an entity list or for searching across entity types.<br /><br /> Keys must be of length 1-63 characters, and cannot start with "kong", "konnect", "mesh", "kic", or "_". |
| `members` _[LocalObjectReference](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#localobjectreference-v1-core) array_ | Members is a list of references to the KonnectGatewayControlPlaneMembers that are part of this control plane group. Only applicable for ControlPlanes that are created as groups. |
| `adopt` _[KonnectAdoptOptions](#konnectadoptoptions)_ | |
| `konnect` _[KonnectConfiguration](#konnectconfiguration)_ | |


Expand Down
Loading
Loading