Look for finished contexts in K8s watch() loop
@@ -69,7 +69,10 @@ func (k *k8sLocker) watch(ctx context.Context, serviceName string, tags []string
watchChan := watched.ResultChan()
for {
- event := <- watchChan
+ select {
+ case <-ctx.Done():
+ return "", ctx.Err()
+ case event := <-watchChan:
switch event.Type {
case watch.Modified, watch.Added:
endpoints, ok := event.Object.(*corev1.Endpoints)
@@ -100,6 +103,7 @@ func (k *k8sLocker) watch(ctx context.Context, serviceName string, tags []string
}
}
}
+}
func parseEndpoint(endpoint *corev1.Endpoints) ([]*lockers.Service, error) {
// the service should only have a single port number assigned, so
