Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Mar 14, 2024
1 parent 286fdee commit f5e9e74
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 35 deletions.
24 changes: 15 additions & 9 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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, ""
}
5 changes: 0 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
39 changes: 22 additions & 17 deletions vendor/knative.dev/pkg/injection/injection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
e := untyped.(InformerExcludingFilter)
return &e
}
4 changes: 0 additions & 4 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f5e9e74

Please sign in to comment.