diff --git a/cmd/controller/main.go b/cmd/controller/main.go index 2ec9d961ac19..088bd8517ad0 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -102,7 +102,7 @@ func main() { ctors = append(ctors, certificate.NewController) // add the net-certmanager controller } else { // Remove all non required informers - ctx = injection.WithExcludeInformerPredicate(ctx, excludeNetCertManagerInformers) + ctx = injection.WithInformerExcludingFilter(ctx, excludeNetCertManagerInformers) } sharedmain.MainWithConfig(ctx, "controller", cfg, ctors...) @@ -122,12 +122,18 @@ func shouldEnableNetCertManagerController(ctx context.Context, client *kubernete netCfg.NamespaceWildcardCertSelector != nil } -func excludeNetCertManagerInformers(ctx context.Context, inf controller.Informer) bool { - isCertInf := v1certificate.Get(ctx).Informer() == inf - isCertReqInf := certificaterequest.Get(ctx).Informer() == inf - isClusterIssuerInf := clusterissuer.Get(ctx).Informer() == inf - isIssuerInf := issuer.Get(ctx).Informer() == inf - isChallengeInf := challenge.Get(ctx).Informer() == inf - - return isCertInf || isCertReqInf || isClusterIssuerInf || isIssuerInf || isChallengeInf +func excludeNetCertManagerInformers(ctx context.Context, inf controller.Informer) (bool, string) { + switch { + case v1certificate.Get(ctx).Informer() == inf: + return true, "CertificateInformer" + case certificaterequest.Get(ctx).Informer() == inf: + return true, "CertificateRequestInformer" + case clusterissuer.Get(ctx).Informer() == inf: + return true, "ClusterIssuerInformer" + case issuer.Get(ctx).Informer() == inf: + return true, "IssuerInformer" + case challenge.Get(ctx).Informer() == inf: + return true, "ChallengeInformer" + } + return false, "" } diff --git a/go.sum b/go.sum index a416ef3bb091..18a448bc92c3 100644 --- a/go.sum +++ b/go.sum @@ -228,13 +228,8 @@ github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -<<<<<<< HEAD github.com/golang/glog v1.2.0 h1:uCdmnmatrKCgMBlM4rMuJZWOkPDqdbZPnrMXDY4gI68= github.com/golang/glog v1.2.0/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -======= -github.com/golang/glog v1.1.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo= -github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= ->>>>>>> f693dd363 (vendor fixes) github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/vendor/knative.dev/pkg/injection/injection.go b/vendor/knative.dev/pkg/injection/injection.go index a3bd818b9901..02bd4d75e10f 100644 --- a/vendor/knative.dev/pkg/injection/injection.go +++ b/vendor/knative.dev/pkg/injection/injection.go @@ -59,36 +59,41 @@ func EnableInjectionOrDie(ctx context.Context, cfg *rest.Config) (context.Contex ctx, informers := Default.SetupInformers(ctx, cfg) - var finalInformers []controller.Informer - + includedInformers := make([]controller.Informer, 0) + for _, inf := range informers { - if p := GetExcludeInformerPredicate(ctx); p != nil && (*p)(ctx, inf){ - continue + if p := getInformerExcludingFilter(ctx); p != nil { + skip, name := (*p)(ctx, inf) + if skip { + logging.FromContext(ctx).Infof("Excluding informer %s", name) + continue + } } - finalInformers = append(finalInformers, inf) + includedInformers = append(includedInformers, inf) } return ctx, func() { - logging.FromContext(ctx).Info("Starting informers...") - logging.FromContext(ctx).Infof("Number of informers to start: %d\n", len(finalInformers)) - if err := controller.StartInformers(ctx.Done(), finalInformers...); err != nil { + logging.FromContext(ctx).Infof("Starting %d informers...", len(includedInformers)) + if err := controller.StartInformers(ctx.Done(), includedInformers...); err != nil { logging.FromContext(ctx).Fatalw("Failed to start informers", zap.Error(err)) } } } -type ExcludeInformerPredicate func(ctx context.Context, inf controller.Informer) bool -type ExcludeInformerPredicateKey struct{} +type InformerExcludingFilter func(ctx context.Context, inf controller.Informer) (bool, string) +type excludeInformerPredicateKey struct{} -func WithExcludeInformerPredicate(ctx context.Context, predicate ExcludeInformerPredicate) context.Context { - return context.WithValue(ctx, ExcludeInformerPredicateKey{}, predicate) +// WithInformerExcludingFilter sets the predicate to exclude informers from being started. +// If predicate returns true the informer will not be started. +func WithInformerExcludingFilter(ctx context.Context, predicate InformerExcludingFilter) context.Context { + return context.WithValue(ctx, excludeInformerPredicateKey{}, predicate) } -func GetExcludeInformerPredicate(ctx context.Context) *ExcludeInformerPredicate { - untyped := ctx.Value(ExcludeInformerPredicateKey{}) +func getInformerExcludingFilter(ctx context.Context) *InformerExcludingFilter { + untyped := ctx.Value(excludeInformerPredicateKey{}) if untyped == nil { return nil } - e := untyped.(ExcludeInformerPredicate) - return &e -} \ No newline at end of file + e := untyped.(InformerExcludingFilter) + return &e +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 771b5aa2a3c5..7d39938773bc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -690,9 +690,6 @@ google.golang.org/appengine/internal/remote_api google.golang.org/appengine/internal/urlfetch google.golang.org/appengine/urlfetch # google.golang.org/genproto/googleapis/api v0.0.0-20240221002015-b0ce06bbee7c -# google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 -# google.golang.org/genproto/googleapis/api v0.0.0-20240122161410-6c6643bf1457 -# google.golang.org/genproto/googleapis/api v0.0.0-20240205150955-31a09d347014 ## explicit; go 1.19 google.golang.org/genproto/googleapis/api/httpbody # google.golang.org/genproto/googleapis/rpc v0.0.0-20240304161311-37d4d3c04a78 @@ -1312,7 +1309,6 @@ k8s.io/kube-openapi/pkg/util/proto k8s.io/kube-openapi/pkg/util/sets k8s.io/kube-openapi/pkg/validation/spec # k8s.io/utils v0.0.0-20240102154912-e7106e64919e -# k8s.io/utils v0.0.0-20230726121419-3b25d923346b ## explicit; go 1.18 k8s.io/utils/buffer k8s.io/utils/clock