Skip to content

Commit 5e57c37

Browse files
committed
add fields for adopting existing konnect entities
1 parent 43bd4c5 commit 5e57c37

File tree

10 files changed

+286
-0
lines changed

10 files changed

+286
-0
lines changed

api/configuration/v1alpha1/kongservice_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ import (
3939
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.controlPlaneRef) || has(self.spec.controlPlaneRef)", message="controlPlaneRef is required once set"
4040
// +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"
4141
// +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"
42+
// +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"
43+
// +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"
4244
// +apireference:kgo:include
4345
// +kong:channels=gateway-operator
4446
type KongService struct {
@@ -53,12 +55,17 @@ type KongService struct {
5355

5456
// KongServiceSpec defines specification of a Kong Service.
5557
// +kubebuilder:validation:XValidation:rule="!has(self.controlPlaneRef) ? true : self.controlPlaneRef.type != 'kic'", message="KIC is not supported as control plane"
58+
// +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"
5659
// +apireference:kgo:include
5760
type KongServiceSpec struct {
5861
// ControlPlaneRef is a reference to a ControlPlane this KongService is associated with.
5962
// +kubebuilder:validation:Required
6063
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef"`
6164

65+
// KonnectOptions includes options specific to Konnect.
66+
// Only used when we manage the KongService by Konnect entity controller.
67+
KonnectOptions *konnectv1alpha1.KonnectEntityOptions `json:"konnect,omitempty"`
68+
6269
KongServiceAPISpec `json:",inline"`
6370
}
6471

api/configuration/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/konnect/v1alpha1/konnect_configuration.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,15 @@ type KonnectConfiguration struct {
1414
// This is a good place to add fields like "class" which could reference a cluster-wide
1515
// configuration for Konnect (similar to what Gateway API's GatewayClass).
1616
}
17+
18+
// KonnectEntityOptions stores the options of entities specific to Konnect.
19+
// +apireference:kgo:include
20+
type KonnectEntityOptions struct {
21+
Adopt *KonnectAdoptOptions `json:"adopt,omitempty"`
22+
}
23+
24+
// KonnectAdoptOptions stores the options for adopting existing Konnect entities.
25+
// +apireference:kgo:include
26+
type KonnectAdoptOptions struct {
27+
ID string `json:"id"`
28+
}

api/konnect/v1alpha1/konnect_gateway_controlplane_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ type KonnectGatewayControlPlaneSpec struct {
5353
// Only applicable for ControlPlanes that are created as groups.
5454
Members []corev1.LocalObjectReference `json:"members,omitempty"`
5555

56+
Adopt *KonnectAdoptOptions `json:"adopt,omitempty"`
57+
5658
KonnectConfiguration KonnectConfiguration `json:"konnect,omitempty"`
5759
}
5860

api/konnect/v1alpha1/zz_generated.deepcopy.go

Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ spec:
135135
description: The host of the upstream server. Note that the host value
136136
is case sensitive.
137137
type: string
138+
konnect:
139+
description: |-
140+
KonnectOptions includes options specific to Konnect.
141+
Only used when we manage the KongService by Konnect entity controller.
142+
properties:
143+
adopt:
144+
description: KonnectAdoptOptions stores the options for adopting
145+
existing Konnect entities.
146+
properties:
147+
id:
148+
type: string
149+
required:
150+
- id
151+
type: object
152+
type: object
138153
name:
139154
description: The Service name.
140155
type: string
@@ -193,6 +208,10 @@ spec:
193208
- message: KIC is not supported as control plane
194209
rule: '!has(self.controlPlaneRef) ? true : self.controlPlaneRef.type
195210
!= ''kic'''
211+
- message: Cannot specify Konnect specific options when control plane
212+
is not Konnect
213+
rule: '(has(self.controlPlaneRef) && (self.controlPlaneRef.type == ''konnectNamespacedRef''
214+
|| self.controlPlaneRef.type == ''konnectID'')) ? true : !has(self.konnect)'
196215
status:
197216
default:
198217
conditions:
@@ -301,6 +320,15 @@ spec:
301320
rule: '(!has(self.spec.controlPlaneRef)) ? true : (!has(self.status) ||
302321
!self.status.conditions.exists(c, c.type == ''Programmed'' && c.status
303322
== ''True'')) ? true : oldSelf.spec.controlPlaneRef == self.spec.controlPlaneRef'
323+
- message: Cannot add spec.konnect.adopt when an entity is already programmed
324+
rule: '(!has(self.status) || !self.status.conditions.exists(c, c.type ==
325+
''Programmed'' && c.status == ''True'')) ? true : !has(self.spec.konnect)
326+
|| !has(self.spec.konnect.adopt) || (has(oldSelf.spec.konnect) && has(oldSelf.spec.konnect.adopt))'
327+
- message: spec.konnect.adopt is immutable when an entity is already Programmed
328+
rule: '(!has(self.spec.konnect) || !has(self.spec.konnect.adopt) || !has(oldSelf.spec.konnect)
329+
|| !has(oldSelf.spec.konnect.adopt)) ? true : (!has(self.status) || !self.status.conditions.exists(c,
330+
c.type == ''Programmed'' && c.status == ''True'')) ? true : oldSelf.spec.konnect.adopt
331+
== self.spec.konnect.adopt'
304332
served: true
305333
storage: true
306334
subresources:

config/crd/gateway-operator/konnect.konghq.com_konnectgatewaycontrolplanes.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,7 @@ KongServiceSpec defines specification of a Kong Service.
14351435
| Field | Description |
14361436
| --- | --- |
14371437
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this KongService is associated with. |
1438+
| `konnect` _[KonnectEntityOptions](#konnectentityoptions)_ | KonnectOptions includes options specific to Konnect. Only used when we manage the KongService by Konnect entity controller. |
14381439
| `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. |
14391440
| `connect_timeout` _integer_ | The timeout in milliseconds for establishing a connection to the upstream server. |
14401441
| `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`. |

docs/konnect-api-reference.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ KonnectAPIAuthType is the type of authentication used to authenticate with the K
9292
_Appears in:_
9393
- [KonnectAPIAuthConfigurationSpec](#konnectapiauthconfigurationspec)
9494

95+
#### KonnectAdoptOptions
96+
97+
98+
KonnectAdoptOptions stores the options for adopting existing Konnect entities.
99+
100+
101+
102+
| Field | Description |
103+
| --- | --- |
104+
| `id` _string_ | |
105+
106+
107+
_Appears in:_
108+
- [KonnectEntityOptions](#konnectentityoptions)
109+
- [KonnectGatewayControlPlaneSpec](#konnectgatewaycontrolplanespec)
110+
95111
#### KonnectConfiguration
96112

97113

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

126+
127+
110128
#### KonnectEntityStatus
111129

112130

@@ -159,6 +177,7 @@ KonnectGatewayControlPlaneSpec defines the desired state of KonnectGatewayContro
159177
| `proxy_urls` _[ProxyURL](#proxyurl) array_ | Array of proxy URLs associated with reaching the data-planes connected to a control-plane. |
160178
| `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 "_". |
161179
| `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. |
180+
| `adopt` _[KonnectAdoptOptions](#konnectadoptoptions)_ | |
162181
| `konnect` _[KonnectConfiguration](#konnectconfiguration)_ | |
163182

164183

0 commit comments

Comments
 (0)