Merge pull request #132400 from xigang/orphan_pod_index · kubernetes/kubernetes@ccf291b · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

Commit ccf291b

Browse files
authored
Merge pull request #132400 from xigang/orphan_pod_index
Add namespace-aware orphan pod indexing for improved controller performance
2 parents 168e02f + 66c6111 commit ccf291b

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

pkg/controller/controller_utils.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,11 @@ func AddPodNodeNameIndexer(podInformer cache.SharedIndexInformer) error {
10831083
})
10841084
}
10851085

1086+
// OrphanPodIndexKeyForNamespace returns the orphan pod index key for a specific namespace.
1087+
func OrphanPodIndexKeyForNamespace(namespace string) string {
1088+
return OrphanPodIndexKey + "/" + namespace
1089+
}
1090+
10861091
// AddPodControllerUIDIndexer adds an indexer for Pod's controllerRef.UID to the given PodInformer.
10871092
// This indexer is used to efficiently look up pods by their ControllerRef.UID
10881093
func AddPodControllerUIDIndexer(podInformer cache.SharedIndexInformer) error {
@@ -1100,9 +1105,9 @@ func AddPodControllerUIDIndexer(podInformer cache.SharedIndexInformer) error {
11001105
if ref := metav1.GetControllerOf(pod); ref != nil {
11011106
return []string{string(ref.UID)}, nil
11021107
}
1103-
// If the Pod has no controller (i.e., it's orphaned), index it with the OrphanPodIndexKey
1108+
// If the Pod has no controller (i.e., it's orphaned), index it with the OrphanPodIndexKeyForNamespace
11041109
// This helps identify orphan pods for reconciliation and adoption by controllers
1105-
return []string{OrphanPodIndexKey}, nil
1110+
return []string{OrphanPodIndexKeyForNamespace(pod.Namespace)}, nil
11061111
},
11071112
})
11081113
}

pkg/controller/daemon/daemon_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ func (dsc *DaemonSetsController) getDaemonPodsFromCache(ds *apps.DaemonSet) ([]*
696696
// The OrphanPodIndexKey, which helps identify orphaned Pods that are not currently managed by any controller,
697697
// but may be adopted later on if they have matching labels with the Daemonset.
698698
podsForDS := []*v1.Pod{}
699-
for _, key := range []string{string(ds.UID), controller.OrphanPodIndexKey} {
699+
for _, key := range []string{string(ds.UID), controller.OrphanPodIndexKeyForNamespace(ds.Namespace)} {
700700
podObjs, err := dsc.podIndexer.ByIndex(controller.PodControllerUIDIndex, key)
701701
if err != nil {
702702
return nil, err

pkg/controller/job/job_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ func (jm *Controller) getPodsForJob(ctx context.Context, j *batch.Job) ([]*v1.Po
811811
// getJobPodsByIndexer returns the set of pods that this Job should manage.
812812
func (jm *Controller) getJobPodsByIndexer(j *batch.Job) ([]*v1.Pod, error) {
813813
podsForJob := []*v1.Pod{}
814-
for _, key := range []string{string(j.UID), controller.OrphanPodIndexKey} {
814+
for _, key := range []string{string(j.UID), controller.OrphanPodIndexKeyForNamespace(j.Namespace)} {
815815
pods, err := jm.podIndexer.ByIndex(controller.PodControllerUIDIndex, key)
816816
if err != nil {
817817
return nil, err

pkg/controller/replicaset/replica_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ func (rsc *ReplicaSetController) getRSPods(rs *apps.ReplicaSet, orphanedPods boo
705705

706706
uidKeys := []string{string(rs.UID)}
707707
if orphanedPods {
708-
uidKeys = append(uidKeys, controller.OrphanPodIndexKey)
708+
uidKeys = append(uidKeys, controller.OrphanPodIndexKeyForNamespace(rs.Namespace))
709709
}
710710

711711
for _, key := range uidKeys {

pkg/controller/statefulset/stateful_set.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (ssc *StatefulSetController) getPodsForStatefulSet(ctx context.Context, set
317317
// The OrphanPodIndexKey, which helps identify orphaned Pods that are not currently managed by any controller,
318318
// but may be adopted later on if they have matching labels with the StatefulSet.
319319
podsForSts := []*v1.Pod{}
320-
for _, key := range []string{string(set.UID), controller.OrphanPodIndexKey} {
320+
for _, key := range []string{string(set.UID), controller.OrphanPodIndexKeyForNamespace(set.Namespace)} {
321321
podObjs, err := ssc.podIndexer.ByIndex(controller.PodControllerUIDIndex, key)
322322
if err != nil {
323323
return nil, err

0 commit comments

Comments
 (0)

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.