Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(konnect): add KonnectCloudGatewayNetwork CRD #268

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .tools_versions.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# renovate: datasource=github-tags depName=kubernetes/code-generator
kube-code-generator: "0.32.1"
# renovate: datasource=github-releases depName=kubernetes-sigs/controller-tools
controller-tools: "0.17.1"
controller-tools: "0.17.2-0.20250205103018-dac769d27bbe"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to workaround broken aliases support in controller-gen kubernetes-sigs/controller-tools#1136 (which wasn't released yet)

# renovate: datasource=github-releases depName=kubernetes-sigs/kustomize
kustomize: "5.6.0"
# renovate: datasource=github-releases depName=elastic/crd-ref-docs
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Adding a new version? You'll need three changes:
- [v1.0.2](#v102)
- [v1.0.0](#v100)

## Unreleased

## Added

- Added `KonnectCloudGatewayNetwork` CRD.
[#268](https://github.com/Kong/kubernetes-configuration/pull/268)

## [v1.1.0]

[v1.1.0]: https://github.com/Kong/kubernetes-configuration/compare/v1.0.6...v1.1.0
Expand Down
70 changes: 70 additions & 0 deletions api/common/v1alpha1/controlplaneref_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package v1alpha1

const (
// 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 is the type for KIC ControlPlaneRef.
// It is used to reference a KIC as Control Plane.
ControlPlaneRefKIC = "kic"
)

// ControlPlaneRef is the schema for the ControlPlaneRef type.
// It is used to reference a Control Plane entity.
//
// +kubebuilder:object:generate=true
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? has(self.konnectNamespacedRef) : true", message="when type is konnectNamespacedRef, konnectNamespacedRef must be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? !has(self.konnectID) : true", message="when type is konnectNamespacedRef, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? !has(self.konnectNamespacedRef) : true", message="when type is konnectID, konnectNamespacedRef must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectID) : true", message="when type is kic, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectNamespacedRef) : true", message="when type is kic, konnectNamespacedRef must not be set"
// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectID) : true", message="when type is unset, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectNamespacedRef) : true", message="when type is unset, konnectNamespacedRef must not be set"
// +apireference:kgo:include
type ControlPlaneRef struct {
// Type indicates the type of the control plane being referenced. Allowed values:
// - konnectID
// - konnectNamespacedRef
// - kic
//
// The default is kic, which implies that the Control Plane is KIC.
//
// +kubebuilder:validation:Enum=konnectID;konnectNamespacedRef;kic
// +kubebuilder:default:=kic
Type string `json:"type,omitempty"`

// KonnectID is the schema for the KonnectID type.
// This field is required when the Type is konnectID.
// +optional
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.
// This field is required when the Type is konnectNamespacedRef.
// +optional
KonnectNamespacedRef *KonnectNamespacedRef `json:"konnectNamespacedRef,omitempty"`
}

// KonnectNamespacedRef is the schema for the KonnectNamespacedRef type.
//
// +kubebuilder:object:generate=true
// +apireference:kgo:include
type KonnectNamespacedRef struct {
// Name is the name of the Konnect Control Plane.
// +kubebuilder:validation:Required
Name string `json:"name"`

// TODO: Implement cross namespace references:
// https://github.com/Kong/kubernetes-configuration/issues/36

// Namespace is the namespace where the Konnect Control Plane is in.
// Currently only cluster scoped resources (KongVault) are allowed to set `konnectNamespacedRef.namespace`.
//
// +optional
Namespace string `json:"namespace,omitempty"`
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import (
"github.com/samber/lo"
"github.com/stretchr/testify/require"

"github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
commonv1alpha1 "github.com/kong/kubernetes-configuration/api/common/v1alpha1"
)

func TestControlPlaneRefStringer(t *testing.T) {
testCases := []struct {
name string
ref *v1alpha1.ControlPlaneRef
ref *commonv1alpha1.ControlPlaneRef
expected string
}{
{
name: "unknown type - doesn't panic",
ref: &v1alpha1.ControlPlaneRef{
ref: &commonv1alpha1.ControlPlaneRef{
Type: "notSupportedType",
},
expected: "<unknown:notSupportedType>",
Expand All @@ -29,19 +29,19 @@ func TestControlPlaneRefStringer(t *testing.T) {
},
{
name: "konnectNamespacedRef with no namespace",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{
ref: &commonv1alpha1.ControlPlaneRef{
Type: commonv1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &commonv1alpha1.KonnectNamespacedRef{
Name: "foo",
},
},
expected: "<konnectNamespacedRef:foo>",
},
{
name: "konnectNamespacedRef with namespace",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &v1alpha1.KonnectNamespacedRef{
ref: &commonv1alpha1.ControlPlaneRef{
Type: commonv1alpha1.ControlPlaneRefKonnectNamespacedRef,
KonnectNamespacedRef: &commonv1alpha1.KonnectNamespacedRef{
Namespace: "bar",
Name: "foo",
},
Expand All @@ -50,23 +50,23 @@ func TestControlPlaneRefStringer(t *testing.T) {
},
{
name: "konnectID without ID - doesn't panic",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectID,
ref: &commonv1alpha1.ControlPlaneRef{
Type: commonv1alpha1.ControlPlaneRefKonnectID,
},
expected: "<konnectID:nil>",
},
{
name: "konnectID with ID",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKonnectID,
ref: &commonv1alpha1.ControlPlaneRef{
Type: commonv1alpha1.ControlPlaneRefKonnectID,
KonnectID: lo.ToPtr("foo"),
},
expected: "<konnectID:foo>",
},
{
name: "kic",
ref: &v1alpha1.ControlPlaneRef{
Type: v1alpha1.ControlPlaneRefKIC,
ref: &commonv1alpha1.ControlPlaneRef{
Type: commonv1alpha1.ControlPlaneRefKIC,
},
expected: "<kic>",
},
Expand Down
18 changes: 18 additions & 0 deletions api/common/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2025 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.
*/

// +kubebuilder:object:generate=true
package v1alpha1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package v1alpha1

// Tags is a type for a list of tags applied to a Kong entity.
// +kubebuilder:validation:MaxItems=20
Expand Down
63 changes: 63 additions & 0 deletions api/common/v1alpha1/zz_generated.deepcopy.go

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

4 changes: 2 additions & 2 deletions api/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/kubernetes-configuration/api/configuration/common"
commonv1alpha1 "github.com/kong/kubernetes-configuration/api/common/v1alpha1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
konnectv1alpha1 "github.com/kong/kubernetes-configuration/api/konnect/v1alpha1"
)
Expand Down Expand Up @@ -79,7 +79,7 @@ type KongConsumerSpec struct {
ControlPlaneRef *configurationv1alpha1.ControlPlaneRef `json:"controlPlaneRef,omitempty"`

// Tags is an optional set of tags applied to the consumer.
Tags common.Tags `json:"tags,omitempty"`
Tags commonv1alpha1.Tags `json:"tags,omitempty"`
}

// KongConsumerList contains a list of KongConsumer.
Expand Down
3 changes: 2 additions & 1 deletion api/configuration/v1/kongplugin_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ limitations under the License.
package v1

import (
"github.com/kong/go-kong/kong"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/kong/go-kong/kong"
)

// KongPlugin is the Schema for the kongplugins API.
Expand Down
4 changes: 2 additions & 2 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.

69 changes: 14 additions & 55 deletions api/configuration/v1alpha1/controlplaneref_types.go
Original file line number Diff line number Diff line change
@@ -1,66 +1,25 @@
package v1alpha1

import (
commonv1alpha1 "github.com/kong/kubernetes-configuration/api/common/v1alpha1"
)

// ControlPlaneRef is the schema for the ControlPlaneRef type.
// It is used to reference a Control Plane entity.
type ControlPlaneRef = commonv1alpha1.ControlPlaneRef

// KonnectNamespacedRef is the schema for the KonnectNamespacedRef type.
type KonnectNamespacedRef = commonv1alpha1.KonnectNamespacedRef

const (
// 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"
ControlPlaneRefKonnectID = commonv1alpha1.ControlPlaneRefKonnectID
// 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"
ControlPlaneRefKonnectNamespacedRef = commonv1alpha1.ControlPlaneRefKonnectNamespacedRef
// ControlPlaneRefKIC is the type for KIC ControlPlaneRef.
// It is used to reference a KIC as Control Plane.
ControlPlaneRefKIC = "kic"
ControlPlaneRefKIC = commonv1alpha1.ControlPlaneRefKIC
)

// ControlPlaneRef is the schema for the ControlPlaneRef type.
// It is used to reference a Control Plane entity.
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? has(self.konnectNamespacedRef) : true", message="when type is konnectNamespacedRef, konnectNamespacedRef must be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectNamespacedRef') ? !has(self.konnectID) : true", message="when type is konnectNamespacedRef, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? has(self.konnectID) : true", message="when type is konnectID, konnectID must be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'konnectID') ? !has(self.konnectNamespacedRef) : true", message="when type is konnectID, konnectNamespacedRef must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectID) : true", message="when type is kic, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="(has(self.type) && self.type == 'kic') ? !has(self.konnectNamespacedRef) : true", message="when type is kic, konnectNamespacedRef must not be set"
// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectID) : true", message="when type is unset, konnectID must not be set"
// +kubebuilder:validation:XValidation:rule="!has(self.type) ? !has(self.konnectNamespacedRef) : true", message="when type is unset, konnectNamespacedRef must not be set"
// +apireference:kgo:include
type ControlPlaneRef struct {
// Type indicates the type of the control plane being referenced. Allowed values:
// - konnectID
// - konnectNamespacedRef
// - kic
//
// The default is kic, which implies that the Control Plane is KIC.
//
// +kubebuilder:validation:Enum=konnectID;konnectNamespacedRef;kic
// +kubebuilder:default:=kic
Type string `json:"type,omitempty"`

// KonnectID is the schema for the KonnectID type.
// This field is required when the Type is konnectID.
// +optional
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.
// This field is required when the Type is konnectNamespacedRef.
// +optional
KonnectNamespacedRef *KonnectNamespacedRef `json:"konnectNamespacedRef,omitempty"`
}

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

// TODO: Implement cross namespace references:
// https://github.com/Kong/kubernetes-configuration/issues/36

// Namespace is the namespace where the Konnect Control Plane is in.
// Currently only cluster scoped resources (KongVault) are allowed to set `konnectNamespacedRef.namespace`.
//
// +optional
Namespace string `json:"namespace,omitempty"`
}
Loading