Skip to content

Commit 012b0d2

Browse files
committed
add adopt types
1 parent 8d39ac7 commit 012b0d2

File tree

7 files changed

+116
-0
lines changed

7 files changed

+116
-0
lines changed

api/common/v1alpha1/adopt_types.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package v1alpha1
2+
3+
// +kubebuilder:object:generate=true
4+
// AdoptOptions is the options for CRDs to attach to an existing Kong entity.
5+
// +kubebuilder:object:generate=true
6+
// +kubebuilder:validation:XValidation:rule="self.from == oldSelf.from",message="'from'(adopt source) is immutable"
7+
// +kubebuilder:validation:XValidation:rule="self.from == 'konnect' ? true : has(self.konnect)",message="Must specify Konnect options when from='konnect'"
8+
// +kubebuilder:validation:XValidation:rule="has(self.konnect) ? (self.konnect.id == oldSelf.konnect.id) : true",message="konnect.id is immutable"
9+
// +apireference:kgo:include
10+
type AdoptOptions struct {
11+
// From is the source of the entity to adopt from.
12+
// Now 'konnect' is supported.
13+
// +required
14+
// +kubebuilder:validation:Enum=konnect
15+
From AdoptSource `json:"from"`
16+
// Konnect is the options for adopting the entity from Konnect.
17+
// Required when from == 'konnect'.
18+
// +optional
19+
Konnect *AdoptKonnectOptions `json:"konnect,omitempty"`
20+
}
21+
22+
// AdoptSource is the type to define the source of the entity to adopt from.
23+
type AdoptSource string
24+
25+
const (
26+
// AdoptSourceKonnect indicates that the entity is adopted from Konnect.
27+
AdoptSourceKonnect AdoptSource = "konnect"
28+
)
29+
30+
// +kubebuilder:object:generate=true
31+
// AdoptKonnectOptions specifies the options for adopting the entity from Konnect.
32+
// +apireference:kgo:include
33+
type AdoptKonnectOptions struct {
34+
// ID is the Konnect ID of the entity.
35+
// +required
36+
ID string `json:"id"`
37+
}

api/common/v1alpha1/zz_generated.deepcopy.go

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

api/configuration/v1alpha1/kongservice_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ type KongServiceSpec struct {
6161
// +required
6262
ControlPlaneRef *commonv1alpha1.ControlPlaneRef `json:"controlPlaneRef"`
6363

64+
// Adopt is the options for adopting a service from an existing service in Konnect.
65+
// +optional
66+
Adopt *commonv1alpha1.AdoptOptions `json:"adopt,omitempty"`
67+
6468
KongServiceAPISpec `json:",inline"`
6569
}
6670

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.

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,39 @@ spec:
5656
spec:
5757
description: KongServiceSpec defines specification of a Kong Service.
5858
properties:
59+
adopt:
60+
description: Adopt is the options for adopting a service from an existing
61+
service in Konnect.
62+
properties:
63+
from:
64+
description: |-
65+
From is the source of the entity to adopt from.
66+
Now 'konnect' is supported.
67+
enum:
68+
- konnect
69+
type: string
70+
konnect:
71+
description: |-
72+
Konnect is the options for adopting the entity from Konnect.
73+
Required when from == 'konnect'.
74+
properties:
75+
id:
76+
description: ID is the Konnect ID of the entity.
77+
type: string
78+
required:
79+
- id
80+
type: object
81+
required:
82+
- from
83+
type: object
84+
x-kubernetes-validations:
85+
- message: '''from''(adopt source) is immutable'
86+
rule: self.from == oldSelf.from
87+
- message: Must specify Konnect options when from='konnect'
88+
rule: 'self.from == ''konnect'' ? true : has(self.konnect)'
89+
- message: konnect.id is immutable
90+
rule: 'has(self.konnect) ? (self.konnect.id == oldSelf.konnect.id)
91+
: true'
5992
connect_timeout:
6093
description: The timeout in milliseconds for establishing a connection
6194
to the upstream server.

docs/all-api-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,7 @@ KongServiceSpec defines specification of a Kong Service.
12841284
| Field | Description |
12851285
| --- | --- |
12861286
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this KongService is associated with. |
1287+
| `adopt` _[AdoptOptions](#adoptoptions)_ | Adopt is the options for adopting a service from an existing service in Konnect. |
12871288
| `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. |
12881289
| `connect_timeout` _integer_ | The timeout in milliseconds for establishing a connection to the upstream server. |
12891290
| `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/configuration-api-reference.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,7 @@ KongServiceSpec defines specification of a Kong Service.
12781278
| Field | Description |
12791279
| --- | --- |
12801280
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this KongService is associated with. |
1281+
| `adopt` _[AdoptOptions](#adoptoptions)_ | Adopt is the options for adopting a service from an existing service in Konnect. |
12811282
| `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. |
12821283
| `connect_timeout` _integer_ | The timeout in milliseconds for establishing a connection to the upstream server. |
12831284
| `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`. |

0 commit comments

Comments
 (0)