update discovery
This commit is contained in:
@@ -30,11 +30,19 @@ func (k *K8sDiscovery) DiscoverInNamespace(namespace string) ([]string, error) {
|
|||||||
}
|
}
|
||||||
hosts := make([]string, 0, len(pods.Items))
|
hosts := make([]string, 0, len(pods.Items))
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
|
if hasReadyCondition(&pod) {
|
||||||
hosts = append(hosts, pod.Status.PodIP)
|
hosts = append(hosts, pod.Status.PodIP)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return hosts, nil
|
return hosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hasReadyCondition(pod *v1.Pod) bool {
|
||||||
|
return slices.ContainsFunc(pod.Status.Conditions, func(condition v1.PodCondition) bool {
|
||||||
|
return condition.Type == v1.PodReady && condition.Status == v1.ConditionTrue
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (k *K8sDiscovery) Watch() (<-chan HostChange, error) {
|
func (k *K8sDiscovery) Watch() (<-chan HostChange, error) {
|
||||||
timeout := int64(30)
|
timeout := int64(30)
|
||||||
ipsThatAreReady := make(map[string]bool)
|
ipsThatAreReady := make(map[string]bool)
|
||||||
@@ -54,9 +62,7 @@ func (k *K8sDiscovery) Watch() (<-chan HostChange, error) {
|
|||||||
for event := range watcher.ResultChan() {
|
for event := range watcher.ResultChan() {
|
||||||
|
|
||||||
pod := event.Object.(*v1.Pod)
|
pod := event.Object.(*v1.Pod)
|
||||||
isReady := slices.ContainsFunc(pod.Status.Conditions, func(condition v1.PodCondition) bool {
|
isReady := hasReadyCondition(pod)
|
||||||
return condition.Type == v1.PodReady && condition.Status == v1.ConditionTrue
|
|
||||||
})
|
|
||||||
m.Lock()
|
m.Lock()
|
||||||
oldState := ipsThatAreReady[pod.Status.PodIP]
|
oldState := ipsThatAreReady[pod.Status.PodIP]
|
||||||
ipsThatAreReady[pod.Status.PodIP] = isReady
|
ipsThatAreReady[pod.Status.PodIP] = isReady
|
||||||
|
|||||||
Reference in New Issue
Block a user