mirror of https://github.com/knative/pkg.git
update the multiple label selector implemention to avoid clobber in filtered factory (#2120)
This commit is contained in:
parent
e749d6a2ad
commit
e2947dba20
|
|
@ -38,10 +38,6 @@ func init() {
|
||||||
|
|
||||||
func withInformerFactory(ctx context.Context) context.Context {
|
func withInformerFactory(ctx context.Context) context.Context {
|
||||||
c := fake.Get(ctx)
|
c := fake.Get(ctx)
|
||||||
opts := []externalversions.SharedInformerOption{}
|
|
||||||
if injection.HasNamespaceScope(ctx) {
|
|
||||||
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value(filtered.LabelKey{})
|
untyped := ctx.Value(filtered.LabelKey{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
logging.FromContext(ctx).Panic(
|
logging.FromContext(ctx).Panic(
|
||||||
|
|
@ -49,11 +45,15 @@ func withInformerFactory(ctx context.Context) context.Context {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, filtered.Key{Selector: 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
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,6 @@ func WithSelectors(ctx context.Context, selector ...string) context.Context {
|
||||||
|
|
||||||
func withInformerFactory(ctx context.Context) context.Context {
|
func withInformerFactory(ctx context.Context) context.Context {
|
||||||
c := client.Get(ctx)
|
c := client.Get(ctx)
|
||||||
opts := []externalversions.SharedInformerOption{}
|
|
||||||
if injection.HasNamespaceScope(ctx) {
|
|
||||||
opts = append(opts, externalversions.WithNamespace(injection.GetNamespaceScope(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value(LabelKey{})
|
untyped := ctx.Value(LabelKey{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
logging.FromContext(ctx).Panic(
|
logging.FromContext(ctx).Panic(
|
||||||
|
|
@ -57,11 +53,15 @@ func withInformerFactory(ctx context.Context) context.Context {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, Key{Selector: selector},
|
ctx = context.WithValue(ctx, Key{Selector: selector},
|
||||||
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
|
externalversions.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
|
||||||
}
|
}
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,6 @@ func init() {
|
||||||
|
|
||||||
func withInformerFactory(ctx context.Context) context.Context {
|
func withInformerFactory(ctx context.Context) context.Context {
|
||||||
c := fake.Get(ctx)
|
c := fake.Get(ctx)
|
||||||
opts := []informers.SharedInformerOption{}
|
|
||||||
if injection.HasNamespaceScope(ctx) {
|
|
||||||
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value(filtered.LabelKey{})
|
untyped := ctx.Value(filtered.LabelKey{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
logging.FromContext(ctx).Panic(
|
logging.FromContext(ctx).Panic(
|
||||||
|
|
@ -49,11 +45,15 @@ func withInformerFactory(ctx context.Context) context.Context {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, filtered.Key{Selector: 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
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,6 @@ func WithSelectors(ctx context.Context, selector ...string) context.Context {
|
||||||
|
|
||||||
func withInformerFactory(ctx context.Context) context.Context {
|
func withInformerFactory(ctx context.Context) context.Context {
|
||||||
c := client.Get(ctx)
|
c := client.Get(ctx)
|
||||||
opts := []informers.SharedInformerOption{}
|
|
||||||
if injection.HasNamespaceScope(ctx) {
|
|
||||||
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value(LabelKey{})
|
untyped := ctx.Value(LabelKey{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
logging.FromContext(ctx).Panic(
|
logging.FromContext(ctx).Panic(
|
||||||
|
|
@ -57,11 +53,15 @@ func withInformerFactory(ctx context.Context) context.Context {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, Key{Selector: selector},
|
ctx = context.WithValue(ctx, Key{Selector: selector},
|
||||||
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), thisOpts...))
|
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
|
||||||
}
|
}
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,6 @@ func init() {
|
||||||
|
|
||||||
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
||||||
c := {{.clientGet|raw}}(ctx)
|
c := {{.clientGet|raw}}(ctx)
|
||||||
opts := []{{.informersSharedInformerOption|raw}}{}
|
|
||||||
if {{.injectionHasNamespace|raw}}(ctx) {
|
|
||||||
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value({{.factoryLabelKey|raw}}{})
|
untyped := ctx.Value({{.factoryLabelKey|raw}}{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
{{.loggingFromContext|raw}}(ctx).Panic(
|
{{.loggingFromContext|raw}}(ctx).Panic(
|
||||||
|
|
@ -120,11 +116,15 @@ func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, {{.factoryKey|raw}}{Selector: 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
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -111,10 +111,6 @@ func WithSelectors(ctx {{.contextContext|raw}}, selector ...string) context.Cont
|
||||||
|
|
||||||
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
||||||
c := {{.cachingClientGet|raw}}(ctx)
|
c := {{.cachingClientGet|raw}}(ctx)
|
||||||
opts := []{{.informersSharedInformerOption|raw}}{}
|
|
||||||
if {{.injectionHasNamespace|raw}}(ctx) {
|
|
||||||
opts = append(opts, {{.informersWithNamespace|raw}}({{.injectionGetNamespace|raw}}(ctx)))
|
|
||||||
}
|
|
||||||
untyped := ctx.Value(LabelKey{})
|
untyped := ctx.Value(LabelKey{})
|
||||||
if untyped == nil {
|
if untyped == nil {
|
||||||
{{.loggingFromContext|raw}}(ctx).Panic(
|
{{.loggingFromContext|raw}}(ctx).Panic(
|
||||||
|
|
@ -122,11 +118,15 @@ func withInformerFactory(ctx {{.contextContext|raw}}) {{.contextContext|raw}} {
|
||||||
}
|
}
|
||||||
labelSelectors := untyped.([]string)
|
labelSelectors := untyped.([]string)
|
||||||
for _, selector := range labelSelectors {
|
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
|
l.LabelSelector = selector
|
||||||
}))
|
}))
|
||||||
ctx = context.WithValue(ctx, Key{Selector: selector},
|
ctx = context.WithValue(ctx, Key{Selector: selector},
|
||||||
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), thisOpts...))
|
{{.informersNewSharedInformerFactoryWithOptions|raw}}(c, {{.controllerGetResyncPeriod|raw}}(ctx), opts...))
|
||||||
}
|
}
|
||||||
return ctx
|
return ctx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue