Skip to content

Commit

Permalink
chore: add missing Konnect methods (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek authored Aug 19, 2024
1 parent a2fc5a5 commit cf8804a
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 83 deletions.
7 changes: 7 additions & 0 deletions api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ func (c *KongConsumer) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
return &c.Status.Konnect.KonnectEntityStatus
}

func (c *KongConsumer) SetKonnectID(id string) {
if c.Status.Konnect == nil {
c.InitKonnectStatus()
}
c.Status.Konnect.ID = id
}

func (c KongConsumer) GetTypeName() string {
return "KongConsumer"
}
Expand Down
44 changes: 30 additions & 14 deletions api/configuration/v1alpha1/kongroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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.konnect.authRef) || has(self.spec.konnect.authRef)", message="Konnect Configuration's API auth ref reference is required once set"
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.serviceRef) || has(self.spec.serviceRef)", message="serviceRef is required once set"
// +kubebuilder:validation:XValidation:rule="self.spec.protocols.exists(p, p == 'http') ? (has(self.spec.hosts) || has(self.spec.methods) || has(self.spec.paths) || has(self.spec.paths) || has(self.spec.paths) || has(self.spec.headers) ) : true", message="If protocols has 'http', at least one of 'hosts', 'methods', 'paths' or 'headers' must be set"
type KongRoute struct {
metav1.TypeMeta `json:",inline"`
Expand All @@ -45,16 +45,40 @@ type KongRoute struct {
Status KongRouteStatus `json:"status,omitempty"`
}

func (c *KongRoute) InitKonnectStatus() {
c.Status.Konnect = &konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs{}
}

func (c *KongRoute) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
if c.Status.Konnect == nil {
return nil
}
return &c.Status.Konnect.KonnectEntityStatus
}

