Skip to content

Commit e73743b

Browse files
vdemeesterclaude
andcommitted
perf(controller): extend informer cache transform to Pod and CustomRun
Extend the cache transform to reduce memory usage for additional resource types: **Pod Transform (for TaskRun controller)** - 66.4% size reduction for realistic TaskRun pods - Strips: ManagedFields, OwnerReferences, Labels, Finalizers, last-applied-configuration, and most Spec fields - Preserves: Name, Namespace, Annotations, Spec.Containers[].Name (for status sorting), all Status fields **Enhanced TaskRun Transform** - For completed TaskRuns, now also strips: Status.Steps, Status.Sidecars, Status.PodName, Status.RetriesStatus, Status.CompletionTime - Preserves: Status.Results, Status.Artifacts, Status.Conditions **CustomRun Transform (new)** - Strips: ManagedFields, last-applied-configuration - For completed CustomRuns: Status.RetriesStatus, Status.CompletionTime - Preserves: Status.Results, Status.Conditions Adds kube_factory.go to wire the Pod transform into the Kubernetes filtered informer factory used by the TaskRun controller. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e741d16 commit e73743b

File tree

5 files changed

+1244
-1
lines changed

5 files changed

+1244
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
Copyright 2026 The Tekton Authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package transform
18+
19+
import (
20+
"context"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
"k8s.io/client-go/informers"
24+
client "knative.dev/pkg/client/injection/kube/client"
25+
filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered"
26+
"knative.dev/pkg/controller"
27+
"knative.dev/pkg/injection"
28+
"knative.dev/pkg/logging"
29+
)
30+
31+
func init() {
32+
// Register our factory AFTER the default one to override it.
33+
// This works because Knative's injection framework allows multiple
34+
// registrations with the same key, and later ones override earlier ones.
35+
injection.Default.RegisterInformerFactory(withTransformFilteredFactory)
36+
}
37+
38+
// withTransformFilteredFactory creates a new filtered informer factory with the
39+
// Pod cache transform applied. This factory replaces the default Knative filtered
40+
// factory by using the same context key.
41+
//
42+
// This approach ensures that all Kubernetes Pod informers used by Tekton apply
43+
// the transform to reduce memory usage without modifying the generated code or
44+
// the Knative pkg.
45+
func withTransformFilteredFactory(ctx context.Context) context.Context {
46+
c := client.Get(ctx)
47+
48+
// Get the label selectors from context (set by filteredinformerfactory.WithSelectors)
49+
untyped := ctx.Value(filteredFactory.LabelKey{})
50+
if untyped == nil {
51+
// No selectors configured, let the default factory handle it
52+
logging.FromContext(ctx).Debug("No label selectors configured for filtered factory, skipping transform")
53+
return ctx
54+
}
55+
56+
labelSelectors := untyped.([]string)
57+
for _, selector := range labelSelectors {
58+
selectorVal := selector
59+
opts := []informers.SharedInformerOption{}
60+
61+
// Handle namespace scoping
62+
if injection.HasNamespaceScope(ctx) {
63+
opts = append(opts, informers.WithNamespace(injection.GetNamespaceScope(ctx)))
64+
}
65+
66+
// Add label selector filter
67+
opts = append(opts, informers.WithTweakListOptions(func(l *metav1.ListOptions) {
68+
l.LabelSelector = selectorVal
69+
}))
70+
71+
// Add our Pod cache transform
72+
opts = append(opts, informers.WithTransform(TransformPodForCache))
73+
74+
// Store using the same Key as the default factory to override it
75+
ctx = context.WithValue(ctx, filteredFactory.Key{Selector: selectorVal},
76+
informers.NewSharedInformerFactoryWithOptions(c, controller.GetResyncPeriod(ctx), opts...))
77+
}
78+
79+
return ctx
80+
}

0 commit comments

Comments
 (0)