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

fix(cert-manager): exclude CRDs from cache to avoid excessive memory usage #2258

Merged
merged 4 commits into from
Oct 11, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,38 @@ func (r *KeptnWebhookCertificateReconciler) Reconcile(ctx context.Context, reque
r.Log.Info("reconciling webhook certificates",
"namespace", request.Namespace, "name", request.Name)

r.Log.Info("Retrieving MutatingWebhooks")
mutatingWebhookConfigurations, err := r.ResourceRetriever.GetMutatingWebhooks(ctx)
if err != nil {
r.Log.Error(err, "could not find mutating webhook configuration")
}
r.Log.Info(
"Found MutatingWebhooks to inject certificates",
"numberOfItems", len(mutatingWebhookConfigurations.Items),
"byteSize", mutatingWebhookConfigurations.Size(),
)

r.Log.Info("Retrieving ValidatingWebhooks")
validatingWebhookConfigurations, err := r.ResourceRetriever.GetValidatingWebhooks(ctx)
if err != nil {
r.Log.Error(err, "could not find validating webhook configuration")
}
r.Log.Info(
"Found ValidatingWebhooks to inject certificates",
"numberOfItems", len(validatingWebhookConfigurations.Items),
"byteSize", validatingWebhookConfigurations.Size(),
)

r.Log.Info("Retrieving CRDs")
crds, err := r.ResourceRetriever.GetCRDs(ctx)
if err != nil {
r.Log.Error(err, "could not find CRDs")
}

r.Log.Info(
"Found CRDs to inject certificates",
"numberOfItems", len(crds.Items),
"byteSize", crds.Size(),
)
certSecret := newCertificateSecret(r.Client)

if err := r.setCertificates(ctx, certSecret); err != nil {
Expand Down Expand Up @@ -240,6 +257,11 @@ func (r *KeptnWebhookCertificateReconciler) updateCRDConfiguration(ctx context.C
return nil
}

r.Log.Info(
"Found conversion webhook in CRD, updating client certificate",
"crd", crdName,
)

// update crd
crd.Spec.Conversion.Webhook.ClientConfig.CABundle = bundle
if err := r.Client.Update(ctx, &crd); err != nil {
Expand Down
6 changes: 6 additions & 0 deletions klt-cert-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/cache"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
Expand Down Expand Up @@ -89,6 +90,11 @@ func main() {
// if you are doing or is intended to do any operation such as perform cleanups
// after the manager stops then its usage might be unsafe.
// LeaderElectionReleaseOnCancel: true,
Client: ctrlclient.Options{
Cache: &ctrlclient.CacheOptions{
DisableFor: []ctrlclient.Object{&apiv1.CustomResourceDefinition{}},
},
},
})
if err != nil {
setupLog.Error(err, "unable to start manager")
Expand Down
Loading