-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(konnect): add support for konghq.com/plugins annotation on KongC…
…onsumerGroups (#684)
- Loading branch information
Showing
8 changed files
with
977 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
config/samples/konnect-kongservice-kongroute-kongconsumergroup-plugin-annotated.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
kind: KonnectAPIAuthConfiguration | ||
apiVersion: konnect.konghq.com/v1alpha1 | ||
metadata: | ||
name: demo-auth | ||
namespace: default | ||
spec: | ||
type: token | ||
token: kpat_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX | ||
serverURL: eu.api.konghq.tech | ||
--- | ||
kind: KonnectGatewayControlPlane | ||
apiVersion: konnect.konghq.com/v1alpha1 | ||
metadata: | ||
name: demo-cp | ||
namespace: default | ||
spec: | ||
name: demo-cp | ||
labels: | ||
app: demo-cp | ||
key1: demo-cp | ||
konnect: | ||
authRef: | ||
name: demo-auth | ||
# namespace not required if APIAuthConfiguration is in the same namespace | ||
--- | ||
# This KongPlugin is bound to both the KongService, KongRoute and KongConsumerGroup | ||
# hence it will create 2 KongPluginBinding with the following targets: | ||
# - KongService and KongConsumerGroup | ||
# - KongRoute and KongConsumerGroup | ||
apiVersion: configuration.konghq.com/v1 | ||
kind: KongPlugin | ||
metadata: | ||
name: rate-limit-5-min | ||
namespace: default | ||
config: | ||
minute: 5 | ||
policy: local | ||
plugin: rate-limiting | ||
--- | ||
kind: KongService | ||
apiVersion: configuration.konghq.com/v1alpha1 | ||
metadata: | ||
name: service-1 | ||
namespace: default | ||
annotations: | ||
konghq.com/plugins: rate-limit-5-min | ||
spec: | ||
name: service-1 | ||
host: example.com | ||
controlPlaneRef: | ||
type: konnectNamespacedRef | ||
konnectNamespacedRef: | ||
name: demo-cp | ||
--- | ||
kind: KongRoute | ||
apiVersion: configuration.konghq.com/v1alpha1 | ||
metadata: | ||
name: route-1 | ||
namespace: default | ||
annotations: | ||
konghq.com/plugins: rate-limit-5-min | ||
spec: | ||
name: route-1 | ||
protocols: | ||
- http | ||
hosts: | ||
- example.com | ||
serviceRef: | ||
type: namespacedRef | ||
namespacedRef: | ||
name: service-1 | ||
--- | ||
kind: KongConsumerGroup | ||
apiVersion: configuration.konghq.com/v1beta1 | ||
metadata: | ||
name: consumer-group-1 | ||
namespace: default | ||
annotations: | ||
konghq.com/plugins: rate-limit-5-min | ||
spec: | ||
name: consumer-group-1 | ||
controlPlaneRef: | ||
type: konnectNamespacedRef | ||
konnectNamespacedRef: | ||
name: test1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package konnect | ||
|
||
import ( | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
"github.com/kong/gateway-operator/pkg/annotations" | ||
|
||
configurationv1beta1 "github.com/kong/kubernetes-configuration/api/configuration/v1beta1" | ||
) | ||
|
||
const ( | ||
// IndexFieldKongConsumerGroupOnPlugin is the index field for KongConsumerGroup -> KongPlugin. | ||
IndexFieldKongConsumerGroupOnPlugin = "consumerGroupPluginRef" | ||
) | ||
|
||
// IndexOptionsForKongConsumerGroup returns required Index options for KongConsumerGroup reconciler. | ||
func IndexOptionsForKongConsumerGroup() []ReconciliationIndexOption { | ||
return []ReconciliationIndexOption{ | ||
{ | ||
IndexObject: &configurationv1beta1.KongConsumerGroup{}, | ||
IndexField: IndexFieldKongConsumerGroupOnPlugin, | ||
ExtractValue: kongConsumerGroupReferencesKongPluginsViaAnnotation, | ||
}, | ||
} | ||
} | ||
|
||
func kongConsumerGroupReferencesKongPluginsViaAnnotation(object client.Object) []string { | ||
consumerGroup, ok := object.(*configurationv1beta1.KongConsumerGroup) | ||
if !ok { | ||
return nil | ||
} | ||
return annotations.ExtractPluginsWithNamespaces(consumerGroup) | ||
} |
Oops, something went wrong.