Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(konnect): KongTarget reconciler #627

Merged
merged 4 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ packages:
ConsumerGroupSDK:
PluginSDK:
UpstreamsSDK:
TargetsSDK:
MeSDK:
KongCredentialBasicAuthSDK:
CACertificatesSDK:
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
[#516](https://github.com/Kong/gateway-operator/pull/516)
- Add `KongPluginBinding` reconciler for Konnect Plugins.
[#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)
- 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: 2 additions & 0 deletions config/rbac/role/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ rules:
- kongplugins/status
- kongroutes/status
- kongservices/status
- kongtargets/status
- kongupstreampolicies/status
- kongupstreams/status
- kongvaults/status
Expand Down Expand Up @@ -182,6 +183,7 @@ rules:
resources:
- kongroutes
- kongservices
- kongtargets
- kongupstreams
verbs:
- get
Expand Down
46 changes: 46 additions & 0 deletions config/samples/konnect_kongtarget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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: KongUpstream
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: upstream-1
namespace: default
spec:
name: upstream-1
controlPlaneRef:
type: konnectNamespacedRef
konnectNamespacedRef:
name: test1
---
kind: KongTarget
apiVersion: configuration.konghq.com/v1alpha1
metadata:
name: target-1
namespace: default
spec:
upstreamRef:
name: upstream-1
target: "10.0.0.1"
weight: 100
14 changes: 14 additions & 0 deletions controller/konnect/conditions/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,17 @@ const (
// condition type indicating that one or more KongConsumerGroup references are invalid.
KongConsumerGroupRefsReasonInvalid = "Invalid"
)

const (
// KongUpstreamRefValidConditionType is the type of the condition that indicates
// whether the KongUpstream reference is valid and points to an existing
// KongUpstreamRefValid.
KongUpstreamRefValidConditionType = "KongUpstreamRefValid"

// KongUpstreamRefReasonValid is the reason used with the KongUpstreamRefValid
// condition type indicating that the KongUpstream reference is valid.
KongUpstreamRefReasonValid = "Valid"
// KongUpstreamRefReasonInvalid is the reason used with the KongUpstreamRefValid
// condition type indicating that the KongUpstream reference is invalid.
KongUpstreamRefReasonInvalid = "Invalid"
)
4 changes: 3 additions & 1 deletion controller/konnect/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type SupportedKonnectEntityType interface {
configurationv1alpha1.KongPluginBinding |
configurationv1alpha1.KongCredentialBasicAuth |
configurationv1alpha1.KongUpstream |
configurationv1alpha1.KongCACertificate
configurationv1alpha1.KongCACertificate |
configurationv1alpha1.KongTarget

// TODO: add other types

GetTypeName() string
Expand Down
25 changes: 25 additions & 0 deletions controller/konnect/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,28 @@ type ReferencedKongConsumerDoesNotExist struct {
func (e ReferencedKongConsumerDoesNotExist) Error() string {
return fmt.Sprintf("referenced Kong Consumer %s does not exist: %v", e.Reference, e.Err)
}

// ReferencedKongUpstreamIsBeingDeleted is an error type that is returned when
// a Konnect entity references a Kong Upstream which is being deleted.
type ReferencedKongUpstreamIsBeingDeleted struct {
Reference types.NamespacedName
DeletionTimestamp time.Time
}

// Error implements the error interface.
func (e ReferencedKongUpstreamIsBeingDeleted) Error() string {
return fmt.Sprintf("referenced Kong Upstream %s is being deleted (deletion timestamp: %s)",
e.Reference, e.DeletionTimestamp)
}

// ReferencedKongUpstreamDoesNotExist is an error type that is returned when
// a Konnect entity references a Kong Upstream which does not exist.
type ReferencedKongUpstreamDoesNotExist struct {
Reference types.NamespacedName
Err error
}

// Error implements the error interface.
func (e ReferencedKongUpstreamDoesNotExist) Error() string {
return fmt.Sprintf("referenced Kong Upstream %s does not exist: %v", e.Reference, e.Err)
}
14 changes: 14 additions & 0 deletions controller/konnect/ops/kongtarget.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ops

import (
"context"

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

// TargetsSDK is the interface for the Konnect Taret SDK.
type TargetsSDK interface {
CreateTargetWithUpstream(ctx context.Context, req sdkkonnectops.CreateTargetWithUpstreamRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateTargetWithUpstreamResponse, error)
UpsertTargetWithUpstream(ctx context.Context, req sdkkonnectops.UpsertTargetWithUpstreamRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertTargetWithUpstreamResponse, error)
DeleteTargetWithUpstream(ctx context.Context, req sdkkonnectops.DeleteTargetWithUpstreamRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteTargetWithUpstreamResponse, error)
}
Loading
Loading