title: Use client-go to simulate 'kubectl wait' for a pod to be ready
body: <p>In bash scripts, I normally use 'kubectl wait' to block until a certain pod resource is ready, e.g. something similar to this:</p>
  <pre><code>kubectl wait --for=condition=Ready --timeout=2m -n mynamespace pod -l myselector
  </code></pre>
  <p>This works well because often times I don't know the exact name of the pod I need to wait for, and 'kubectl wait' allows me to locate the pod based on selectors and then block until it's ready.</p>
  <p>Now I need to do something similar in golang code. I have seen examples of using the <a href="https://github.com/kubernetes/client-go/tree/master/examples/out-of-cluster-client-configuration" rel="nofollow noreferrer">client-go</a> library to authenticate and 'get' a specific pod by name. But I have a few questions on how to best adapt this example to my needs...</p>
  <ol>
  <li><p>I do not know the exact/full name of the pod to be able to 'Get()' it, which is why 'kubectl wait' is perfect as it allows me to find the pod using selectors. I assume that I should use client-go library to instead do a CoreV1().Pods().List() call instead of a Get() in order to allow me to find the pod I want using selectors?</p>
  </li>
  <li><p>Also, the pod may not exist immediately and might be created only after 1 minute or so, which 'kubectl wait' handles for me. In code, do I need to loop/sleep and keep performing List() until the pod exists?</p>
  </li>
  <li><p>Similar question to #2...once the List() does return a pod name, what is the best way in golang to 'wait' for that pod to be in a 'ready' state? I do not want to do any ugly polls with sleeps if avoidable...so is there is a better option using golang 'wait' package or similar? What do you recommend?</p>
  </li>
  </ol>