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): add KongCredentialSecretReconciler to reconcile consumer Secrets and create Credential resources in response #623

Closed
wants to merge 1 commit into from
Closed
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 @@ -19,3 +19,4 @@ packages:
PluginSDK:
UpstreamsSDK:
MeSDK:
CredentialBasicAuthSDK:
20 changes: 20 additions & 0 deletions config/rbac/role/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ rules:
- get
- patch
- update
- apiGroups:
- konnect.konghq.com
resources:
- credentialbasicauths
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- konnect.konghq.com
resources:
- kongconsumers
verbs:
- get
- list
- watch
- apiGroups:
- konnect.konghq.com
resources:
Expand Down
1 change: 1 addition & 0 deletions controller/konnect/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type SupportedKonnectEntityType interface {
configurationv1.KongConsumer |
configurationv1beta1.KongConsumerGroup |
configurationv1alpha1.KongPluginBinding |
configurationv1alpha1.CredentialBasicAuth |
configurationv1alpha1.KongUpstream
// TODO: add other types

Expand Down
7 changes: 6 additions & 1 deletion controller/konnect/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/kong/gateway-operator/controller/konnect/constraints"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)

Expand All @@ -21,9 +22,13 @@ func ReconciliationIndexOptionsForEntity[
T constraints.SupportedKonnectEntityType,
]() []ReconciliationIndexOption {
var e TEnt
switch any(e).(type) { //nolint:gocritic // TODO: add index options required for other entities
switch any(e).(type) {
case *configurationv1alpha1.KongPluginBinding:
return IndexOptionsForKongPluginBinding()
case *configurationv1.KongConsumer:
return IndexOptionsForKongConsumer()
case *configurationv1alpha1.CredentialBasicAuth:
return IndexOptionsForCredentialsBasicAuth()
}
return nil
}
48 changes: 48 additions & 0 deletions controller/konnect/index_credentials_basicauth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package konnect

import (
"sigs.k8s.io/controller-runtime/pkg/client"

configurationv1alpha1 "github.com/kong/kubernetes-configuration/api/configuration/v1alpha1"
)

const (
// IndexFieldCredentialReferencesKongConsumer is the index name for CredentialBasicAuth -> Consumer.
IndexFieldCredentialReferencesKongConsumer = "kongCredentialsBasicAuthConsumerRef"
// IndexFieldCredentialReferencesKongSecret is the index name for CredentialBasicAuth -> Secret.
IndexFieldCredentialReferencesKongSecret = "kongCredentialsBasicAuthSecretRef"
)

// IndexOptionsForCredentialsBasicAuth returns required Index options for CredentialBasicAuth.
func IndexOptionsForCredentialsBasicAuth() []ReconciliationIndexOption {
return []ReconciliationIndexOption{
{
IndexObject: &configurationv1alpha1.CredentialBasicAuth{},
IndexField: IndexFieldCredentialReferencesKongConsumer,
ExtractValue: kongCredentialBasicAuthReferencesConsumer,
},
{
IndexObject: &configurationv1alpha1.CredentialBasicAuth{},
IndexField: IndexFieldCredentialReferencesKongSecret,
ExtractValue: kongCredentialBasicAuthReferencesSecret,
},
}
}

// kongCredentialBasicAuthReferencesConsumer returns the name of referenced Consumer.
func kongCredentialBasicAuthReferencesConsumer(obj client.Object) []string {
cred, ok := obj.(*configurationv1alpha1.CredentialBasicAuth)
if !ok {
return nil
}
return []string{cred.Spec.ConsumerRef.Name}
}

// kongCredentialBasicAuthReferencesSecret returns the name of referenced Secret.
func kongCredentialBasicAuthReferencesSecret(obj client.Object) []string {
cred, ok := obj.(*configurationv1alpha1.CredentialBasicAuth)
if !ok {
return nil
}
return []string{cred.Spec.SecretRef.Name}
}
32 changes: 32 additions & 0 deletions controller/konnect/index_kongconsumer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package konnect

import (
"sigs.k8s.io/controller-runtime/pkg/client"

configurationv1 "github.com/kong/kubernetes-configuration/api/configuration/v1"
)

const (
// IndexFieldKongConsumerReferencesSecrets is the index field for Consumer -> Secret.
IndexFieldKongConsumerReferencesSecrets = "kongConsumerSecretRef"
)

// IndexOptionsForKongConsumer returns required Index options for Kong Consumer.
func IndexOptionsForKongConsumer() []ReconciliationIndexOption {
return []ReconciliationIndexOption{
{
IndexObject: &configurationv1.KongConsumer{},
IndexField: IndexFieldKongConsumerReferencesSecrets,
ExtractValue: kongConsumerReferencesSecret,
},
}
}

// kongConsumerReferencesSecret returns name of referenced Secrets.
func kongConsumerReferencesSecret(obj client.Object) []string {
consumer, ok := obj.(*configurationv1.KongConsumer)
if !ok {
return nil
}
return consumer.Credentials
}
14 changes: 14 additions & 0 deletions controller/konnect/ops/credenetialbasicauth.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"
)

// CredentialBasicAuthSDK is the interface for the Konnect CredentialBasicAuthSDK.
type CredentialBasicAuthSDK interface {
CreateBasicAuthWithConsumer(ctx context.Context, req sdkkonnectops.CreateBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.CreateBasicAuthWithConsumerResponse, error)
DeleteBasicAuthWithConsumer(ctx context.Context, request sdkkonnectops.DeleteBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.DeleteBasicAuthWithConsumerResponse, error)
UpsertBasicAuthWithConsumer(ctx context.Context, request sdkkonnectops.UpsertBasicAuthWithConsumerRequest, opts ...sdkkonnectops.Option) (*sdkkonnectops.UpsertBasicAuthWithConsumerResponse, error)
}
Loading
Loading