-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(konnect): add KongCredentialSecretReconciler to reconcile consum…
…er Secrets and create Credential resources in response
- Loading branch information
Showing
15 changed files
with
703 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,4 @@ packages: | |
PluginSDK: | ||
UpstreamsSDK: | ||
MeSDK: | ||
CredentialBasicAuthSDK: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.