Skip to content

Commit 3690dbe

Browse files
authored
moved IsPodReady func to podutils (#662)
* moved IsPodReady func to pod utils to be shared between pod reconciler and datastore Signed-off-by: Nir Rozenbaum <[email protected]> * code review changes Signed-off-by: Nir Rozenbaum <[email protected]> * plural to singular Signed-off-by: Nir Rozenbaum <[email protected]> --------- Signed-off-by: Nir Rozenbaum <[email protected]>
1 parent 59c5781 commit 3690dbe

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

pkg/epp/controller/pod_reconciler.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
3131
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/datastore"
3232
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
33+
podutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/pod"
3334
)
3435

3536
type PodReconciler struct {
@@ -71,7 +72,7 @@ func (c *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
7172

7273
func (c *PodReconciler) updateDatastore(logger logr.Logger, pod *corev1.Pod, pool *v1alpha2.InferencePool) {
7374
namespacedName := types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}
74-
if !pod.DeletionTimestamp.IsZero() || !c.Datastore.PoolLabelsMatch(pod.Labels) || !podIsReady(pod) {
75+
if !pod.DeletionTimestamp.IsZero() || !c.Datastore.PoolLabelsMatch(pod.Labels) || !podutil.IsPodReady(pod) {
7576
logger.V(logutil.DEBUG).Info("Pod removed or not added", "name", namespacedName)
7677
c.Datastore.PodDelete(namespacedName)
7778
} else {
@@ -82,15 +83,3 @@ func (c *PodReconciler) updateDatastore(logger logr.Logger, pod *corev1.Pod, poo
8283
}
8384
}
8485
}
85-
86-
func podIsReady(pod *corev1.Pod) bool {
87-
for _, condition := range pod.Status.Conditions {
88-
if condition.Type == corev1.PodReady {
89-
if condition.Status == corev1.ConditionTrue {
90-
return true
91-
}
92-
break
93-
}
94-
}
95-
return false
96-
}

pkg/epp/datastore/datastore.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sigs.k8s.io/gateway-api-inference-extension/api/v1alpha2"
3131
backendmetrics "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/backend/metrics"
3232
logutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/logging"
33+
podutil "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/util/pod"
3334
)
3435

3536
const (
@@ -259,7 +260,7 @@ func (ds *datastore) PodResyncAll(ctx context.Context, ctrlClient client.Client,
259260

260261
activePods := make(map[string]bool)
261262
for _, pod := range podList.Items {
262-
if podIsReady(&pod) {
263+
if podutil.IsPodReady(&pod) {
263264
namespacedName := types.NamespacedName{Name: pod.Name, Namespace: pod.Namespace}
264265
activePods[pod.Name] = true
265266
if ds.PodUpdateOrAddIfNotExist(&pod, pool) {
@@ -308,16 +309,3 @@ func IsCritical(model *v1alpha2.InferenceModel) bool {
308309
}
309310
return false
310311
}
311-
312-
// TODO: move out to share with pod_reconciler.go
313-
func podIsReady(pod *corev1.Pod) bool {
314-
for _, condition := range pod.Status.Conditions {
315-
if condition.Type == corev1.PodReady {
316-
if condition.Status == corev1.ConditionTrue {
317-
return true
318-
}
319-
break
320-
}
321-
}
322-
return false
323-
}

pkg/epp/util/pod/pod.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2025 The Kubernetes 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 pod
18+
19+
import (
20+
corev1 "k8s.io/api/core/v1"
21+
)
22+
23+
func IsPodReady(pod *corev1.Pod) bool {
24+
for _, condition := range pod.Status.Conditions {
25+
if condition.Type == corev1.PodReady {
26+
if condition.Status == corev1.ConditionTrue {
27+
return true
28+
}
29+
break
30+
}
31+
}
32+
return false
33+
}

0 commit comments

Comments
 (0)