Skip to content

Commit e3ca28f

Browse files
pmalekfgiudici
andauthored
feat: add support for cross namespace references from KongRoute to KongService (#3125)
Co-authored-by: Francesco Giudici <fgiudici@foggy.day>
1 parent e4020e8 commit e3ca28f

39 files changed

+750
-147
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,13 @@
5252
- Support cross namespace references from `KongPluginBinding` to `KongPlugin`.
5353
For this reference to be allowed, a `KongReferenceGrant` resource must be created
5454
in the namespace of the `KongPlugin`, allowing access for the `KongPluginBinding`.
55-
[#31038](https://github.com/Kong/kong-operator/pull/3108)
55+
[#3108](https://github.com/Kong/kong-operator/pull/3108)
5656
- HybridGateway: Added support to PathPrefixMatch for the `RequestRedirect` `HTTPRoute` filter.
5757
[#3065](https://github.com/Kong/kong-operator/pull/3065)
58+
- Support cross namespace references from `KongRoute` to `KongService`.
59+
For this reference to be allowed, a `KongReferenceGrant` resource must be created
60+
in the namespace of the `KongService`, allowing access for the `KongRoute`.
61+
[#3125](https://github.com/Kong/kong-operator/pull/3125)
5862

5963
### Fixes
6064

api/configuration/v1alpha1/kongreferencegrant_types.go

Lines changed: 2 additions & 2 deletions
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', 'KongPluginBinding']",message="Only KongConsumer, KongConsumerGroup, KongCertificate, KongCACertificate, KongDataPlaneClientCertificate, KongService, KongUpstream, KongKey, KongKeySet, KongVault and KongPluginBinding kinds are supported for 'configuration.konghq.com' group"
94+
// +kubebuilder:validation:XValidation:rule="self.group != 'configuration.konghq.com' || self.kind in [ 'KongConsumer', 'KongConsumerGroup', 'KongRoute', 'KongService', 'KongCertificate', 'KongCACertificate', 'KongDataPlaneClientCertificate', 'KongUpstream', 'KongKey', 'KongKeySet', 'KongVault', 'KongPluginBinding']",message="Only KongConsumer, KongConsumerGroup, KongRoute, 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,7 +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"
120+
// +kubebuilder:validation:XValidation:rule=".self.group != 'configuration.konghq.com' || .self.kind in ['KongPlugin', 'KongService']",message="Only 'KongPlugin' and 'KongService' kinds are supported for 'configuration.konghq.com' group"
121121
type ReferenceGrantTo struct {
122122
// Group is the group of the referent.
123123
//

api/configuration/v1alpha1/service_ref.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,12 @@ type ServiceRef struct {
1919
Type string `json:"type,omitempty"`
2020

2121
// NamespacedRef is a reference to a KongService.
22-
NamespacedRef *commonv1alpha1.NameRef `json:"namespacedRef,omitempty"`
22+
// If namespace is not specified, the KongService in the same namespace
23+
// as the referencing entity.
24+
// Namespace can be specified to reference a KongService in a different namespace
25+
// but this requires a KongReferenceGrant in the target namespace allowing
26+
// the reference.
27+
//
28+
// +optional
29+
NamespacedRef *commonv1alpha1.NamespacedRef `json:"namespacedRef,omitempty"`
2330
}

api/configuration/v1alpha1/zz_generated.deepcopy.go

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

api/test/unit/konnect_funcs_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ func TestServiceRef(t *testing.T) {
304304

305305
serviceRef := &configurationv1alpha1.ServiceRef{
306306
Type: configurationv1alpha1.ServiceRefNamespacedRef,
307-
NamespacedRef: &commonv1alpha1.NameRef{
307+
NamespacedRef: &commonv1alpha1.NamespacedRef{
308308
Name: "test-service",
309309
},
310310
}

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

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54255,14 +54255,14 @@ spec:
5425554255
- namespace
5425654256
type: object
5425754257
x-kubernetes-validations:
54258-
- message: Only KongConsumer, KongConsumerGroup, KongCertificate,
54258+
- message: Only KongConsumer, KongConsumerGroup, KongRoute, KongCertificate,
5425954259
KongCACertificate, KongDataPlaneClientCertificate, KongService,
5426054260
KongUpstream, KongKey, KongKeySet, KongVault and KongPluginBinding
5426154261
kinds are supported for 'configuration.konghq.com' group
5426254262
rule: self.group != 'configuration.konghq.com' || self.kind in
54263-
[ 'KongConsumer', 'KongConsumerGroup', 'KongService', 'KongCertificate',
54264-
'KongCACertificate', 'KongDataPlaneClientCertificate', 'KongUpstream',
54265-
'KongKey', 'KongKeySet', 'KongVault', 'KongPluginBinding']
54263+
[ 'KongConsumer', 'KongConsumerGroup', 'KongRoute', 'KongService',
54264+
'KongCertificate', 'KongCACertificate', 'KongDataPlaneClientCertificate',
54265+
'KongUpstream', 'KongKey', 'KongKeySet', 'KongVault', 'KongPluginBinding']
5426654266
- message: namespace must be empty for KongVault and non-empty for
5426754267
other kinds
5426854268
rule: 'self.kind == ''KongVault'' ? self.__namespace__ == "" :
@@ -54315,10 +54315,10 @@ spec:
5431554315
kinds are supported for 'konnect.konghq.com' group
5431654316
rule: .self.group != 'konnect.konghq.com' || .self.kind in ['KonnectGatewayControlPlane',
5431754317
'KonnectAPIAuthConfiguration']
54318-
- message: Only 'KongPlugin' kind is supported for 'configuration.konghq.com'
54319-
group
54318+
- message: Only 'KongPlugin' and 'KongService' kinds are supported
54319+
for 'configuration.konghq.com' group
5432054320
rule: .self.group != 'configuration.konghq.com' || .self.kind
54321-
in ['KongPlugin']
54321+
in ['KongPlugin', 'KongService']
5432254322
maxItems: 16
5432354323
minItems: 1
5432454324
type: array
@@ -54611,13 +54611,29 @@ spec:
5461154611
specify a ServiceRef and be associated with a Service.
5461254612
properties:
5461354613
namespacedRef:
54614-
description: NamespacedRef is a reference to a KongService.
54614+
description: |-
54615+
NamespacedRef is a reference to a KongService.
54616+
If namespace is not specified, the KongService in the same namespace
54617+
as the referencing entity.
54618+
Namespace can be specified to reference a KongService in a different namespace
54619+
but this requires a KongReferenceGrant in the target namespace allowing
54620+
the reference.
5461554621
properties:
5461654622
name:
54617-
description: Name is the name of the entity.
54623+
description: Name is the name of the referred resource.
5461854624
maxLength: 253
5461954625
minLength: 1
5462054626
type: string
54627+
namespace:
54628+
description: |-
54629+
Namespace is the namespace of the referred resource.
54630+
54631+
For namespace-scoped resources if no Namespace is provided then the
54632+
namespace of the parent object MUST be used.
54633+
54634+
This field MUST not be set when referring to cluster-scoped resources.
54635+
maxLength: 253
54636+
type: string
5462154637
required:
5462254638
- name
5462354639
type: object

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

Lines changed: 22 additions & 6 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: 22 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)