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

Store client #3861

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ linters-settings:
alias: metav1
- pkg: sigs.k8s.io/gateway-api/apis/(v[\w\d]+)
alias: gateway${1}

- pkg: sigs.k8s.io/controller-runtime/pkg/client/fake
alias: ctrlclientfake
gomodguard:
blocked:
modules:
Expand Down
14 changes: 7 additions & 7 deletions hack/generators/controllers/networking/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
obj.Name = req.Name
{{if .NeedsUpdateReferences}}
// remove reference record where the {{.Kind}} is the referrer
if err := ctrlref.DeleteReferencesByReferrer(r.ReferenceIndexers, r.DataplaneClient, obj); err != nil {
if err := ctrlref.DeleteReferencesByReferrer(ctx, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil {
return ctrl.Result{}, err
}
{{end}}
return ctrl.Result{}, r.DataplaneClient.DeleteObject(obj)
return ctrl.Result{}, r.DataplaneClient.DeleteObject(ctx, obj)
}
return ctrl.Result{}, err
}
Expand All @@ -543,16 +543,16 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
log.V(util.DebugLevel).Info("resource is being deleted, its configuration will be removed", "type", "{{.Kind}}", "namespace", req.Namespace, "name", req.Name)
{{if .NeedsUpdateReferences}}
// remove reference record where the {{.Kind}} is the referrer
if err := ctrlref.DeleteReferencesByReferrer(r.ReferenceIndexers, r.DataplaneClient, obj); err != nil {
if err := ctrlref.DeleteReferencesByReferrer(ctx, r.ReferenceIndexers, r.DataplaneClient, obj); err != nil {
return ctrl.Result{}, err
}
{{end}}
objectExistsInCache, err := r.DataplaneClient.ObjectExists(obj)
objectExistsInCache, err := r.DataplaneClient.ObjectExists(ctx, obj)
if err != nil {
return ctrl.Result{}, err
}
if objectExistsInCache {
if err := r.DataplaneClient.DeleteObject(obj); err != nil {
if err := r.DataplaneClient.DeleteObject(ctx, obj); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil // wait until the object is no longer present in the cache
Expand All @@ -574,14 +574,14 @@ func (r *{{.PackageAlias}}{{.Kind}}Reconciler) Reconcile(ctx context.Context, re
if !ctrlutils.MatchesIngressClass(obj, r.IngressClassName, ctrlutils.IsDefaultIngressClass(class)) {
log.V(util.DebugLevel).Info("object missing ingress class, ensuring it's removed from configuration",
"namespace", req.Namespace, "name", req.Name, "class", r.IngressClassName)
return ctrl.Result{}, r.DataplaneClient.DeleteObject(obj)
return ctrl.Result{}, r.DataplaneClient.DeleteObject(ctx, obj)
} else {
log.V(util.DebugLevel).Info("object has matching ingress class", "namespace", req.Namespace, "name", req.Name,
"class", r.IngressClassName)
}
{{end}}
// update the kong Admin API with the changes
if err := r.DataplaneClient.UpdateObject(obj); err != nil {
if err := r.DataplaneClient.UpdateObject(ctx, obj); err != nil {
return ctrl.Result{}, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/adminapi/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
fakeclient "sigs.k8s.io/controller-runtime/pkg/client/fake"
ctrlclientfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
)

func TestAddressesFromEndpointSlice(t *testing.T) {
Expand Down Expand Up @@ -537,7 +537,7 @@ func TestGetAdminAPIsForService(t *testing.T) {
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
fakeClient := fakeclient.NewClientBuilder().
fakeClient := ctrlclientfake.NewClientBuilder().
WithLists(tt.objects...).
Build()

Expand Down
8 changes: 4 additions & 4 deletions internal/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (validator KongHTTPValidator) ValidateConsumer(
ignoredSecrets := make(map[string]map[string]struct{})
for _, secretName := range consumer.Credentials {
// retrieve the credentials secret
secret, err := validator.SecretGetter.GetSecret(consumer.Namespace, secretName)
secret, err := validator.SecretGetter.GetSecret(ctx, consumer.Namespace, secretName)
if err != nil {
if apierrors.IsNotFound(err) {
return false, ErrTextConsumerCredentialSecretNotFound, err
Expand Down Expand Up @@ -236,7 +236,7 @@ func (validator KongHTTPValidator) ValidatePlugin(
if len(plugin.Config) > 0 {
return false, ErrTextPluginUsesBothConfigTypes, nil
}
config, err := kongstate.SecretToConfiguration(validator.SecretGetter, (*k8sPlugin.ConfigFrom).SecretValue, k8sPlugin.Namespace)
config, err := kongstate.SecretToConfiguration(ctx, validator.SecretGetter, (*k8sPlugin.ConfigFrom).SecretValue, k8sPlugin.Namespace)
if err != nil {
return false, ErrTextPluginSecretConfigUnretrievable, err
}
Expand Down Expand Up @@ -433,9 +433,9 @@ type managerClientSecretGetter struct {
managerClient client.Client
}

func (m *managerClientSecretGetter) GetSecret(namespace, name string) (*corev1.Secret, error) {
func (m *managerClientSecretGetter) GetSecret(ctx context.Context, namespace, name string) (*corev1.Secret, error) {
secret := &corev1.Secret{}
return secret, m.managerClient.Get(context.Background(), client.ObjectKey{
return secret, m.managerClient.Get(ctx, client.ObjectKey{
Namespace: namespace,
Name: name,
}, secret)
Expand Down
8 changes: 4 additions & 4 deletions internal/controllers/configuration/secret_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (r *CoreV1SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request
if apierrors.IsNotFound(err) {
secret.Namespace = req.Namespace
secret.Name = req.Name
return ctrl.Result{}, r.DataplaneClient.DeleteObject(secret)
return ctrl.Result{}, r.DataplaneClient.DeleteObject(ctx, secret)
}
return ctrl.Result{}, err
}
Expand All @@ -112,12 +112,12 @@ func (r *CoreV1SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request
// clean the object up if it's being deleted
if !secret.DeletionTimestamp.IsZero() && time.Now().After(secret.DeletionTimestamp.Time) {
log.V(util.DebugLevel).Info("resource is being deleted, its configuration will be removed", "type", "Secret", "namespace", req.Namespace, "name", req.Name)
objectExistsInCache, err := r.DataplaneClient.ObjectExists(secret)
objectExistsInCache, err := r.DataplaneClient.ObjectExists(ctx, secret)
if err != nil {
return ctrl.Result{}, err
}
if objectExistsInCache {
if err := r.DataplaneClient.DeleteObject(secret); err != nil {
if err := r.DataplaneClient.DeleteObject(ctx, secret); err != nil {
return ctrl.Result{}, err
}
return ctrl.Result{Requeue: true}, nil // wait until the object is no longer present in the cache
Expand All @@ -126,7 +126,7 @@ func (r *CoreV1SecretReconciler) Reconcile(ctx context.Context, req ctrl.Request
}

// update the kong Admin API with the changes
if err := r.DataplaneClient.UpdateObject(secret); err != nil {
if err := r.DataplaneClient.UpdateObject(ctx, secret); err != nil {
return ctrl.Result{}, err
}

Expand Down
Loading