Skip to content

Commit

Permalink
fix: support ConsumerGroups in KongRawStateToKongState (#5438)
Browse files Browse the repository at this point in the history
  • Loading branch information
programmer04 authored Jan 15, 2024
1 parent 253bd93 commit b8b543c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,11 @@ Adding a new version? You'll need three changes:
[#5303](https://github.com/Kong/kubernetes-ingress-controller/pull/5303)
- Allow the `ws` and `wss` Enterprise protocol values for protocol annotations.
[#5399](https://github.com/Kong/kubernetes-ingress-controller/pull/5399)
- Add a `workspace` paramater in filling IDs of Kong entities to avoid
- Add a `workspace` parameter in filling IDs of Kong entities to avoid
duplicate IDs cross different workspaces.
[#5401](https://github.com/Kong/kubernetes-ingress-controller/pull/5401)
[#5401](https://github.com/Kong/kubernetes-ingress-controller/pull/5401)
- Support properly ConsumerGroups when fallback to the last valid configuration.
[#5438](https://github.com/Kong/kubernetes-ingress-controller/pull/5438)

### Changed

Expand Down
10 changes: 10 additions & 0 deletions internal/dataplane/configfetcher/kongrawstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func KongRawStateToKongState(rawstate *utils.KongRawState) *kongstate.KongState
}
}

for _, cg := range rawstate.ConsumerGroups {
kongState.ConsumerGroups = append(kongState.ConsumerGroups, kongstate.ConsumerGroup{ConsumerGroup: sanitizeConsumerGroup(*cg.ConsumerGroup)})
}

targets := make(map[string][]*kong.Target)
for _, u := range rawstate.Targets {
if u.Upstream != nil && u.Upstream.ID != nil {
Expand Down Expand Up @@ -273,6 +277,12 @@ func sanitizeConsumer(consumer kong.Consumer) kong.Consumer {
return consumer
}

func sanitizeConsumerGroup(consumerGroup kong.ConsumerGroup) kong.ConsumerGroup {
consumerGroup.ID = nil
consumerGroup.CreatedAt = nil
return consumerGroup
}

type authT interface {
*kong.KeyAuth |
*kong.HMACAuth |
Expand Down
16 changes: 15 additions & 1 deletion internal/dataplane/configfetcher/kongrawstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ func TestKongRawStateToKongState(t *testing.T) {
CustomID: kong.String("customID"),
},
},
ConsumerGroups: []*kong.ConsumerGroupObject{
{
ConsumerGroup: &kong.ConsumerGroup{
ID: kong.String("consumerGroup"),
Name: kong.String("consumerGroup"),
},
},
},
KeyAuths: []*kong.KeyAuth{
{
ID: kong.String("keyAuth"),
Expand Down Expand Up @@ -209,6 +217,13 @@ func TestKongRawStateToKongState(t *testing.T) {
Cert: kong.String("cert"),
},
},
ConsumerGroups: []kongstate.ConsumerGroup{
{
ConsumerGroup: kong.ConsumerGroup{
Name: kong.String("consumerGroup"),
},
},
},
Consumers: []kongstate.Consumer{
{
Consumer: kong.Consumer{
Expand Down Expand Up @@ -315,7 +330,6 @@ func ensureAllKongRawStateFieldsAreTested(t *testing.T, testedFields []string) {
kongRawStateFieldsKICDoesntSupport := []string{
// These are fields that KIC explicitly doesn't support.
"SNIs",
"ConsumerGroups",
"CustomEntities",
"Vaults",
"RBACRoles",
Expand Down

0 comments on commit b8b543c

Please sign in to comment.