Skip to content

Commit 989cfe8

Browse files
authored
Read pod role from kubernetes pod info in reconciler (kubernetes-sigs#82)
* Read pod role from kubernetes pod info in reconciler * Mark pod without role label as Both * updated for review comments
1 parent f67cc34 commit 989cfe8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/epp/backend/metrics/pod_metrics.go

+25
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ import (
3232

3333
const (
3434
fetchMetricsTimeout = 5 * time.Second
35+
roleLabel = "llmd.org/role"
36+
rolePrefill = "prefill"
37+
roleDecode = "decode"
38+
roleBoth = "both"
3539
)
3640

3741
type podMetrics struct {
@@ -67,13 +71,34 @@ func (pm *podMetrics) UpdatePod(in *corev1.Pod) {
6771
pm.pod.Store(toInternalPod(in))
6872
}
6973

74+
func podLabelToRole(in *corev1.Pod) PodRole {
75+
roleLabel, ok := in.ObjectMeta.Labels[roleLabel]
76+
77+
if ok {
78+
switch roleLabel {
79+
case rolePrefill:
80+
return Prefill
81+
case roleDecode:
82+
return Decode
83+
case roleBoth:
84+
return Both
85+
default:
86+
return Unknown
87+
}
88+
}
89+
90+
// role label is missing
91+
return Both
92+
}
93+
7094
func toInternalPod(in *corev1.Pod) *Pod {
7195
return &Pod{
7296
NamespacedName: types.NamespacedName{
7397
Name: in.Name,
7498
Namespace: in.Namespace,
7599
},
76100
Address: in.Status.PodIP,
101+
Role: podLabelToRole(in),
77102
}
78103
}
79104

pkg/epp/backend/metrics/types.go

+11
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,19 @@ type PodMetrics interface {
6565
String() string
6666
}
6767

68+
type PodRole int
69+
70+
const (
71+
Prefill PodRole = iota
72+
Decode
73+
Both
74+
Unknown
75+
)
76+
6877
type Pod struct {
6978
NamespacedName types.NamespacedName
7079
Address string
80+
Role PodRole
7181
}
7282

7383
func (p *Pod) String() string {
@@ -87,6 +97,7 @@ func (p *Pod) Clone() *Pod {
8797
Namespace: p.NamespacedName.Namespace,
8898
},
8999
Address: p.Address,
100+
Role: p.Role,
90101
}
91102
}
92103

0 commit comments

Comments
 (0)