Skip to content

Commit

Permalink
feat(konnect): make controlPlaneRef optional for KongService, KongCon…
Browse files Browse the repository at this point in the history
…sumer and KongPluginBinding
  • Loading branch information
pmalek committed Aug 13, 2024
1 parent ac8a90c commit 040db10
Show file tree
Hide file tree
Showing 27 changed files with 389 additions and 146 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ GOTESTSUM_FORMAT ?= standard-verbose
.PHONY: test
test: test.unit test.crds-validation

.PHONY: test.pretty
test.pretty: test.unit.pretty test.crds-validation.pretty

UNIT_TEST_PATHS := ./test/unit/...
CRDS_VALIDATION_TEST_PATHS := ./test/crdsvalidation/...

Expand Down
3 changes: 2 additions & 1 deletion api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func (c *KongConsumer) SetConditions(conditions []metav1.Condition) {

type KongConsumerSpec struct {
// ControlPlaneRef is a reference to a ControlPlane this Route is associated with.
ControlPlaneRef configurationv1alpha1.ControlPlaneRef `json:"controlPlaneRef,omitempty"`
// +kubebuilder:validation:Optional
ControlPlaneRef *configurationv1alpha1.ControlPlaneRef `json:"controlPlaneRef,omitempty"`

// KonnectConfiguration holds the Konnect configuration like authentication configuration.
KonnectConfiguration konnectv1alpha1.KonnectConfiguration `json:"konnect,omitempty"`
Expand Down
11 changes: 8 additions & 3 deletions api/configuration/v1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type KongPluginBindingSpec struct {
Targets KongPluginBindingTargets `json:"targets"`

// ControlPlaneRef is a reference to a ControlPlane this KongPluginBinding is associated with.
ControlPlaneRef ControlPlaneRef `json:"controlPlaneRef,omitempty"`
ControlPlaneRef *ControlPlaneRef `json:"controlPlaneRef,omitempty"`
}

// KongPluginBindingTargets contains the targets references.
Expand Down
7 changes: 4 additions & 3 deletions api/configuration/v1alpha1/kongservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
// +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="(!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 entity is already Programmed."
// +kubebuilder:validation:XValidation:rule="(!has(self.status) || !self.status.conditions.exists(c, c.type == 'Programmed' && c.status == 'True') || oldSelf.spec.controlPlaneRef.type != 'konnectNamespacedRef') ? true : oldSelf.spec.controlPlaneRef.konnectNamespacedRef.name == self.spec.controlPlaneRef.konnectNamespacedRef.name", message="spec.controlPlaneRef is immutable when entity is already Programmed."
type KongService struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -88,9 +89,9 @@ func (c *KongService) SetConditions(conditions []metav1.Condition) {

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

KongServiceAPISpec `json:",inline"`
}
Expand Down
32 changes: 17 additions & 15 deletions api/configuration/v1alpha1/konnect_controlplaneref_types.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
package v1alpha1

const (
ControlPlaneRefKonnectID = "konnectID"
// ControlPlaneRefKonnectID is the type for the KonnectID ControlPlaneRef.
// It is used to reference a Konnect Control Plane entity by its ID on the Konnect platform.
ControlPlaneRefKonnectID = "konnectID"
// ControlPlaneRefKonnectNamespacedRef is the type for the KonnectNamespacedRef ControlPlaneRef.
// It is used to reference a Konnect Control Plane entity inside the cluster
// using a namespaced reference.
ControlPlaneRefKonnectNamespacedRef = "konnectNamespacedRef"
ControlPlaneRefKIC = "kic"
)

// ControlPlaneRef is the schema for the ControlPlaneRef type.
// It is used to reference a Control Plane entity.
// +kubebuilder:validation:XValidation:rule="self.type == 'konnectNamespacedRef' ? has(self.konnectNamespacedRef) : true", message="when type is konnectNamespacedRef, konnectNamespacedRef must be set"
type ControlPlaneRef struct {
// Type can be one of:
// - konnectID
// - konnectNamespacedRef
// - kic
// +kubebuilder:validation:Enum=konnectID;konnectNamespacedRef
Type string `json:"type,omitempty"`

// TODO(pmalek)
// KonnectID is the schema for the KonnectID type.
// This field is required when the Type is konnectID.
KonnectID *string `json:"konnectID,omitempty"`

// KonnectNamespacedRef is a reference to a Konnect Control Plane entity inside the cluster.
// It contains the name of the Konnect Control Plane and the namespace in which it exists.
// If the namespace is not provided, it is assumed that the Konnect Control Plane
// is in the same namespace as the resource that references it.
// It contains the name of the Konnect Control Plane.
// This field is required when the Type is konnectNamespacedRef.
KonnectNamespacedRef *KonnectNamespacedRef `json:"konnectNamespacedRef,omitempty"`

// TODO(pmalek)
KIC *KIC `json:"kic,omitempty"`
}

// KonnectNamespacedRef is the schema for the KonnectNamespacedRef type.
type KonnectNamespacedRef struct {
// Name is the name of the Konnect Control Plane.
// +kubebuilder:validation:Required
Name string `json:"name"`

// +kubebuilder:validation:Optional
Namespace string `json:"namespace,omitempty"`
// TODO: Implement cross namespace references:
// https://github.com/Kong/kubernetes-configuration/issues/36
}

// TODO(pmalek)
type KIC struct{}
32 changes: 10 additions & 22 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.

2 changes: 2 additions & 0 deletions api/konnect/v1alpha1/konnect_controlplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type KonnectControlPlane struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

// Spec defines the desired state of KonnectControlPlane.
Spec KonnectControlPlaneSpec `json:"spec,omitempty"`

// Status defines the observed state of KonnectControlPlane.
Status KonnectControlPlaneStatus `json:"status,omitempty"`
}

Expand Down
24 changes: 14 additions & 10 deletions config/crd/bases/configuration.konghq.com_kongconsumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,19 @@ spec:
description: ControlPlaneRef is a reference to a ControlPlane this
Route is associated with.
properties:
kic:
description: TODO(pmalek)
type: object
konnectID:
description: TODO(pmalek)
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 and the namespace in which it exists.
If the namespace is not provided, it is assumed that the Konnect Control Plane
is in the same namespace as the resource that references it.
It contains the name of the Konnect Control Plane.
This field is required when the Type is konnectNamespacedRef.
properties:
name:
type: string
namespace:
description: Name is the name of the Konnect Control Plane.
type: string
required:
- name
Expand All @@ -104,9 +101,16 @@ spec:
Type can be one of:
- konnectID
- konnectNamespacedRef
- kic
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'
konnect:
description: KonnectConfiguration holds the Konnect configuration
like authentication configuration.
Expand Down
24 changes: 14 additions & 10 deletions config/crd/bases/configuration.konghq.com_kongpluginbindings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,19 @@ spec:
description: ControlPlaneRef is a reference to a ControlPlane this
KongPluginBinding is associated with.
properties:
kic:
description: TODO(pmalek)
type: object
konnectID:
description: TODO(pmalek)
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 and the namespace in which it exists.
If the namespace is not provided, it is assumed that the Konnect Control Plane
is in the same namespace as the resource that references it.
It contains the name of the Konnect Control Plane.
This field is required when the Type is konnectNamespacedRef.
properties:
name:
type: string
namespace:
description: Name is the name of the Konnect Control Plane.
type: string
required:
- name
Expand All @@ -82,9 +79,16 @@ spec:
Type can be one of:
- konnectID
- konnectNamespacedRef
- kic
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'
pluginRef:
description: PluginReference is a reference to the KongPlugin or KongClusterPlugin
resource.
Expand Down
24 changes: 14 additions & 10 deletions config/crd/bases/configuration.konghq.com_kongroutes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,19 @@ spec:
description: ControlPlaneRef is a reference to a ControlPlane this
Route is associated with.
properties:
kic:
description: TODO(pmalek)
type: object
konnectID:
description: TODO(pmalek)
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 and the namespace in which it exists.
If the namespace is not provided, it is assumed that the Konnect Control Plane
is in the same namespace as the resource that references it.
It contains the name of the Konnect Control Plane.
This field is required when the Type is konnectNamespacedRef.
properties:
name:
type: string
namespace:
description: Name is the name of the Konnect Control Plane.
type: string
required:
- name
Expand All @@ -73,9 +70,16 @@ spec:
Type can be one of:
- konnectID
- konnectNamespacedRef
- kic
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'
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
Loading

0 comments on commit 040db10

Please sign in to comment.