func (c KongRoute) GetTypeName() string {
return "KongRoute"
func (c *KongRoute) GetControlPlaneID() string {
if c.Status.Konnect == nil {
return ""
}
return c.Status.Konnect.ControlPlaneID
}

func (c *KongRoute) SetControlPlaneID(id string) {
if c.Status.Konnect == nil {
c.InitKonnectStatus()
}
c.Status.Konnect.ControlPlaneID = id
}

func (c *KongRoute) GetKonnectAPIAuthConfigurationRef() konnectv1alpha1.KonnectAPIAuthConfigurationRef {
return c.Spec.KonnectConfiguration.APIAuthConfigurationRef
func (c *KongRoute) SetKonnectID(id string) {
if c.Status.Konnect == nil {
c.InitKonnectStatus()
}
c.Status.Konnect.ID = id
}

func (c KongRoute) GetTypeName() string {
return "KongRoute"
}

// GetConditions returns the Status Conditions
Expand All @@ -69,17 +93,9 @@ func (c *KongRoute) SetConditions(conditions []metav1.Condition) {

// KongRouteSpec defines specification of a Kong Route.
type KongRouteSpec struct {
// ControlPlaneRef is a reference to a ControlPlane this Route is associated with.
// +kubebuilder:validation:Required
ControlPlaneRef ControlPlaneRef `json:"controlPlaneRef"`

// ServiceRef is a reference to a Service this Route is associated with.
// +optional
ServiceRef ServiceRef `json:"serviceRef,omitempty"`

// KonnectConfiguration holds the Konnect configuration like authentication configuration.
// +kubebuilder:validation:Required
KonnectConfiguration konnectv1alpha1.KonnectConfiguration `json:"konnect,omitempty"`
ServiceRef *ServiceRef `json:"serviceRef,omitempty"`

KongRouteAPISpec `json:",inline"`
}
Expand Down
7 changes: 7 additions & 0 deletions api/configuration/v1alpha1/kongservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ func (c *KongService) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
return &c.Status.Konnect.KonnectEntityStatus
}

func (c *KongService) SetKonnectID(id string) {
if c.Status.Konnect == nil {
c.InitKonnectStatus()
}
c.Status.Konnect.ID = id
}

func (c *KongService) GetControlPlaneID() string {
if c.Status.Konnect == nil {
return ""
Expand Down
8 changes: 5 additions & 3 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.

4 changes: 4 additions & 0 deletions api/konnect/v1alpha1/konnect_controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (c *KonnectControlPlane) SetKonnectLabels(labels map[string]string) {
c.Spec.Labels = labels
}

func (c *KonnectControlPlane) SetKonnectID(id string) {
c.Status.ID = id
}

// GetKonnectAPIAuthConfigurationRef returns the Konnect API Auth Configuration Ref.
func (c *KonnectControlPlane) GetKonnectAPIAuthConfigurationRef() KonnectAPIAuthConfigurationRef {
return c.Spec.KonnectConfiguration.APIAuthConfigurationRef
Expand Down
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 @@ -77,3 +77,13 @@ type KonnectEntityStatusWithControlPlaneAndServiceRefs struct {
// ServiceID is the Konnect ID of the Service this entity is associated with.
ServiceID string `json:"serviceID,omitempty"`
}

// SetServerURL sets the server URL of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndServiceRefs) SetControlPlaneID(id string) {
in.ControlPlaneID = id
}

// GetServerURL sets the server URL of the KonnectEntityStatus struct.
func (in *KonnectEntityStatusWithControlPlaneAndServiceRefs) GetControlPlaneID() string {
return in.ControlPlaneID
}
65 changes: 2 additions & 63 deletions config/crd/bases/configuration.konghq.com_kongroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,44 +44,6 @@ spec:
spec:
description: KongRouteSpec defines specification of a Kong Route.
properties:
controlPlaneRef:
description: ControlPlaneRef is a reference to a ControlPlane this
Route 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'
destinations:
description: A list of IP destinations of incoming connections that
match this Route when using stream routing. Each entry is an object
Expand Down Expand Up @@ -120,25 +82,6 @@ spec:
`https` protocol.'
format: int64
type: integer
konnect:
description: KonnectConfiguration holds the Konnect configuration
like authentication configuration.
properties:
authRef:
description: |-
APIAuthConfigurationRef is the reference to the API Auth Configuration
that should be used for this Konnect Configuration.
properties:
name:
description: Name is the name of the KonnectAPIAuthConfiguration
resource.
type: string
required:
- name
type: object
required:
- authRef
type: object
methods:
description: A list of HTTP methods that match this Route.
items:
Expand Down Expand Up @@ -241,9 +184,6 @@ spec:
items:
type: string
type: array
required:
- controlPlaneRef
- konnect
type: object
status:
description: KongRouteStatus represents the current status of the Kong
Expand Down Expand Up @@ -347,9 +287,8 @@ spec:
- spec
type: object
x-kubernetes-validations:
- message: Konnect Configuration's API auth ref reference is required once
set
rule: '!has(oldSelf.spec.konnect.authRef) || has(self.spec.konnect.authRef)'
- message: serviceRef is required once set
rule: '!has(oldSelf.spec.serviceRef) || has(self.spec.serviceRef)'
- message: If protocols has 'http', at least one of 'hosts', 'methods', 'paths'
or 'headers' must be set
rule: 'self.spec.protocols.exists(p, p == ''http'') ? (has(self.spec.hosts)
Expand Down
3 changes: 0 additions & 3 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ It is used to reference a Control Plane entity.
_Appears in:_
- [KongConsumerSpec](#kongconsumerspec)
- [KongPluginBindingSpec](#kongpluginbindingspec)
- [KongRouteSpec](#kongroutespec)
- [KongServiceSpec](#kongservicespec)

#### ControllerReference
Expand Down Expand Up @@ -656,9 +655,7 @@ KongRouteSpec defines specification of a Kong Route.

| Field | Description |
| --- | --- |
| `controlPlaneRef` _[ControlPlaneRef](#controlplaneref)_ | ControlPlaneRef is a reference to a ControlPlane this Route is associated with. |
| `serviceRef` _[ServiceRef](#serviceref)_ | ServiceRef is a reference to a Service this Route is associated with. |
| `konnect` _[KonnectConfiguration](#konnectconfiguration)_ | KonnectConfiguration holds the Konnect configuration like authentication configuration. |
| `destinations` _Destinations array_ | A list of IP destinations of incoming connections that match this Route when using stream routing. Each entry is an object with fields "ip" (optionally in CIDR range notation) and/or "port". |
| `headers` _object (keys:string, values:string)_ | One or more lists of values indexed by header name that will cause this Route to match if present in the request. The `Host` header cannot be used with this attribute: hosts should be specified using the `hosts` attribute. When `headers` contains only one value and that value starts with the special prefix `~*`, the value is interpreted as a regular expression. |
| `hosts` _string array_ | A list of domain names that match this Route. Note that the hosts value is case sensitive. |
Expand Down

0 comments on commit cf8804a

Please sign in to comment.