Skip to content

Commit

Permalink
feat: Consumer Groups can be configured in Consumer (#4419)
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 committed Jul 28, 2023
1 parent c768c7d commit a6e5a0d
Show file tree
Hide file tree
Showing 19 changed files with 225 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Adding a new version? You'll need three changes:
### Added

- **WIP** Introduce `KongConsumerGroup` CRD (supported by Kong Enterprise only)
[#4325](https://github.com/Kong/kubernetes-ingress-controller/pull/4325), [#4387](https://github.com/Kong/kubernetes-ingress-controller/pull/4387)
[#4325](https://github.com/Kong/kubernetes-ingress-controller/pull/4325), [#4387](https://github.com/Kong/kubernetes-ingress-controller/pull/4387), [#4419](https://github.com/Kong/kubernetes-ingress-controller/pull/4419)
- The ResponseHeaderModifier Gateway API filter is now supported and translated
to the proper set of Kong plugins.
[#4350](https://github.com/Kong/kubernetes-ingress-controller/pull/4350)
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/configuration.konghq.com_kongconsumers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ spec:
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
consumerGroups:
description: ConsumerGroups are references to consumer groups (that consumer
wants to be part of) provisioned in Kong.
items:
type: string
type: array
credentials:
description: Credentials are references to secrets containing a credential
to be provisioned in Kong.
Expand Down
6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-enterprise.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-k4k8s-enterprise.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-konnect-enterprise.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-konnect.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless-legacy.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-dbless.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-postgres-enterprise.yaml

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

6 changes: 6 additions & 0 deletions deploy/single/all-in-one-postgres.yaml

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

1 change: 1 addition & 0 deletions docs/api-reference.md

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

5 changes: 5 additions & 0 deletions internal/dataplane/deckgen/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func ToDeckContent(
continue
}

for _, cg := range c.ConsumerGroups {
cg := cg
consumer.Groups = append(consumer.Groups, &cg)
}

for _, p := range c.Plugins {
consumer.Plugins = append(consumer.Plugins, &file.FPlugin{Plugin: p})
}
Expand Down
4 changes: 3 additions & 1 deletion internal/dataplane/kongstate/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import (
// Consumer holds a Kong consumer and its plugins and credentials.
type Consumer struct {
kong.Consumer
Plugins []kong.Plugin
Plugins []kong.Plugin
ConsumerGroups []kong.ConsumerGroup

KeyAuths []*KeyAuth
HMACAuths []*HMACAuth
JWTAuths []*JWTAuth
Expand Down
12 changes: 12 additions & 0 deletions internal/dataplane/kongstate/kongstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ func (ks *KongState) FillConsumersAndCredentials(
c.K8sKongConsumer = *consumer
c.Tags = util.GenerateTagsForObject(consumer)

// Get consumer groups
for _, cgName := range consumer.ConsumerGroups {
cg, err := s.GetKongConsumerGroup(consumer.Namespace, cgName)
if err != nil {
failuresCollector.PushResourceFailure(fmt.Sprintf("nonexistent consumer group: %q", err), consumer)
continue
}
c.ConsumerGroups = append(c.ConsumerGroups, kong.ConsumerGroup{
Name: &cg.Name,
})
}

for _, cred := range consumer.Credentials {
pushCredentialResourceFailures := func(message string) {
failuresCollector.PushResourceFailure(fmt.Sprintf("credential %q failure: %s", cred, message), consumer)
Expand Down

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: configuration.konghq.com/v1beta1
kind: KongConsumerGroup
metadata:
name: consumer-group-2
annotations:
kubernetes.io/ingress.class: kong
---
apiVersion: configuration.konghq.com/v1beta1
kind: KongConsumerGroup
metadata:
name: consumer-group-1
annotations:
kubernetes.io/ingress.class: kong
---
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: consumer-1
annotations:
kubernetes.io/ingress.class: kong
username: consumer-1
consumerGroups:
- consumer-group-1
---
apiVersion: configuration.konghq.com/v1
kind: KongConsumer
metadata:
name: consumer-2
annotations:
kubernetes.io/ingress.class: kong
username: consumer-2
consumerGroups:
- consumer-group-1
- consumer-group-2
3 changes: 3 additions & 0 deletions pkg/apis/configuration/v1/kongconsumer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type KongConsumer struct {
// Credentials are references to secrets containing a credential to be
// provisioned in Kong.
Credentials []string `json:"credentials,omitempty"`
// ConsumerGroups are references to consumer groups (that consumer wants to be part of)
// provisioned in Kong.
ConsumerGroups []string `json:"consumerGroups,omitempty"`

// Status represents the current status of the KongConsumer resource.
Status KongConsumerStatus `json:"status,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/configuration/v1/zz_generated.deepcopy.go

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

0 comments on commit a6e5a0d

Please sign in to comment.