update the multiple label selector implemention to avoid clobber in filtered factory (#2120)

This commit is contained in:
ying 2021-05-25 15:14:38 +08:00 committed by GitHub
parent e749d6a2ad
commit e2947dba20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 36 deletions

View File

@ -38,10 +38,6 @@ func init() {
func withInformerFactory(ctx context.Context) context.Context {
c := fake.Get(ctx)
opts := []externalversions.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
}
untyped := ctx.Value(filtered.LabelKey{})
if untyped == nil {
logging.FromContext(ctx).Panic(
@ -49,11 +45,15 @@ func withInformerFactory(ctx context.Context) context.Context {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) {
opts := []externalversions.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
}
opts = append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, filtered.Key{Selector: selector},
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
}
return ctx
}

View File

@ -46,10 +46,6 @@ func WithSelectors(ctx context.Context, selector ...string) context.Context {
func withInformerFactory(ctx context.Context) context.Context {
c := client.Get(ctx)
opts := []externalversions.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
}
untyped := ctx.Value(LabelKey{})
if untyped == nil {
logging.FromContext(ctx).Panic(
@ -57,11 +53,15 @@ func withInformerFactory(ctx context.Context) context.Context {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) {
opts := []externalversions.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
}
opts = append(opts, externalversions.WithTweakListOptions(func(l *v1.ListOptions) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, Key{Selector: selector},
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
}
return ctx
}

View File

@ -38,10 +38,6 @@ func init() {
func withInformerFactory(ctx context.Context) context.Context {
c := fake.Get(ctx)
opts := []informers.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
}
untyped := ctx.Value(filtered.LabelKey{})
if untyped == nil {
logging.FromContext(ctx).Panic(
@ -49,11 +45,15 @@ func withInformerFactory(ctx context.Context) context.Context {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, informers.WithTweakListOptions(func(l *v1.ListOptions) {
opts := []informers.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
}
opts = append(opts, informers.WithTweakListOptions(func(l *v1.ListOptions) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, filtered.Key{Selector: selector},
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
}
return ctx
}

View File

@ -46,10 +46,6 @@ func WithSelectors(ctx context.Context, selector ...string) context.Context {
func withInformerFactory(ctx context.Context) context.Context {
c := client.Get(ctx)
opts := []informers.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
}
untyped := ctx.Value(LabelKey{})
if untyped == nil {
logging.FromContext(ctx).Panic(
@ -57,11 +53,15 @@ func withInformerFactory(ctx context.Context) context.Context {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, informers.WithTweakListOptions(func(l *v1.ListOptions) {
opts := []informers.SharedInformerOption{}
if injection.HasNamespaceScope(ctx) {
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
}
opts = append(opts, informers.WithTweakListOptions(func(l *v1.ListOptions) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, Key{Selector: selector},
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
}
return ctx
}

View File

@ -109,10 +109,6 @@ func init() {
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
c := {{.clientGet|raw}}(ctx)
opts := []{{.informersSharedInformerOption|raw}}{}
if {{.injectionHasNamespace|raw}}(ctx) {
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
}
untyped := ctx.Value({{.factoryLabelKey|raw}}{})
if untyped == nil {
{{.loggingFromContext|raw}}(ctx).Panic(
@ -120,11 +116,15 @@ func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, {{.informersWithTweakListOptions|raw}}(func(l *{{.metav1ListOptions|raw}}) {
opts := []{{.informersSharedInformerOption|raw}}{}
if {{.injectionHasNamespace|raw}}(ctx) {
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
}
opts = append(opts, {{.informersWithTweakListOptions|raw}}(func(l *{{.metav1ListOptions|raw}}) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, {{.factoryKey|raw}}{Selector: selector},
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), thisOpts...))
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), opts...))
}
return ctx
}

View File

@ -111,10 +111,6 @@ func WithSelectors(ctx {{.contextContext|raw}}, selector ...string) context.Cont
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
c := {{.cachingClientGet|raw}}(ctx)
opts := []{{.informersSharedInformerOption|raw}}{}
if {{.injectionHasNamespace|raw}}(ctx) {
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
}
untyped := ctx.Value(LabelKey{})
if untyped == nil {
{{.loggingFromContext|raw}}(ctx).Panic(
@ -122,11 +118,15 @@ func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
}
labelSelectors := untyped.([]string)
for _, selector := range labelSelectors {
thisOpts := append(opts, {{.informersWithTweakListOptions|raw}}(func(l *{{.metav1ListOptions|raw}}) {
opts := []{{.informersSharedInformerOption|raw}}{}
if {{.injectionHasNamespace|raw}}(ctx) {
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
}
opts = append(opts, {{.informersWithTweakListOptions|raw}}(func(l *{{.metav1ListOptions|raw}}) {
l.LabelSelector = selector
}))
ctx = context.WithValue(ctx, Key{Selector: selector},
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), thisOpts...))
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), opts...))
}
return ctx
}