Skip to content

Commit fafcd8a

Browse files
authored
feat: support cross namespace references from KongPluginBinding to KongPlugin (#3108)
1 parent 3fdd2de commit fafcd8a

35 files changed

+645
-116
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
[#3039](https://github.com/Kong/kong-operator/pull/3039)
5050
- HybridGateway: Added comprehensive HTTPRoute converter tests to improve translation stability.
5151
[#3111](https://github.com/Kong/kong-operator/pull/3111)
52+
- Support cross namespace references from `KongPluginBinding` to `KongPlugin`.
53+
For this reference to be allowed, a `KongReferenceGrant` resource must be created
54+
in the namespace of the `KongPlugin`, allowing access for the `KongPluginBinding`.
55+
[#31038](https://github.com/Kong/kong-operator/pull/3108)
5256

5357
### Fixes
5458

api/configuration/v1alpha1/kongpluginbinding_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,17 @@ type KongPluginBindingTargets struct {
146146

147147
// PluginRef is a reference to a KongPlugin or KongClusterPlugin resource.
148148
// +apireference:kgo:include
149+
// +kubebuilder:validation:XValidation:rule="self.kind == 'KongPlugin' || !has(self.__namespace__)", message="Namespace can be set only when kind is 'KongPlugin'"
149150
type PluginRef struct {
150-
// TODO(mattia): cross-namespace references are not supported yet.
151-
// https://github.com/Kong/kubernetes-configuration/issues/9
152-
153151
// Name is the name of the KongPlugin or KongClusterPlugin resource.
154152
// +required
155153
Name string `json:"name"`
156154

155+
// Namespace is the namespace of the referenced KongPlugin resource.
156+
// Can only be set when Kind is KongPlugin.
157+
// +optional
158+
Namespace string `json:"namespace,omitempty"`
159+
157160
// Kind can be KongPlugin or KongClusterPlugin. If not set, it is assumed to be KongPlugin.
158161
// +kubebuilder:validation:Enum=KongPlugin;KongClusterPlugin
159162
// +kubebuilder:default:=KongPlugin

api/configuration/v1alpha1/kongreferencegrant_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ type KongReferenceGrantSpec struct {
9191

9292
// ReferenceGrantFrom describes trusted namespaces and kinds.
9393
//
94-
// +kubebuilder:validation:XValidation:rule="self.group != 'configuration.konghq.com' || self.kind in [ 'KongConsumer', 'KongConsumerGroup', 'KongService', 'KongCertificate', 'KongCACertificate', 'KongDataPlaneClientCertificate', 'KongUpstream', 'KongKey', 'KongKeySet', 'KongVault']",message="Only KongConsumer, KongConsumerGroup, KongCertificate, KongCACertificate, KongDataPlaneClientCertificate, KongService, KongUpstream, KongKey, KongKeySet, and KongVault kinds are supported for 'configuration.konghq.com' group"
94+
// +kubebuilder:validation:XValidation:rule="self.group != 'configuration.konghq.com' || self.kind in [ 'KongConsumer', 'KongConsumerGroup', 'KongService', 'KongCertificate', 'KongCACertificate', 'KongDataPlaneClientCertificate', 'KongUpstream', 'KongKey', 'KongKeySet', 'KongVault', 'KongPluginBinding']",message="Only KongConsumer, KongConsumerGroup, KongCertificate, KongCACertificate, KongDataPlaneClientCertificate, KongService, KongUpstream, KongKey, KongKeySet, KongVault and KongPluginBinding kinds are supported for 'configuration.konghq.com' group"
9595
// +kubebuilder:validation:XValidation:rule="self.kind == 'KongVault' ? self.__namespace__ == \"\" : self.__namespace__ != \"\"",message="namespace must be empty for KongVault and non-empty for other kinds"
9696
type ReferenceGrantFrom struct {
9797
// Group is the group of the referent.
@@ -117,6 +117,7 @@ type ReferenceGrantFrom struct {
117117
//
118118
// +kubebuilder:validation:XValidation:rule=".self.group != 'core' || .self.kind == 'Secret'",message="Only 'Secret' kind is supported for 'core' group"
119119
// +kubebuilder:validation:XValidation:rule=".self.group != 'konnect.konghq.com' || .self.kind in ['KonnectGatewayControlPlane', 'KonnectAPIAuthConfiguration']",message="Only 'KonnectGatewayControlPlane' and 'KonnectAPIAuthConfiguration' kinds are supported for 'konnect.konghq.com' group"
120+
// +kubebuilder:validation:XValidation:rule=".self.group != 'configuration.konghq.com' || .self.kind in ['KongPlugin']",message="Only 'KongPlugin' kind is supported for 'configuration.konghq.com' group"
120121
type ReferenceGrantTo struct {
121122
// Group is the group of the referent.
122123
//

charts/kong-operator/charts/ko-crds/templates/ko-crds.yaml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53389,12 +53389,19 @@ spec:
5338953389
description: Name is the name of the KongPlugin or KongClusterPlugin
5339053390
resource.
5339153391
type: string
53392+
namespace:
53393+
description: |-
53394+
Namespace is the namespace of the referenced KongPlugin resource.
53395+
Can only be set when Kind is KongPlugin.
53396+
type: string
5339253397
required:
5339353398
- name
5339453399
type: object
5339553400
x-kubernetes-validations:
5339653401
- message: pluginRef name must be set
5339753402
rule: self.name != ''
53403+
- message: Namespace can be set only when kind is 'KongPlugin'
53404+
rule: self.kind == 'KongPlugin' || !has(self.__namespace__)
5339853405
scope:
5339953406
default: OnlyTargets
5340053407
description: Scope defines the scope of the plugin binding.
@@ -54250,12 +54257,12 @@ spec:
5425054257
x-kubernetes-validations:
5425154258
- message: Only KongConsumer, KongConsumerGroup, KongCertificate,
5425254259
KongCACertificate, KongDataPlaneClientCertificate, KongService,
54253-
KongUpstream, KongKey, KongKeySet, and KongVault kinds are supported
54254-
for 'configuration.konghq.com' group
54260+
KongUpstream, KongKey, KongKeySet, KongVault and KongPluginBinding
54261+
kinds are supported for 'configuration.konghq.com' group
5425554262
rule: self.group != 'configuration.konghq.com' || self.kind in
5425654263
[ 'KongConsumer', 'KongConsumerGroup', 'KongService', 'KongCertificate',
5425754264
'KongCACertificate', 'KongDataPlaneClientCertificate', 'KongUpstream',
54258-
'KongKey', 'KongKeySet', 'KongVault']
54265+
'KongKey', 'KongKeySet', 'KongVault', 'KongPluginBinding']
5425954266
- message: namespace must be empty for KongVault and non-empty for
5426054267
other kinds
5426154268
rule: 'self.kind == ''KongVault'' ? self.__namespace__ == "" :
@@ -54308,6 +54315,10 @@ spec:
5430854315
kinds are supported for 'konnect.konghq.com' group
5430954316
rule: .self.group != 'konnect.konghq.com' || .self.kind in ['KonnectGatewayControlPlane',
5431054317
'KonnectAPIAuthConfiguration']
54318+
- message: Only 'KongPlugin' kind is supported for 'configuration.konghq.com'
54319+
group
54320+
rule: .self.group != 'configuration.konghq.com' || .self.kind
54321+
in ['KongPlugin']
5431154322
maxItems: 16
5431254323
minItems: 1
5431354324
type: array

charts/kong-operator/ci/__snapshots__/affinity-values.snap

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/kong-operator/ci/__snapshots__/controlplane-config-dump.snap

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/kong-operator/ci/__snapshots__/disable-gateway-controller-values.snap

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/kong-operator/ci/__snapshots__/env-and-args-values.snap

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)