<p>I have some questions about the golang API for kubernetes.</p>

<ol>
<li><p>which one should I use? k8s.io/client-go or k8s.io/kubernetes/pkg/client? What's the difference?</p></li>
<li><p>I want to get list of all pods and then listen to add/update/delete events, what's the difference between using the api.Pods("").Watch method and using an informer?</p></li>
<li><p>I'm using the API from inside the cluster, how can I fetch the name of the node I'm currently in? is it just the hostname of the machine?</p></li>
</ol>

areller
<blockquote>
  <p>which one should I use? k8s.io/client-go or k8s.io/kubernetes/pkg/client?</p>
</blockquote>

<p>Use <code>k8s.io/client-go</code>.</p>

<blockquote>
  <p>what's the difference between using the api.Pods("").Watch method and using an informer?</p>
</blockquote>

<p>The informer is essentially a shared cache, reducing the load on the API server. Unless you're doing something trivial, this is the preferred way.</p>

<blockquote>
  <p>how can I fetch the name of the node I'm currently in? </p>
</blockquote>

<p>Use <a href="https://godoc.org/k8s.io/api/core/v1#Node" rel="noreferrer">k8s.io/api/core/v1.Node</a>, see for example <a href="https://github.com/openshift-talks/k8s-go/blob/master/client-go-basic/main.go" rel="noreferrer">this code</a>.</p>

<p>BTW, a colleague of mine and myself gave a workshop on this topic (using the Kube API with Go) last week at GopherCon UK—maybe the <a href="https://301.sh/2018-gopherconuk-slides" rel="noreferrer">slide deck</a> and the <a href="https://github.com/openshift-talks/k8s-go" rel="noreferrer">repo</a> are useful for you; also, there is an accompanying online <a href="https://www.katacoda.com/mhausenblas/scenarios/k8s-go" rel="noreferrer">Katacoda scenario</a> you can use to play around.</p>
