Skip to content

Commit

Permalink
feat(crd): add KonnectControlPlane
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Aug 2, 2024
1 parent 3233f9f commit edb32c4
Show file tree
Hide file tree
Showing 18 changed files with 953 additions and 112 deletions.
4 changes: 2 additions & 2 deletions api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ type KongConsumer struct {
Status KongConsumerStatus `json:"status,omitempty"`
}

func (c *KongConsumer) GetKonnectStatus() *configurationv1alpha1.KonnectEntityStatus {
func (c *KongConsumer) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
return &c.Status.Konnect.KonnectEntityStatus
}

Expand Down Expand Up @@ -107,7 +107,7 @@ type KongConsumerList struct {
// KongConsumerStatus represents the current status of the KongConsumer resource.
type KongConsumerStatus struct {
// Konnect contains the Konnect entity status.
Konnect configurationv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"`
Konnect konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"`

// Conditions describe the current conditions of the KongConsumer.
//
Expand Down
6 changes: 4 additions & 2 deletions api/configuration/v1alpha1/kongpluginbinding_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package v1alpha1

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

konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)

// KongPluginBinding is the schema for Plugin Bindings API which defines a Kong Plugin Binding.
Expand All @@ -40,7 +42,7 @@ type KongPluginBinding struct {
Status KongPluginBindingStatus `json:"status,omitempty"`
}

func (c *KongPluginBinding) GetKonnectStatus() *KonnectEntityStatus {
func (c *KongPluginBinding) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
return &c.Status.Konnect.KonnectEntityStatus
}

Expand Down Expand Up @@ -137,7 +139,7 @@ type EntityRef struct {
// KongPluginBindingStatus represents the current status of the KongBinding resource.
type KongPluginBindingStatus struct {
// Konnect contains the Konnect entity status.
Konnect KonnectEntityStatusWithControlPlaneAndServiceRefs `json:"konnect,omitempty"`
Konnect konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs `json:"konnect,omitempty"`

// Conditions describe the status of the Konnect entity.
// +listType=map
Expand Down
4 changes: 2 additions & 2 deletions api/configuration/v1alpha1/kongroute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type KongRoute struct {
Status KongRouteStatus `json:"status,omitempty"`
}

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

Expand Down Expand Up @@ -128,7 +128,7 @@ type KongRouteAPISpec struct {
// KongRouteStatus represents the current status of the Kong Route resource.
type KongRouteStatus struct {
// Konnect contains the Konnect entity status.
Konnect KonnectEntityStatusWithControlPlaneAndServiceRefs `json:"konnect,omitempty"`
Konnect konnectv1alpha1.KonnectEntityStatusWithControlPlaneAndServiceRefs `json:"konnect,omitempty"`

// Conditions describe the status of the Konnect entity.
// +listType=map
Expand Down
4 changes: 2 additions & 2 deletions api/configuration/v1alpha1/kongservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type KongService struct {
Status KongServiceStatus `json:"status,omitempty"`
}

func (c *KongService) GetKonnectStatus() *KonnectEntityStatus {
func (c *KongService) GetKonnectStatus() *konnectv1alpha1.KonnectEntityStatus {
return &c.Status.Konnect.KonnectEntityStatus
}

Expand Down Expand Up @@ -129,7 +129,7 @@ type KongServiceAPISpec struct {
// KongServiceStatus represents the current status of the Kong Service resource.
type KongServiceStatus struct {
// Konnect contains the Konnect entity status.
Konnect KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"`
Konnect konnectv1alpha1.KonnectEntityStatusWithControlPlaneRef `json:"konnect,omitempty"`

// Conditions describe the status of the Konnect entity.
// +listType=map
Expand Down
47 changes: 0 additions & 47 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.

97 changes: 97 additions & 0 deletions api/konnect/v1alpha1/konnect_controlplane_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package v1alpha1

import (
sdkkonnectgocomp "github.com/Kong/sdk-konnect-go/models/components"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&KonnectControlPlane{}, &KonnectControlPlaneList{})
}

// KonnectControlPlane is the Schema for the KonnectControlplanes API.
//
// +genclient
// +kubebuilder:resource:scope=Namespaced
// +kubebuilder:object:root=true
// +kubebuilder:object:generate=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Programmed",description="The Resource is Programmed on Konnect",type=string,JSONPath=`.status.conditions[?(@.type=='Programmed')].status`
// +kubebuilder:printcolumn:name="ID",description="Konnect ID",type=string,JSONPath=`.status.id`
// +kubebuilder:printcolumn:name="OrgID",description="Konnect Organization ID this resource belongs to.",type=string,JSONPath=`.status.organizationID`
// +kubebuilder:validation:XValidation:rule="!has(oldSelf.spec.konnect.authRef) || has(oldSelf.spec.konnect.authRef)", message="Konnect Configuration's API auth ref reference is immutable"
type KonnectControlPlane struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec KonnectControlPlaneSpec `json:"spec,omitempty"`

Status KonnectControlPlaneStatus `json:"status,omitempty"`
}

// KonnectControlPlaneSpec defines the desired state of KonnectControlPlane.
type KonnectControlPlaneSpec struct {
sdkkonnectgocomp.CreateControlPlaneRequest `json:",inline"`

KonnectConfiguration KonnectConfiguration `json:"konnect,omitempty"`
}

// KonnectControlPlaneStatus defines the observed state of KonnectControlPlane.
type KonnectControlPlaneStatus struct {
KonnectEntityStatus `json:",inline"`

// Conditions describe the current conditions of the KonnectControlPlane.
//
// Known condition types are:
//
// * "Programmed"
//
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:default={{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// GetKonnectStatus returns the Konnect Status of the KonnectControlPlane.
func (c *KonnectControlPlane) GetKonnectStatus() *KonnectEntityStatus {
return &c.Status.KonnectEntityStatus
}

// GetTypeName returns the KonnectControlPlane type name.
func (c KonnectControlPlane) GetTypeName() string {
return "KonnectControlPlane"
}

// GetKonnectLabels gets the Konnect Labels from object's spec.
func (c *KonnectControlPlane) GetKonnectLabels() map[string]string {
return c.Spec.Labels
}

// SetKonnectLabels sets the Konnect Labels in object's spec.
func (c *KonnectControlPlane) SetKonnectLabels(labels map[string]string) {
c.Spec.Labels = labels
}

// GetKonnectAPIAuthConfigurationRef returns the Konnect API Auth Configuration Ref.
func (c *KonnectControlPlane) GetKonnectAPIAuthConfigurationRef() KonnectAPIAuthConfigurationRef {
return c.Spec.KonnectConfiguration.APIAuthConfigurationRef
}

// GetConditions returns the Status Conditions
func (c *KonnectControlPlane) GetConditions() []metav1.Condition {
return c.Status.Conditions
}

// SetConditions sets the Status Conditions
func (c *KonnectControlPlane) SetConditions(conditions []metav1.Condition) {
c.Status.Conditions = conditions
}

// +kubebuilder:object:root=true
type KonnectControlPlaneList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Items []KonnectControlPlane `json:"items"`
}
146 changes: 146 additions & 0 deletions api/konnect/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit edb32c4

Please sign in to comment.