refactor/checkout (#8)
All checks were successful
Build and Publish / BuildAndDeployAmd64 (push) Successful in 59s
Build and Publish / BuildAndDeployArm64 (push) Successful in 5m40s

Co-authored-by: matst80 <mats.tornberg@gmail.com>
Reviewed-on: #8
Co-authored-by: Mats Törnberg <mats@tornberg.me>
Co-committed-by: Mats Törnberg <mats@tornberg.me>
This commit was merged in pull request #8.
This commit is contained in:
2025-12-03 09:45:48 +01:00
committed by mats
parent ebd1508294
commit ee5f54f0dd
77 changed files with 5190 additions and 5795 deletions

View File

@@ -14,17 +14,16 @@ import (
)
type K8sDiscovery struct {
ctx context.Context
client *kubernetes.Clientset
ctx context.Context
client *kubernetes.Clientset
listOptions metav1.ListOptions
}
func (k *K8sDiscovery) Discover() ([]string, error) {
return k.DiscoverInNamespace("")
}
func (k *K8sDiscovery) DiscoverInNamespace(namespace string) ([]string, error) {
pods, err := k.client.CoreV1().Pods(namespace).List(k.ctx, metav1.ListOptions{
LabelSelector: "actor-pool=cart",
})
pods, err := k.client.CoreV1().Pods(namespace).List(k.ctx, k.listOptions)
if err != nil {
return nil, err
}
@@ -44,14 +43,10 @@ func hasReadyCondition(pod *v1.Pod) bool {
}
func (k *K8sDiscovery) Watch() (<-chan HostChange, error) {
timeout := int64(30)
ipsThatAreReady := make(map[string]bool)
m := sync.Mutex{}
watcherFn := func(options metav1.ListOptions) (watch.Interface, error) {
return k.client.CoreV1().Pods("").Watch(k.ctx, metav1.ListOptions{
LabelSelector: "actor-pool=cart",
TimeoutSeconds: &timeout,
})
return k.client.CoreV1().Pods("").Watch(k.ctx, k.listOptions)
}
watcher, err := toolsWatch.NewRetryWatcherWithContext(k.ctx, "1", &cache.ListWatch{WatchFunc: watcherFn})
if err != nil {
@@ -82,9 +77,10 @@ func (k *K8sDiscovery) Watch() (<-chan HostChange, error) {
return ch, nil
}
func NewK8sDiscovery(client *kubernetes.Clientset) *K8sDiscovery {
func NewK8sDiscovery(client *kubernetes.Clientset, listOptions metav1.ListOptions) *K8sDiscovery {
return &K8sDiscovery{
ctx: context.Background(),
client: client,
ctx: context.Background(),
client: client,
listOptions: listOptions,
}
}