Skip to content

Commit 41e3b1e

Browse files
committed
MULTIARCH-4257: Cache and reconcile only Pending pods
1 parent 84d7c36 commit 41e3b1e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
_ "k8s.io/client-go/plugin/pkg/client/auth"
3030

3131
corev1 "k8s.io/api/core/v1"
32+
"k8s.io/apimachinery/pkg/fields"
3233
"k8s.io/apimachinery/pkg/runtime"
3334
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3435
"k8s.io/client-go/dynamic"
@@ -37,6 +38,7 @@ import (
3738
"k8s.io/klog/v2"
3839
ctrl "sigs.k8s.io/controller-runtime"
3940

41+
"sigs.k8s.io/controller-runtime/pkg/cache"
4042
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
4143
"sigs.k8s.io/controller-runtime/pkg/healthz"
4244
ctrllog "sigs.k8s.io/controller-runtime/pkg/log"
@@ -99,13 +101,20 @@ func init() {
99101
func main() {
100102
bindFlags()
101103
must(validateFlags(), "invalid flags")
104+
cacheOpts := cache.Options{
105+
DefaultTransform: cache.TransformStripManagedFields(),
106+
}
107+
102108
// Build the leader election ID deterministically and based on the flags
103109
leaderId := "208d7abd.multiarch.openshift.io"
104110
if enableOperator {
105111
leaderId = fmt.Sprintf("operator-%s", leaderId)
106112
}
107113
if enableClusterPodPlacementConfigOperandControllers {
108114
leaderId = fmt.Sprintf("ppc-controllers-%s", leaderId)
115+
// We need to watch the pods with the status.phase equal to Pending to be able to update the nodeAffinity.
116+
// We can discard the other pods because they are already scheduled.
117+
cacheOpts.DefaultFieldSelector = fields.OneTermEqualSelector("status.phase", "Pending")
109118
}
110119
// Rapid Reset CVEs. For more information see:
111120
// - https://github.com/advisories/GHSA-qppj-fm5r-hxr3
@@ -135,6 +144,7 @@ func main() {
135144
HealthProbeBindAddress: probeAddr,
136145
LeaderElection: enableLeaderElection,
137146
LeaderElectionID: leaderId,
147+
Cache: cacheOpts,
138148
// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
139149
// when the Manager ends. This requires the binary to immediately end when the
140150
// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly

0 commit comments

Comments
 (0)