Skip to content

Commit

Permalink
feat(konnect): add KongVault reconciler (#597)
Browse files Browse the repository at this point in the history
* add KongVault reconciler

* add unit tests for KongVault

* add integration test

* fix owner reference and add envtest

* address comments

* add watch for apiAuthConfiguration and controlPlane in KongVault reconciler

* add comments on cpref namespace
  • Loading branch information
randmonkey authored Sep 25, 2024
1 parent 7583a25 commit 23b649b
Show file tree
Hide file tree
Showing 20 changed files with 1,374 additions and 7 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ packages:
PluginSDK:
UpstreamsSDK:
TargetsSDK:
VaultSDK:
MeSDK:
KongCredentialBasicAuthSDK:
CACertificatesSDK:
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
[#513](https://github.com/Kong/gateway-operator/pull/513), [#535](https://github.com/Kong/gateway-operator/pull/535)
- Add `KongTarget` reconciler for Konnect Targets.
[#627](https://github.com/Kong/gateway-operator/pull/627)
- Add `KongVault` reconciler for Konnect Vaults.
[#597](https://github.com/Kong/gateway-operator/pull/597)
- The `DataPlaneKonnectExtension` CRD has been introduced. Such a CRD can be attached
to a `DataPlane` via the extensions field to have a konnect-flavored `DataPlane`.
[#453](https://github.com/Kong/gateway-operator/pull/453), [#578](https://github.com/Kong/gateway-operator/pull/578)
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/role/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ rules:
- kongingresses
- konglicenses
- kongupstreampolicies
- kongvaults
- tcpingresses
- udpingresses
verbs:
Expand Down Expand Up @@ -185,6 +184,7 @@ rules:
- kongservices
- kongtargets
- kongupstreams
- kongvaults
verbs:
- get
- list
Expand Down
39 changes: 39 additions & 0 deletions config/samples/konnect_kongvault.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
kind: KonnectAPIAuthConfiguration
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: konnect-api-auth-dev-1
namespace: default
spec:
type: token
token: kpat_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
serverURL: us.api.konghq.com
---
kind: KonnectGatewayControlPlane
apiVersion: konnect.konghq.com/v1alpha1
metadata:
name: test1
namespace: default
spec:
name: test1
labels:
app: test1
key1: test1
konnect:
authRef:
name: konnect-api-auth-dev-1
---
kind: KongVault
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: env-vault-1
spec:
backend: env
prefix: env-vault
config:
prefix: "konnect_vault_test_"
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: test1
# KongVault is cluster scoped currently, so we need to specify namespace of Konnect control plane.
namespace: default
4 changes: 2 additions & 2 deletions controller/konnect/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type SupportedKonnectEntityType interface {
configurationv1alpha1.KongCredentialBasicAuth |
configurationv1alpha1.KongUpstream |
configurationv1alpha1.KongCACertificate |
configurationv1alpha1.KongTarget

configurationv1alpha1.KongTarget |
configurationv1alpha1.KongVault
// TODO: add other types

GetTypeName() string
Expand Down
15 changes: 15 additions & 0 deletions controller/konnect/ops/kongvault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ops

import (
"context"

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

// VaultSDK is the interface for Konnect Vault SDK.
type VaultSDK interface {
CreateVault(ctx context.Context, controlPlaneID string, vault sdkkonnectcomp.VaultInput, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateVaultResponse, error)
UpsertVault(ctx context.Context, request sdkkonnectops.UpsertVaultRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertVaultResponse, error)
DeleteVault(ctx context.Context, controlPlaneID string, vaultID string, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteVaultResponse, error)
}
264 changes: 264 additions & 0 deletions controller/konnect/ops/kongvault_mock.go

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

6 changes: 6 additions & 0 deletions controller/konnect/ops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func Create[
return e, createCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongTarget:
return e, createTarget(ctx, sdk.GetTargetsSDK(), ent)
case *configurationv1alpha1.KongVault:
return e, createVault(ctx, sdk.GetVaultSDK(), ent)

// ---------------------------------------------------------------------
// TODO: add other Konnect types
Expand Down Expand Up @@ -118,6 +120,8 @@ func Delete[
return deleteCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongTarget:
return deleteTarget(ctx, sdk.GetTargetsSDK(), ent)
case *configurationv1alpha1.KongVault:
return deleteVault(ctx, sdk.GetVaultSDK(), ent)

// ---------------------------------------------------------------------
// TODO: add other Konnect types
Expand Down Expand Up @@ -209,6 +213,8 @@ func Update[
return ctrl.Result{}, updateCACertificate(ctx, sdk.GetCACertificatesSDK(), ent)
case *configurationv1alpha1.KongTarget:
return ctrl.Result{}, updateTarget(ctx, sdk.GetTargetsSDK(), ent)
case *configurationv1alpha1.KongVault:
return ctrl.Result{}, updateVault(ctx, sdk.GetVaultSDK(), ent)

// ---------------------------------------------------------------------
// TODO: add other Konnect types
Expand Down
Loading

0 comments on commit 23b649b

Please sign in to comment.