Skip to content

Commit

Permalink
feat(konnect): allow setting ControlPlane group members
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalek committed Oct 4, 2024
1 parent 0d9d721 commit fb43522
Show file tree
Hide file tree
Showing 18 changed files with 819 additions and 93 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ packages:
github.com/kong/gateway-operator/controller/konnect/ops:
interfaces:
ControlPlaneSDK:
ControlPlaneGroupSDK:
ServicesSDK:
RoutesSDK:
ConsumersSDK:
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
- HMAC Auth [#687](https://github.com/Kong/gateway-operator/pull/687)
- Add support for `KongRoute`s bound directly to `KonnectGatewayControlPlane`s (serviceless rotues).
[#669](https://github.com/Kong/gateway-operator/pull/669)
- Allow setting `KonnectGatewayControlPlane`s group membership
[#697](https://github.com/Kong/gateway-operator/pull/697)

### Fixed

Expand Down
61 changes: 61 additions & 0 deletions config/samples/konnect_gatewaycontrolplane_group_assignment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
kind: KonnectAPIAuthConfiguration
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: konnect-api-auth-dev-1
namespace: default
spec:
type: token
token: kpat_XXXXXXXXXXXXXXXXXXX
serverURL: us.api.konghq.tech
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: test1
namespace: default
spec:
name: test1
konnect:
authRef:
name: konnect-api-auth-dev-1
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: test2
namespace: default
spec:
name: test2
konnect:
authRef:
name: konnect-api-auth-dev-1
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: test3
namespace: default
spec:
name: test3
konnect:
authRef:
name: konnect-api-auth-dev-1
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: group1
namespace: default
spec:
name: group1
cluster_type: CLUSTER_TYPE_CONTROL_PLANE_GROUP
members:
- name: test1
- name: test2
- name: test3
labels:
app: group1
key1: group1
konnect:
authRef:
name: konnect-api-auth-dev-1
5 changes: 5 additions & 0 deletions controller/konnect/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ const (
// KonnectEntityProgrammedReasonFailedToReconcileConsumerGroupsWithKonnect is the reason for the Programmed condition.
// It is set when one or more KongConsumerGroup references could not be reconciled with Konnect.
KonnectEntityProgrammedReasonFailedToReconcileConsumerGroupsWithKonnect = "FailedToReconcileConsumerGroupsWithKonnect"

// KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers
// is the reason for the Programmed condition. It is set when the control plane
// group members could not be set.
KonnectGatewayControlPlaneProgrammedReasonFailedToSetControlPlaneGroupMembers = "FailedToSetControlPlaneGroupMembers"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion controller/konnect/ops/controlplane.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations"
)

// ControlPlaneSDK is the interface for the Konnect ControlPlaneSDK SDK.
// ControlPlaneSDK is the interface for the Konnect ControlPlane SDK.
type ControlPlaneSDK interface {
CreateControlPlane(ctx context.Context, req sdkkonnectcomp.CreateControlPlaneRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateControlPlaneResponse, error)
DeleteControlPlane(ctx context.Context, id string, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteControlPlaneResponse, error)
Expand Down
13 changes: 13 additions & 0 deletions controller/konnect/ops/controlplanegroup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ops

import (
"context"

sdkkonnectcomp "github.com/Kong/sdk-konnect-go/models/components"
sdkkonnectops "github.com/Kong/sdk-konnect-go/models/operations"
)

// ControlPlaneGroupSDK is the interface for the Konnect ControlPlaneGroupSDK SDK.
type ControlPlaneGroupSDK interface {
PutControlPlanesIDGroupMemberships(ctx context.Context, id string, groupMembership *sdkkonnectcomp.GroupMembership, opts ...sdkkonnectops.Option) (*sdkkonnectops.PutControlPlanesIDGroupMembershipsResponse, error)
}
115 changes: 115 additions & 0 deletions controller/konnect/ops/controlplanegroup_mock.go

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

4 changes: 2 additions & 2 deletions controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Create[

switch ent := any(e).(type) {
case *konnectv1alpha1.KonnectGatewayControlPlane:
return e, createControlPlane(ctx, sdk.GetControlPlaneSDK(), ent)
return e, createControlPlane(ctx, sdk.GetControlPlaneSDK(), sdk.GetControlPlaneGroupSDK(), cl, ent)
case *configurationv1alpha1.KongService:
return e, createService(ctx, sdk.GetServicesSDK(), ent)
case *configurationv1alpha1.KongRoute:
Expand Down Expand Up @@ -226,7 +226,7 @@ func Update[

switch ent := any(e).(type) {
case *konnectv1alpha1.KonnectGatewayControlPlane:
return ctrl.Result{}, updateControlPlane(ctx, sdk.GetControlPlaneSDK(), ent)
return ctrl.Result{}, updateControlPlane(ctx, sdk.GetControlPlaneSDK(), sdk.GetControlPlaneGroupSDK(), cl, ent)
case *configurationv1alpha1.KongService:
return ctrl.Result{}, updateService(ctx, sdk.GetServicesSDK(), ent)
case *configurationv1alpha1.KongRoute:
Expand Down
Loading

0 comments on commit fb43522

Please sign in to comment.