Skip to content

Commit f189f2d

Browse files
authored
feat(konnect): add support for konghq.com/plugins annotation on KongConsumerGroups (#684)
1 parent 4ecf237 commit f189f2d

8 files changed

+977
-63
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
- `KongService` [#550](https://github.com/Kong/gateway-operator/pull/550)
8484
- `KongRoute` [#644](https://github.com/Kong/gateway-operator/pull/644)
8585
- `KongConsumer` [#676](https://github.com/Kong/gateway-operator/pull/676)
86+
- `KongConsumerGroup` [#684](https://github.com/Kong/gateway-operator/pull/684)
8687
These `KongPluginBinding`s are taken by the `KongPluginBinding` reconciler
8788
to create the corresponding plugin objects in Konnect.
8889
- `KongConsumer` associated with `ConsumerGroups` is now reconciled in Konnect by removing/adding
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
kind: KonnectAPIAuthConfiguration
2+
apiVersion: konnect.konghq.com/v1alpha1
3+
metadata:
4+
name: demo-auth
5+
namespace: default
6+
spec:
7+
type: token
8+
token: kpat_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9+
serverURL: eu.api.konghq.tech
10+
---
11+
kind: KonnectGatewayControlPlane
12+
apiVersion: konnect.konghq.com/v1alpha1
13+
metadata:
14+
name: demo-cp
15+
namespace: default
16+
spec:
17+
name: demo-cp
18+
labels:
19+
app: demo-cp
20+
key1: demo-cp
21+
konnect:
22+
authRef:
23+
name: demo-auth
24+
# namespace not required if APIAuthConfiguration is in the same namespace
25+
---
26+
# This KongPlugin is bound to both the KongService, KongRoute and KongConsumerGroup
27+
# hence it will create 2 KongPluginBinding with the following targets:
28+
# - KongService and KongConsumerGroup
29+
# - KongRoute and KongConsumerGroup
30+
apiVersion: configuration.konghq.com/v1
31+
kind: KongPlugin
32+
metadata:
33+
name: rate-limit-5-min
34+
namespace: default
35+
config:
36+
minute: 5
37+
policy: local
38+
plugin: rate-limiting
39+
---
40+
kind: KongService
41+
apiVersion: configuration.konghq.com/v1alpha1
42+
metadata:
43+
name: service-1
44+
namespace: default
45+
annotations:
46+
konghq.com/plugins: rate-limit-5-min
47+
spec:
48+
name: service-1
49+
host: example.com
50+
controlPlaneRef:
51+
type: konnectNamespacedRef
52+
konnectNamespacedRef:
53+
name: demo-cp
54+
---
55+
kind: KongRoute
56+
apiVersion: configuration.konghq.com/v1alpha1
57+
metadata:
58+
name: route-1
59+
namespace: default
60+
annotations:
61+
konghq.com/plugins: rate-limit-5-min
62+
spec:
63+
name: route-1
64+
protocols:
65+
- http
66+
hosts:
67+
- example.com
68+
serviceRef:
69+
type: namespacedRef
70+
namespacedRef:
71+
name: service-1
72+
---
73+
kind: KongConsumerGroup
74+
apiVersion: configuration.konghq.com/v1beta1
75+
metadata:
76+
name: consumer-group-1
77+
namespace: default
78+
annotations:
79+
konghq.com/plugins: rate-limit-5-min
80+
spec:
81+
name: consumer-group-1
82+
controlPlaneRef:
83+
type: konnectNamespacedRef
84+
konnectNamespacedRef:
85+
name: test1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package konnect
2+
3+
import (
4+
"sigs.k8s.io/controller-runtime/pkg/client"
5+
6+
"github.com/kong/gateway-operator/pkg/annotations"
7+
8+
configurationv1beta1 "github.com/kong/kubernetes-configuration/api/configuration/v1beta1"
9+
)
10+
11+
const (
12+
// IndexFieldKongConsumerGroupOnPlugin is the index field for KongConsumerGroup -> KongPlugin.
13+
IndexFieldKongConsumerGroupOnPlugin = "consumerGroupPluginRef"
14+
)
15+
16+
// IndexOptionsForKongConsumerGroup returns required Index options for KongConsumerGroup reconciler.
17+
func IndexOptionsForKongConsumerGroup() []ReconciliationIndexOption {
18+
return []ReconciliationIndexOption{
19+
{
20+
IndexObject: &configurationv1beta1.KongConsumerGroup{},
21+
IndexField: IndexFieldKongConsumerGroupOnPlugin,
22+
ExtractValue: kongConsumerGroupReferencesKongPluginsViaAnnotation,
23+
},
24+
}
25+
}
26+
27+
func kongConsumerGroupReferencesKongPluginsViaAnnotation(object client.Object) []string {
28+
consumerGroup, ok := object.(*configurationv1beta1.KongConsumerGroup)
29+
if !ok {
30+
return nil
31+
}
32+
return annotations.ExtractPluginsWithNamespaces(consumerGroup)
33+
}

0 commit comments

Comments
 (0)