Skip to content

Commit

Permalink
enable cache only for 1 object
Browse files Browse the repository at this point in the history
  • Loading branch information
dbadura committed Feb 2, 2024
1 parent ff15366 commit 2f6b95c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
15 changes: 10 additions & 5 deletions cmd/admission/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"github.com/kyma-project/warden/internal/logging"
"github.com/kyma-project/warden/internal/webhook"
"go.uber.org/zap/zapcore"
"k8s.io/apimachinery/pkg/fields"
"os"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"

"github.com/go-logr/zapr"
Expand All @@ -21,7 +23,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager"
ctrlwebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
)
Expand Down Expand Up @@ -110,10 +111,14 @@ func main() {
MetricsBindAddress: ":9090",
Logger: logrZap,
HealthProbeBindAddress: ":8090",
ClientDisableCacheFor: []ctrlclient.Object{
&corev1.Secret{},
&corev1.ConfigMap{},
},
NewCache: cache.BuilderWithOptions(cache.Options{
SelectorsByObject: cache.SelectorsByObject{
&corev1.Secret{}: {
Field: fields.SelectorFromSet(fields.Set{"metadata.name": appConfig.Admission.SecretName,
"metadata.namespace": appConfig.Admission.SystemNamespace}),
},
},
}),
})
if err != nil {
logger.Error("failed to start manager", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion internal/webhook/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package webhook

import (
"context"
corev1 "k8s.io/api/core/v1"
"os"
"path"
"time"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/kyma-project/warden/internal/webhook/certs"
"github.com/pkg/errors"
admissionregistrationv1 "k8s.io/api/admissionregistration/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
Expand Down

0 comments on commit 2f6b95c

Please sign in to comment.