You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current implementation only checks if the pod phase is Running, which might not accurately reflect the readiness of the containers within the pod. Consider checking container ready conditions for more accurate readiness determination.
func (c *Client) isHeadlessServiceReady(ctx context.Context, service *v1.Service) (bool, error) {
pods, err := c.clientset.CoreV1().Pods(service.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{
MatchLabels: service.Spec.Selector,
}),
})
if err != nil {
return false, ErrGettingPodsForService.WithParams(service.Name).Wrap(err)
}
// Check if at least one pod is ready
for _, pod := range pods.Items {
- if pod.Status.Phase == v1.PodRunning {+ if pod.Status.Phase == v1.PodRunning {+ // Check if all containers are ready+ allContainersReady := true+ for _, condition := range pod.Status.Conditions {+ if condition.Type == v1.PodReady && condition.Status != v1.ConditionTrue {+ allContainersReady = false+ break+ }+ }+ if allContainersReady {
return true, nil
+ }
}
}
return false, nil
}
📝 Committable suggestion
‼️IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
func (c *Client) isHeadlessServiceReady(ctx context.Context, service *v1.Service) (bool, error) {
// For headless services, we check if the service has any pods ready
pods, err := c.clientset.CoreV1().Pods(service.Namespace).List(ctx, metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{
MatchLabels: service.Spec.Selector,
}),
})
if err != nil {
return false, ErrGettingPodsForService.WithParams(service.Name).Wrap(err)
}
// Check if at least one pod is ready
for _, pod := range pods.Items {
if pod.Status.Phase == v1.PodRunning {
// Check if all containers are ready
allContainersReady := true
for _, condition := range pod.Status.Conditions {
if condition.Type == v1.PodReady && condition.Status != v1.ConditionTrue {
allContainersReady = false
break
}
}
if allContainersReady {
return true, nil
}
}
}
return false, nil
}
Enhance pod readiness check for headless services
The current implementation only checks if the pod phase is Running, which might not accurately reflect the readiness of the containers within the pod. Consider checking container ready conditions for more accurate readiness determination.
📝 Committable suggestion
Originally posted by @coderabbitai[bot] in #574 (comment)
The text was updated successfully, but these errors were encountered: