Skip to content

Commit

Permalink
feat: dataplaneKonnectExtension CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Mattia Lavacca <[email protected]>
  • Loading branch information
mlavacca committed Aug 1, 2024
1 parent 76401ff commit b09db39
Show file tree
Hide file tree
Showing 18 changed files with 865 additions and 7 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@
[#387](https://github.com/Kong/gateway-operator/pull/387)
- Introduce `KongPluginInstallation` CRD to allow installing custom Kong
plugins distributed as container images.
[400](https://github.com/Kong/gateway-operator/pull/400)
[#400](https://github.com/Kong/gateway-operator/pull/400)
- The `DataPlaneKonnectExtension` CRD has been introduced. Such a CRD can be attached
to a `DataPlane` via the extensions field to have a konnect-flavored `DataPlane`.
[#453](https://github.com/Kong/gateway-operator/pull/453)

### Fixed

Expand Down
74 changes: 74 additions & 0 deletions api/v1alpha1/dataplane_konnect_extension_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package v1alpha1

/*
Copyright 2024 Kong Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&DataplaneKonnectExtension{}, &DataplaneKonnectExtensionList{})

Check failure on line 21 in api/v1alpha1/dataplane_konnect_extension_types.go

View workflow job for this annotation

GitHub Actions / lint

use of `DataplaneKonnectExtension` forbidden because "Please use camel case 'DataPlane' instead of 'Dataplane'" (forbidigo)
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:categories=kong;all
// +kubebuilder:subresource:status

// DataPlane is the Schema for the dataplanes API
type DataplaneKonnectExtension struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec DataplaneKonnectExtensionSpec `json:"spec,omitempty"`

Check failure on line 35 in api/v1alpha1/dataplane_konnect_extension_types.go

View workflow job for this annotation

GitHub Actions / lint

use of `DataplaneKonnectExtensionSpec` forbidden because "Please use camel case 'DataPlane' instead of 'Dataplane'" (forbidigo)
Status DataplaneKonnectExtensionStatus `json:"status,omitempty"`

Check failure on line 36 in api/v1alpha1/dataplane_konnect_extension_types.go

View workflow job for this annotation

GitHub Actions / lint

use of `DataplaneKonnectExtensionStatus` forbidden because "Please use camel case 'DataPlane' instead of 'Dataplane'" (forbidigo)
}

// +kubebuilder:object:root=true

// DataPlaneList contains a list of DataPlane
type DataplaneKonnectExtensionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []DataplaneKonnectExtension `json:"items"`

Check failure on line 45 in api/v1alpha1/dataplane_konnect_extension_types.go

View workflow job for this annotation

GitHub Actions / lint

use of `DataplaneKonnectExtension` forbidden because "Please use camel case 'DataPlane' instead of 'Dataplane'" (forbidigo)
}

// DataPlaneSpec defines the desired state of DataPlane
type DataplaneKonnectExtensionSpec struct {
// ControlPlaneID is the identifier of the Konnect Control Plane.
// +kubebuilder:validation:Required
ControlPlaneID string `json:"controlPlaneID"`

// ControlPlaneRegion is the region of the Konnect Control Plane.
// If not set, 'us' is used as the default region.
// +optional
// +kubebuilder:validation:Enum=us;eu
// +kubebuilder:default=us
ControlPlaneRegion *string `json:"controlPlaneRegion,omitempty"`

// ClusterCertificate is a name of the Secret containing the Konnect Control Plane's cluster certificate.
// +kubebuilder:validation:Required
ClusterCertificate string `json:"clusterCertificate"`
}

// DataPlaneStatus defines the observed state of DataPlane
type DataplaneKonnectExtensionStatus struct {
// DataPlaneRefs is the array of DataPlane references this is associated with.
// A new reference is set by the operator when this extension is associated with
// a DataPlane through its extensions spec.
//
// +kube:validation:Optional
DataPlaneRefs []NamespacedRef `json:"dataPlaneRefs,omitempty"`
}
2 changes: 2 additions & 0 deletions api/v1alpha1/extensionref_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package v1alpha1
// defines extended behavior for a resource (e.g. ControlPlane).
type ExtensionRef struct {
// Group is the group of the extension resource.
// +kubebuilder:validation:Optional
// +kubebuilder:default=gateway-operator.konghq.com
Group string `json:"group"`

// Kind is kind of the extension resource.
Expand Down
101 changes: 101 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

11 changes: 11 additions & 0 deletions api/v1beta1/dataplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"github.com/kong/gateway-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -32,6 +33,7 @@ func init() {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=kodp,categories=kong;all
// +kubebuilder:validation:XValidation:message="Extension not allowed for DataPlane",rule="has(self.spec.extensions) ? has(self.spec.extensions) && self.spec.extensions.all(e, e.group == 'gateway-operator.konghq.com' && e.kind == 'DataPlaneKonnectExtension') : true"
// +kubebuilder:printcolumn:name="Ready",description="The Resource is ready",type=string,JSONPath=`.status.conditions[?(@.type=='Ready')].status`

// DataPlane is the Schema for the dataplanes API
Expand Down Expand Up @@ -68,6 +70,15 @@ type DataPlaneOptions struct {

// +optional
Resources DataPlaneResources `json:"resources"`

// Extensions provide additional or replacement features for the DataPlane
// resources to influence or enhance functionality.
// NOTE: since we have one extension only (DataPlaneKonnectExtension), we limit the amount of extensions to 1.
//
// +optional
// +kubebuilder:validation:MinItems=0
// +kubebuilder:validation:MaxItems=1
Extensions []v1alpha1.ExtensionRef `json:"extensions,omitempty"`
}

// DataPlaneResources defines the resources that will be created and managed
Expand Down
20 changes: 16 additions & 4 deletions api/v1beta1/gatewayconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ package v1beta1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/gateway-operator/api/v1alpha1"
)

func init() {
SchemeBuilder.Register(&GatewayConfiguration{}, &GatewayConfigurationList{})
}

//+genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=kogc,categories=kong;all
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=kogc,categories=kong;all
// +kubebuilder:validation:XValidation:message="Extension not allowed for DataPlane config options",rule="has(self.spec.dataPlaneOptions.extensions) ? has(self.spec.dataPlaneOptions.extensions) && self.spec.dataPlaneOptions.extensions.all(e, e.group == 'gateway-operator.konghq.com' && e.kind == 'DataPlaneKonnectExtension') : true"

// GatewayConfiguration is the Schema for the gatewayconfigurations API
type GatewayConfiguration struct {
Expand Down Expand Up @@ -61,6 +64,15 @@ type GatewayConfigDataPlaneOptions struct {

// +optional
Network GatewayConfigDataPlaneNetworkOptions `json:"network"`

// Extensions provide additional or replacement features for the DataPlane
// resources to influence or enhance functionality.
// NOTE: since we have one extension only (DataPlaneKonnectExtension), we limit the amount of extensions to 1.
//
// +optional
// +kubebuilder:validation:MinItems=0
// +kubebuilder:validation:MaxItems=1
Extensions []v1alpha1.ExtensionRef `json:"extensions,omitempty"`
}

// GatewayConfigDataPlaneNetworkOptions defines network related options for a DataPlane.
Expand Down
14 changes: 14 additions & 0 deletions api/v1beta1/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 @@ -8116,6 +8116,7 @@ spec:
defines extended behavior for a resource (e.g. ControlPlane).
properties:
group:
default: gateway-operator.konghq.com
description: Group is the group of the extension resource.
type: string
kind:
Expand All @@ -8138,7 +8139,6 @@ spec:
This field MUST not be set when referring to cluster-scoped resources.
type: string
required:
- group
- kind
- name
type: object
Expand Down
Loading

0 comments on commit b09db39

Please sign in to comment.